public void CalculatePredictionCommand_HappyPath() { // Arrange // Instantiate class under test. var viewModel = new GamePredictorWindowViewModel(_sharedService, _windowService) { GuestName = "Guest", HostName = "Host" }; // Set up needed infrastructure of class under test. var guestSeason = new TeamSeason { TeamName = "Guest", SeasonID = 2017, OffensiveFactor = 1.1, OffensiveAverage = 22, DefensiveFactor = 0.9, DefensiveAverage = 20 }; A.CallTo(() => _sharedService.FindTeamSeason(viewModel.GuestName, viewModel.GuestSelectedSeason)) .Returns(guestSeason); var hostSeason = new TeamSeason { TeamName = "Host", SeasonID = 2017, OffensiveFactor = 1.2, OffensiveAverage = 23, DefensiveFactor = 0.8, DefensiveAverage = 19 }; A.CallTo(() => _sharedService.FindTeamSeason(viewModel.HostName, viewModel.HostSelectedSeason)) .Returns(hostSeason); // Act viewModel.CalculatePredictionCommand.Execute(null); // Assert #region ValidateDataEntry() A.CallTo(() => _sharedService.FindTeamSeason(viewModel.GuestName, viewModel.GuestSelectedSeason)) .MustHaveHappenedOnceExactly(); A.CallTo(() => _sharedService.FindTeamSeason(viewModel.HostName, viewModel.HostSelectedSeason)) .MustHaveHappenedOnceExactly(); #endregion ValidateDataEntry() Assert.AreEqual((int)((guestSeason.OffensiveFactor * hostSeason.DefensiveAverage + hostSeason.DefensiveFactor * guestSeason.OffensiveAverage) / 2d), viewModel.GuestScore); Assert.AreEqual((int)((hostSeason.OffensiveFactor * guestSeason.DefensiveAverage + guestSeason.DefensiveFactor * hostSeason.OffensiveAverage) / 2d), viewModel.HostScore); }
public void AddGameCommand_GuestNameIsNull_ShowsExceptionMessageAndAborts() { // Arrange // Instantiate class under test. var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow) { // Set up needed infrastructure of class under test. GuestName = null, HostName = "Host" }; // Set up needed infrastructure of class under test. var seasonID = (int)WpfGlobals.SelectedSeason; A.CallTo(() => _sharedService.FindTeamSeason(viewModel.GuestName, seasonID)).Returns(null); A.CallTo(() => _sharedService.FindTeamSeason(viewModel.HostName, seasonID)).Returns(null); // Act viewModel.AddGameCommand.Execute(null); // Assert var ex = new DataValidationException(WpfGlobals.Constants.BothTeamsNeededErrorMessage); A.CallTo(() => _sharedService.ShowExceptionMessage(A <DataValidationException> .That.IsEqualTo(ex))) .MustHaveHappenedOnceExactly(); A.CallTo(() => _controlService.AddGame(A <Game> .Ignored)).MustNotHaveHappened(); A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null)).MustNotHaveHappened(); }