Thought Cloud TDD #10: Think back

We’re just about done with the TDD push on Thought Cloud. This is the last test before creating some UI.

In the last test, Mike published a thought to Russell. Let’s see if Russell can send one back to Mike.

[TestMethod]
public void RussellCanShareAThoughtWithMike()
{
    Cloud cloud = MikeSharesCloudWithRussell();
    Thought thought = cloud.NewThought();
    cloud.CentralThought = thought;
    thought.Text = "Lunch suggestions";

    Synchronize();

    Cloud sharedCloud = _russellsIdentity.SharedClouds.Single();
    Thought newThought = sharedCloud.NewThought();
    newThought.Text = "Mi Pueblo";
    Thought centralThought = sharedCloud.CentralThought;
    centralThought.LinkTo(newThought);

    Synchronize();

    IEnumerable<Thought> suggestions = thought.Neighbors.Where(n => n != thought);
    Assert.AreEqual(1, suggestions.Count());
    string suggestionText = suggestions.Single().Text;
    Assert.AreEqual("Mi Pueblo", suggestionText);
}

In this test, Mike shares a cloud with the central thought “Lunch suggestions” with Russell. Russell responds by creating a linked thought with the text “Mi Pueblo”. Does Mike see the response?

No! The test fails. Can you see why?

The reason is that we have subscribed to all clouds shared with us. We haven’t subscribed to the clouds that we created ourselves.

_mikesCommunity = new Community(new MemoryStorageStrategy())
    .AddCommunicationStrategy(sharedCommunication)
    .Register<Model.CorrespondenceModel>()
    .Subscribe(() => _mikesIdentity)
    .Subscribe(() => _mikesIdentity.SharedClouds)
    .Subscribe(() => _mikesIdentity.Clouds)
    ;

With this new subscription, the test passes. Mike created the cloud, so now he subscribes to it. When Russell adds a thought to it, that thought is published to Mike’s cloud.

Leave a Reply

You must be logged in to post a comment.