Thought Cloud TDD #9: Penny for your thoughts

The Thought Cloud application just needs a few more tests. Then we are on to building the UI.

In the last test, we made it possible to share clouds with other users. But what we really want to do is share thoughts.

public void MikeCanShareThoughtsWithRussell()
    Cloud cloud = MikeSharesCloudWithRussell();
    Thought thought = cloud.NewThought();
    cloud.CentralThought = thought;
    thought.Text = "Lunch suggestions";


    Thought sharedThought = _russellsIdentity.SharedClouds.Single().CentralThought;
    string sharedText = sharedThought.Text;
    Assert.AreEqual("Lunch suggestions", sharedText);

In this test, Mike is sharing the cloud with Russell, and then adding a thought. Russell should be able to see the thought and the text that Michael put into it. The test, of course, fails.

Subscribe to related facts

The test fails because Russell thinks that CentralThought is still null. The Share was published to him, but not the CentralThought. Let’s publish that now.

fact Cloud {
    Identity creator;

    publish Thought centralThought;

This keyword publishes the CentralThought property to the Cloud. So to receive it, Russell must subscribe to the cloud.

_russellsCommunity = new Community(new MemoryStorageStrategy())
    .Subscribe(() => _russellsIdentity)
    .Subscribe(() => _russellsIdentity.SharedClouds)

With this subscription, Russell receives all facts published to the clouds that have been shared with him. This should be enough to let him see CentralThought. But the test still fails.

Publish successors to shared facts

The test fails now because Russell thinks that the central thought’s text is still null. He can’t see that Mike has changed it. So we somehow need to publish the thought’s text to the Cloud.

Text is a mutable field of a Thought, so it can be published to a Thought. It cannot be published directly to a Cloud. But a Thought can be published to a Cloud.

fact Thought {
    publish Cloud cloud;


This change makes the unit test pass. Why? Because of rule #5.

Rule #5: All successors of published facts are automatically published.

The Text property of the central thought is a successor of the Thought. The Thought is published to the Cloud. Therefore, a subscriber to the Cloud will also see the Text.

Leave a Reply

You must be logged in to post a comment.