Using the skills you have gained so far, add the following features to your model:
  • A User can start a Game.
  • A Game typically has two Players.
  • A Player is the role that a User plays within the Game.
  • A User can query its successor Players to find all of the Games that he participates in.
  • Two Users can play several Games at the same time.

Make these unit tests pass:
[TestClass]
public class GameTest
{
    private Community _community;

    [TestInitialize]
    public void Initialize()
    {
        _community = new Community(new MemoryStorageStrategy())
            .Register<Model.CorrespondenceModel>();
    }

    [TestMethod]
    public void AUserIsInitiallyNotAPlayer()
    {
        User alan = _community.AddFact(new User("alan1"));

        Assert.IsFalse(alan.Players.Any());
    }

    [TestMethod]
    public void UserIsAPlayerAfterStartingAGame()
    {
        User alan = _community.AddFact(new User("alan1"));
        User flynn = _community.AddFact(new User("flynn1"));
        Game game = _community.AddFact(new Game());
        Player alanAsPlayer = _community.AddFact(new Player(alan, game));
        Player flynnAsPlayer = _community.AddFact(new Player(flynn, game));

        Assert.AreSame(alanAsPlayer, alan.Players.Single());
    }

    [TestMethod]
    public void OpponentIsAPlayerAfterStartingAGame()
    {
        User alan = _community.AddFact(new User("alan1"));
        User flynn = _community.AddFact(new User("flynn1"));
        Game game = _community.AddFact(new Game());
        Player alanAsPlayer = _community.AddFact(new Player(alan, game));
        Player flynnAsPlayer = _community.AddFact(new Player(flynn, game));

        Assert.AreSame(flynnAsPlayer, flynn.Players.Single());
    }

    [TestMethod]
    public void TwoUsersBeginASecondGame()
    {
        User alan = _community.AddFact(new User("alan1"));
        User flynn = _community.AddFact(new User("flynn1"));
        Game game1 = _community.AddFact(new Game());
        _community.AddFact(new Player(alan, game1));
        _community.AddFact(new Player(flynn, game1));
        Game game2 = _community.AddFact(new Game());
        _community.AddFact(new Player(alan, game2));
        _community.AddFact(new Player(flynn, game2));

        Assert.AreEqual(2, alan.Players.Count());
    }
}

Answer 1: Define a query

Last edited May 15, 2011 at 4:27 AM by MichaelLPerry1971, version 3

Comments

No comments yet.