Using the skills you've acquired, create a view model listing the games that you are playling.

The view model takes a User. It exposes a list of games that they are currently playing.
public IEnumerable<GameSummaryViewModel> ActiveGames
The GameSummaryViewModel class has a property for the opponent's name.

This unit test verifies that the collection starts out empty. Make it pass.
[TestMethod]
public void UserInitiallyHasNoGames()
{
    Assert.IsFalse(_viewModel.ActiveGames.Any());
}
The user enters the name of an opponent and clicks the "Challenge" button. After this, the collection contains a matching game.
[TestMethod]
public void UserChallengesAnOpponent()
{
    _viewModel.Opponent = "flynn1";
    _viewModel.Challenge.Execute(null);

    Assert.AreEqual("flynn1", _viewModel.ActiveGames.Single().OpponentName);
}
The Challenge button should not be enabled until the user enters an opponent name.
[TestMethod]
public void ChallengeButtonIsInitiallyDisabled()
{
    Assert.IsFalse(_viewModel.Challenge.CanExecute(null));
}

[TestMethod]
public void ChallengeButtonIsEnabledAfterUserEntersOpponentName()
{
    _viewModel.Opponent = "flynn1";

    Assert.IsTrue(_viewModel.Challenge.CanExecute(null));
}
And once the user issues the challenge, the opponent name field should be cleared and the button again disabled.
[TestMethod]
public void AfterChallengeOpponentNameIsCleared()
{
    _viewModel.Opponent = "flynn1";
    _viewModel.Challenge.Execute(null);

    Assert.IsNull(_viewModel.Opponent);
}

[TestMethod]
public void AfterChallengeButtonIsDisabled()
{
    _viewModel.Opponent = "flynn1";
    _viewModel.Challenge.Execute(null);

    Assert.IsFalse(_viewModel.Challenge.CanExecute(null));
}
Define your view model classes. Make the tests compile and pass. You will have to go back to the factual model and add a query, so don't forget what you learned in the first lesson.

Answer 2: Create a view model

Last edited Aug 8, 2010 at 1:22 AM by MichaelLPerry1971, version 2

Comments

No comments yet.