public void DeleteGameCommand_ExceptionCaught_ShowsExceptionMessage()
        {
            // 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 ex = new Exception();

            A.CallTo(() => _controlService.DeleteGame(A <Game> .Ignored)).Throws(ex);

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

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(ex, "Exception")).MustHaveHappenedOnceExactly();
        }
示例#2
0
        public void ViewGamesCommand_WhenSeasonIsNotNull_ShouldAssignToWeek()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();
            var games          = new List <Game>();

            A.CallTo(() => gameRepository.GetGamesBySeason(A <int> .Ignored)).Returns(games);

            var seasonRepository    = A.Fake <ISeasonRepository>();
            int numOfWeeksCompleted = 1;
            var season = new Season
            {
                NumOfWeeksCompleted = numOfWeeksCompleted
            };

            A.CallTo(() => seasonRepository.GetSeasonByYear(A <int> .Ignored)).Returns(season);

            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            // Act
            testObject.ViewGamesCommand.Execute(null !);

            // Assert
            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).MustHaveHappenedOnceExactly();
            testObject.Games.ShouldBeOfType <ReadOnlyCollection <Game> >();
            testObject.Games.ShouldBe(games);
            testObject.SelectedGame.ShouldBeNull();
            A.CallTo(() => seasonRepository.GetSeasonByYear(WpfGlobals.SelectedSeason)).MustHaveHappenedOnceExactly();
            testObject.Week.ShouldBe(numOfWeeksCompleted);
        }
        public void SelectedGame_ValueEqualsNull_ClearsDataEntryControls()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Act
            viewModel.SelectedGame = null;

            // Assert
            #region ClearDataEntryControls();

            Assert.AreEqual(string.Empty, viewModel.GuestName);
            Assert.AreEqual(0, viewModel.GuestScore);
            Assert.AreEqual(string.Empty, viewModel.HostName);
            Assert.AreEqual(0, viewModel.HostScore);
            Assert.IsFalse(viewModel.IsPlayoffGame);
            Assert.AreEqual(string.Empty, viewModel.Notes);

            Assert.AreEqual(Visibility.Visible, viewModel.AddGameControlVisibility);
            Assert.AreEqual(Visibility.Hidden, viewModel.EditGameControlVisibility);
            Assert.AreEqual(Visibility.Hidden, viewModel.DeleteGameControlVisibility);

            #endregion ClearDataEntryControls();
        }
示例#4
0
        public void EditGameCommand_WhenDataEntryIsValidAndFindGameFilterAppliedIsFalse_ShouldEditGameAndShowAllGames()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();
            var games          = new List <Game>();

            A.CallTo(() => gameRepository.GetGamesBySeason(A <int> .Ignored)).Returns(games);

            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService)
            {
                SelectedGame          = new Game(),
                GuestName             = "Guest",
                HostName              = "Host",
                FindGameFilterApplied = false
            };

            // Act
            testObject.EditGameCommand.Execute(null !);

            // Assert
            A.CallTo(() => messageBoxService.Show(A <string> .Ignored, A <string> .Ignored, A <MessageBoxButton> .Ignored,
                                                  A <MessageBoxImage> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => gameService.EditGame(A <Game> .Ignored, A <Game> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).MustHaveHappenedOnceExactly();
            testObject.Games.ShouldBeOfType <ReadOnlyCollection <Game> >();
            testObject.Games.ShouldBe(games);
            testObject.FindGameFilterApplied.ShouldBeFalse();
        }
        public void SelectedGame_ValueDoesNotEqualNull_PopulatesDataEntryControls()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Act
            viewModel.SelectedGame = new Game();

            // Assert
            #region PopulateDataEntryControls();

            var selectedGame = viewModel.SelectedGame;
            Assert.AreEqual(selectedGame.Week, viewModel.Week);
            Assert.AreEqual(selectedGame.GuestName, viewModel.GuestName);
            Assert.AreEqual(selectedGame.GuestScore, viewModel.GuestScore);
            Assert.AreEqual(selectedGame.HostName, viewModel.HostName);
            Assert.AreEqual(selectedGame.HostScore, viewModel.HostScore);
            Assert.AreEqual(selectedGame.IsPlayoffGame, viewModel.IsPlayoffGame);
            Assert.AreEqual(selectedGame.Notes, viewModel.Notes);

            Assert.AreEqual(Visibility.Hidden, viewModel.AddGameControlVisibility);
            Assert.AreEqual(Visibility.Visible, viewModel.EditGameControlVisibility);
            Assert.AreEqual(Visibility.Visible, viewModel.DeleteGameControlVisibility);

            #endregion PopulateDataEntryControls();
        }
        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();
        }
