コード例 #1
0
        private void AddGame()
        {
            try
            {
                try
                {
                    ValidateDataEntry();
                }
                catch (DataValidationException ex)
                {
                    _sharedService.ShowExceptionMessage(ex);
                    return;
                }

                var newGame = MapNewGameValues();
                _controlService.AddGame(newGame);

                Games = new ReadOnlyCollection <Game>(
                    _controlService.GetGames((int)WpfGlobals.SelectedSeason).ToList());

                SelectedGame = null;
            }
            catch (Exception ex)
            {
                _sharedService.ShowExceptionMessage(ex);
            }
        }
コード例 #2
0
        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();
        }