public void DeleteGameCommand_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow)
            {
                // Set up needed infrastructure of class under test.
                SelectedGame = new Game
                {
                    SeasonID      = (int)WpfGlobals.SelectedSeason,
                    Week          = 1,
                    GuestName     = "Guest",
                    GuestScore    = 0,
                    HostName      = "Host",
                    HostScore     = 0,
                    IsPlayoffGame = false,
                    Notes         = "Notes"
                }
            };

            // Set up needed infrastructure of class under test.
            var selectedGame = viewModel.SelectedGame;
            var oldGame      = new Game
            {
                ID            = selectedGame.ID,
                SeasonID      = (int)WpfGlobals.SelectedSeason,
                Week          = selectedGame.Week,
                GuestName     = selectedGame.GuestName,
                GuestScore    = selectedGame.GuestScore,
                HostName      = selectedGame.HostName,
                HostScore     = selectedGame.HostScore,
                IsPlayoffGame = selectedGame.IsPlayoffGame,
                Notes         = selectedGame.Notes
            };

            // Act
            viewModel.DeleteGameCommand.Execute(null);

            // Assert
            A.CallTo(() => _controlService.DeleteGame(A <Game> .That.IsEqualTo(oldGame))).MustHaveHappenedOnceExactly();

            Assert.IsNull(viewModel.SelectedGame);

            A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
        }
예제 #2
0
        private void DeleteGame()
        {
            try
            {
                // Delete matching row in the dataset.Games table
                var oldGame = MapOldGameValues();

                _controlService.DeleteGame(oldGame);

                SelectedGame = null;

                Games = new ReadOnlyCollection <Game>(_controlService.GetGames((int)WpfGlobals.SelectedSeason).ToList());
            }
            catch (Exception ex)
            {
                _sharedService.ShowExceptionMessage(ex);
            }
        }