示例#7
0
        public void DeleteGameCommand_ShouldDeleteGameAndRefreshGamesCollection()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();
            var games          = new List <Game>();

            A.CallTo(() => gameRepository.GetGamesBySeason(A <int> .Ignored)).Returns(games);

            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService)
            {
                SelectedGame = new Game()
            };

            // Act
            testObject.DeleteGameCommand.Execute(null !);

            // Assert
            A.CallTo(() => gameService.DeleteGame(A <int> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).MustHaveHappenedOnceExactly();
            testObject.Games.ShouldBeOfType <ReadOnlyCollection <Game> >();
            testObject.Games.ShouldBe(games);
            testObject.SelectedGame.ShouldBeNull();
        }
        public void FindGameCommand_DialogResultIsFalse_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow)
            {
                AddGameControlVisibility = Visibility.Visible,
                SelectedGame             = null
            };

            // Set up needed infrastructure of class under test.
            A.CallTo(() => viewModel.GameFinder.ShowDialog()).Returns(false);

            var game = new Game();

            viewModel.SelectedGame = game;

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

            // Assert
            A.CallTo(() => viewModel.GameFinder.ShowDialog()).MustHaveHappenedOnceExactly();

            Assert.IsFalse(viewModel.IsGamesReadOnly);
            Assert.IsFalse(viewModel.IsShowAllGamesEnabled);
            Assert.AreSame(game, viewModel.SelectedGame);
        }
        public void ViewGamesCommand_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            var week = 1;

            A.CallTo(() => _controlService.GetWeekCount()).Returns(week);

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

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

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
            Assert.IsNull(viewModel.SelectedGame);

            A.CallTo(() => _controlService.GetWeekCount()).MustHaveHappenedOnceExactly();

            Assert.AreEqual(week, viewModel.Week);
        }
        public void ShowAllGamesCommand_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            var weekCount = 1;

            A.CallTo(() => _controlService.GetWeekCount()).Returns(weekCount);

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

            // Assert
            #region ViewGames();

            // Load the DataModel's Games table.
            A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
            Assert.IsNull(viewModel.SelectedGame);

            A.CallTo(() => _controlService.GetWeekCount()).MustHaveHappenedOnceExactly();

            Assert.AreEqual(weekCount, viewModel.Week);

            #endregion ViewGames();

            Assert.IsFalse(viewModel.IsFindGameFilterApplied);
            Assert.IsFalse(viewModel.IsGamesReadOnly);
            Assert.IsFalse(viewModel.IsShowAllGamesEnabled);
            Assert.IsNull(viewModel.SelectedGame);
        }
        public void FindGameCommand_DialogResultIsTrueAndGamesCountIsZero_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            A.CallTo(() => viewModel.GameFinder.ShowDialog()).Returns(true);

            viewModel.Games        = new ReadOnlyCollection <Game>(new List <Game>());
            viewModel.SelectedGame = new Game();

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

            // Assert
            A.CallTo(() => viewModel.GameFinder.ShowDialog()).MustHaveHappenedOnceExactly();

            #region ApplyFindGameFilter();

            var dataContext = viewModel.GameFinder.DataContext as IGameFinderWindowViewModel;

            A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, dataContext.GuestName,
                                                    dataContext.HostName)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
            Assert.IsTrue(viewModel.IsFindGameFilterApplied);

            #endregion ApplyFindGameFilter();

            Assert.IsTrue(viewModel.IsGamesReadOnly);
            Assert.IsTrue(viewModel.IsShowAllGamesEnabled);
            Assert.IsNull(viewModel.SelectedGame);
            Assert.AreEqual(Visibility.Hidden, viewModel.AddGameControlVisibility);
        }
        public void EditGameCommand_NotIsFindGameFilterApplied_SetsGamesProperty()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow)
            {
                // Set up needed infrastructure of class under test.
                IsFindGameFilterApplied = false,
                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
            };

            var newGame = new Game
            {
                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.EditGameCommand.Execute(null);

            // Assert
            A.CallTo(() => _controlService.EditGame(A <Game> .That.IsEqualTo(oldGame), A <Game> .That.IsEqualTo(newGame)))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
        }
        public void AddGameCommand_NoDataValidationExceptionCaught_HappyPath()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow)
            {
                // Set up needed infrastructure of class under test.
                GuestName    = "Guest",
                HostName     = "Host",
                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 seasonID = (int)WpfGlobals.SelectedSeason;

            A.CallTo(() => _sharedService.FindTeamSeason(viewModel.GuestName, seasonID)).Returns(new TeamSeason());
            A.CallTo(() => _sharedService.FindTeamSeason(viewModel.HostName, seasonID)).Returns(new TeamSeason());

            var selectedGame = viewModel.SelectedGame;
            var newGame      = new Game
            {
                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.AddGameCommand.Execute(null);

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(A <DataValidationException> .Ignored))
            .MustNotHaveHappened();
            A.CallTo(() => _controlService.AddGame(A <Game> .That.IsEqualTo(newGame))).MustHaveHappenedOnceExactly();
            A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ReadOnlyCollection <Game> >(viewModel.Games);
            Assert.IsNull(viewModel.SelectedGame);
        }
示例#14
0
        public void SelectedGameSetter_WhenValueDoesNotEqualSelectedGameAndIsNotNull_ShouldAssignValueToSelectedGameAndPopulateDataEntryControls()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService)
            {
                GuestName  = string.Empty,
                GuestScore = 0,
                HostName   = string.Empty,
                HostScore  = 0,
                IsPlayoff  = true,
                Notes      = string.Empty,
                AddGameControlVisibility    = Visibility.Visible,
                EditGameControlVisibility   = Visibility.Hidden,
                DeleteGameControlVisibility = Visibility.Hidden,
                SelectedGame = new Game()
            };

            var guestName  = "Guest";
            var guestScore = 1;
            var hostName   = "Host";
            var hostScore  = 1;
            var notes      = "Notes";
            var game       = new Game
            {
                GuestName  = guestName,
                GuestScore = guestScore,
                HostName   = hostName,
                HostScore  = hostScore,
                IsPlayoff  = false,
                Notes      = notes
            };

            // Act
            testObject.SelectedGame = game;

            // Assert
            testObject.SelectedGame.ShouldBe(game);
            testObject.GuestName.ShouldBe <string>(guestName);
            testObject.GuestScore.ShouldBe(guestScore);
            testObject.HostName.ShouldBe <string>(hostName);
            testObject.HostScore.ShouldBe(hostScore);
            testObject.IsPlayoff.ShouldBeFalse();
            testObject.Notes.ShouldBe <string>(notes);
            testObject.AddGameControlVisibility.ShouldBe(Visibility.Hidden);
            testObject.EditGameControlVisibility.ShouldBe(Visibility.Visible);
            testObject.DeleteGameControlVisibility.ShouldBe(Visibility.Visible);
        }
示例#15
0
        public void FindGameCommand_WhenGamesCountIsNotZero_ShouldSetSelectedGameToOtherThanNull()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();
            var games          = new List <Game>
            {
                new Game
                {
                    GuestName = "Guest",
                    HostName  = "Host"
                }
            };

            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).Returns(games);

            var seasonRepository = A.Fake <ISeasonRepository>();
            var gameService      = A.Fake <IGameService>();

            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var gameFinderWindow        = A.Fake <IGameFinderWindow>();

            gameFinderWindow.DataContext = A.Fake <IGameFinderWindowViewModel>();
            ((IGameFinderWindowViewModel)(gameFinderWindow.DataContext)).GuestName = "Guest";
            ((IGameFinderWindowViewModel)(gameFinderWindow.DataContext)).HostName  = "Host";
            A.CallTo(() => gameFinderWindow.ShowDialog()).Returns(true);
            A.CallTo(() => gameFinderWindowFactory.CreateWindow()).Returns(gameFinderWindow);

            var messageBoxService = A.Fake <IMessageBoxService>();
            var testObject        = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                             gameFinderWindowFactory, messageBoxService)
            {
                Games        = new ReadOnlyCollection <Game>(games),
                SelectedGame = games[0]
            };

            // Act
            testObject.FindGameCommand.Execute(null !);

            // Assert
            A.CallTo(() => gameFinderWindowFactory.CreateWindow()).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameFinderWindow.ShowDialog()).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).MustHaveHappenedOnceExactly();
            testObject.Games.ShouldBeOfType <ReadOnlyCollection <Game> >();
            testObject.Games.ShouldBe(games);
            testObject.FindGameFilterApplied.ShouldBeTrue();
            testObject.IsGamesReadOnly.ShouldBeTrue();
            testObject.ShowAllGamesEnabled.ShouldBeTrue();
            testObject.SelectedGame.ShouldNotBeNull();
            testObject.AddGameControlVisibility.ShouldBe(Visibility.Hidden);
        }
        //[TestCase]
        public void TestCase1()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // TODO: Define argument variables of method under test.

            // TODO: Set up needed infrastructure of class under test.

            // Act
            // TODO: Call method under test.

            // Assert
            // TODO: Assert results of call to method under test.
        }
        public void ShowAllGamesCommand_ExceptionCaught_ShowsExceptionMessage()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            var ex = new Exception();

            A.CallTo(() => _sharedService.ShowExceptionMessage(A <Exception> .Ignored, "Exception")).Throws(ex);

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

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(ex, "Exception"));
        }
        public void EditGameCommand_GenericExceptionCaught_ShowsExceptionMessage()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            var ex = new Exception();

            A.CallTo(() => _sharedService.FindTeamSeason(A <string> .Ignored, A <int> .Ignored)).Throws(ex);

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

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(ex, "Exception"));
        }
        public void ViewGamesCommand_ExceptionCaught_ShowsExceptionMessage()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow);

            // Set up needed infrastructure of class under test.
            var ex = new Exception();

            A.CallTo(() => _controlService.GetGames(A <int> .Ignored, null, null)).Throws(ex);

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

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(ex, "Exception")).MustHaveHappenedOnceExactly();
        }
        public void EditGameCommand_DataValidationExceptionCaught_ShowsExceptionMessage()
        {
            // Arrange
            // Instantiate class under test.
            var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow)
            {
                // Set up needed infrastructure of class under test.
                GuestName = null,
                HostName  = null
            };

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

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(A <DataValidationException> .That.IsNotNull()));
        }
示例#21
0
        public void ShowAllGamesEnabledSetter_WhenValueDoesNotEqualIsShowAllGamesEnabled_ShouldAssignValueToIsShowAllGamesEnabled()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            // Act
            testObject.ShowAllGamesEnabled = true;

            // Assert
            testObject.ShowAllGamesEnabled.ShouldBeTrue();
        }
示例#22
0
        public void GuestScoreSetter_WhenValueDoesNotEqualGuestScore_ShouldAssignValueToGuestScore()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var guestScore = 7;

            // Act
            testObject.GuestScore = guestScore;

            // Assert
            testObject.GuestScore.ShouldBe(guestScore);
        }
示例#23
0
        public void DeleteGameControlVisibilitySetter_WhenValueDoesNotEqualDeleteGameControlVisibility_ShouldAssignValueToDeleteGameControlVisibility()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var visibility = Visibility.Hidden;

            // Act
            testObject.DeleteGameControlVisibility = visibility;

            // Assert
            testObject.DeleteGameControlVisibility.ShouldBe(visibility);
        }
示例#24
0
        public void GamesSetter_WhenValueIsNull_ShouldThrowArgumentNullException()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            // Act
            Func <ReadOnlyCollection <Game> > func = () => testObject.Games = null !;

            // Assert
            var ex = func.ShouldThrow <ArgumentNullException>();

            ex.ParamName.ShouldBe <string>($"{testObject.GetType()}.{nameof(testObject.Games)}");
        }
示例#25
0
        public void NotesSetter_WhenValueDoesNotEqualNotes_ShouldAssignValueToNotes()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var notes = "Notes";

            // Act
            testObject.Notes = notes;

            // Assert
            testObject.Notes.ShouldBe <string>(notes);
        }
示例#26
0
        public void WeekSetter_WhenValueDoesNotEqualWeek_ShouldAssignValueToWeek()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var week = 1;

            // Act
            testObject.Week = week;

            // Assert
            testObject.Week.ShouldBe(week);
        }
示例#27
0
        public void HostNameSetter_WhenValueDoesNotEqualHostName_ShouldAssignValueToHostName()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var hostName = "Host";

            // Act
            testObject.HostName = hostName;

            // Assert
            testObject.HostName.ShouldBe(hostName);
        }
示例#28
0
        public void GamesSetter_WhenValueDoesNotEqualGames_ShouldAssignValueToGames()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService);

            var games = new ReadOnlyCollection <Game>(new List <Game>());

            // Act
            Func <ReadOnlyCollection <Game> > func = () => testObject.Games = games;

            // Assert
            func.ShouldNotThrow();
            testObject.Games.ShouldBeOfType <ReadOnlyCollection <Game> >();
            testObject.Games.ShouldBe(games);
        }
示例#29
0
        public void SelectedGameSetter_WhenValueDoesNotEqualSelectedGameAndIsNull_ShouldAssignValueToSelectedGameAndClearDataEntryControls()
        {
            // Arrange
            var gameRepository          = A.Fake <IGameRepository>();
            var seasonRepository        = A.Fake <ISeasonRepository>();
            var gameService             = A.Fake <IGameService>();
            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var messageBoxService       = A.Fake <IMessageBoxService>();
            var testObject = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                      gameFinderWindowFactory, messageBoxService)
            {
                GuestName  = "Guest",
                GuestScore = 1,
                HostName   = "Host",
                HostScore  = 1,
                IsPlayoff  = true,
                Notes      = "Notes",
                AddGameControlVisibility    = Visibility.Hidden,
                EditGameControlVisibility   = Visibility.Visible,
                DeleteGameControlVisibility = Visibility.Visible,
                SelectedGame = new Game()
            };

            // Act
            testObject.SelectedGame = null;

            // Assert
            testObject.SelectedGame.ShouldBeNull();
            testObject.GuestName.ShouldBe <string>(string.Empty);
            testObject.GuestScore.ShouldBe(0);
            testObject.HostName.ShouldBe <string>(string.Empty);
            testObject.HostScore.ShouldBe(0);
            testObject.IsPlayoff.ShouldBeFalse();
            testObject.Notes.ShouldBe <string>(string.Empty);
            testObject.AddGameControlVisibility.ShouldBe(Visibility.Visible);
            testObject.EditGameControlVisibility.ShouldBe(Visibility.Hidden);
            testObject.DeleteGameControlVisibility.ShouldBe(Visibility.Hidden);
        }
示例#30
0
        public void FindGameCommand_WhenGameFinderShowDialogReturnsFalse_ShouldReturnEarly()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();
            var games          = new List <Game>();

            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).Returns(games);

            var seasonRepository = A.Fake <ISeasonRepository>();
            var gameService      = A.Fake <IGameService>();

            var gameFinderWindowFactory = A.Fake <IGameFinderWindowFactory>();
            var gameFinderWindow        = A.Fake <IGameFinderWindow>();

            gameFinderWindow.DataContext = A.Fake <IGameFinderWindowViewModel>();
            A.CallTo(() => gameFinderWindow.ShowDialog()).Returns(false);
            A.CallTo(() => gameFinderWindowFactory.CreateWindow()).Returns(gameFinderWindow);

            var messageBoxService = A.Fake <IMessageBoxService>();
            var testObject        = new GamesWindowViewModel(gameRepository, seasonRepository, gameService,
                                                             gameFinderWindowFactory, messageBoxService);

            // Act
            testObject.FindGameCommand.Execute(null !);

            // Assert
            A.CallTo(() => gameFinderWindowFactory.CreateWindow()).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameFinderWindow.ShowDialog()).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameRepository.GetGamesBySeason(WpfGlobals.SelectedSeason)).MustNotHaveHappened();
            testObject.Games.ShouldBeNull();
            testObject.FindGameFilterApplied.ShouldBeFalse();
            testObject.IsGamesReadOnly.ShouldBeFalse();
            testObject.ShowAllGamesEnabled.ShouldBeFalse();
            testObject.SelectedGame.ShouldBeNull();
            testObject.AddGameControlVisibility.ShouldBe(Visibility.Visible);
        }