コード例 #1
0
        public void GameViewNewGameButtonClicked_WhenButtonClickedAndGameParameterIsNotNull_ShouldUpdateViewEliminateEach()
        {
            //Arrange
            var mockView        = new Mock <IChildrensGameView>();
            var mockRepo        = new Mock <IGameRepository>();
            var mockGameManager = new Mock <IChildrensGameManager>();

            mockRepo.Setup(m => m.GetGameParameter()).Returns(Task.FromResult(new GameParameter()));
            var presenter = new ChildrensGamePresenter(mockView.Object, mockRepo.Object, mockGameManager.Object);

            //Act
            presenter.GameViewNewGameButtonClicked(mockView.Object, EventArgs.Empty);

            //Assert
            mockView.VerifySet(m => m.EliminateEach = It.IsAny <decimal>(), Times.Once);
        }
コード例 #2
0
        public void GameViewNewGameButtonClicked_WhenButtonClicked_ShouldCallRepositoryGetGameParameter()
        {
            //Arrange
            var mockView        = new Mock <IChildrensGameView>();
            var mockRepo        = new Mock <IGameRepository>();
            var mockGameManager = new Mock <IChildrensGameManager>();

            mockRepo.Setup(m => m.GetGameParameter()).Verifiable();
            var presenter = new ChildrensGamePresenter(mockView.Object, mockRepo.Object, mockGameManager.Object);

            //Act
            presenter.GameViewNewGameButtonClicked(mockView.Object, EventArgs.Empty);

            //Assert
            mockRepo.Verify(m => m.GetGameParameter(), Times.Once);
        }
コード例 #3
0
        public void GameViewNewGameButtonClicked_WhenButtonClickedAndGameParameterIsNull_ShouldCallViewShowErrorMessage()
        {
            //Arrange
            var mockView = new Mock <IChildrensGameView>();
            var mockRepo = new Mock <IGameRepository>();

            mockView.Setup(m => m.ShowErrorMessage(It.IsAny <string>())).Verifiable();
            mockRepo.Setup(m => m.GetGameParameter()).Returns(Task.FromResult <GameParameter>(null));
            var mockGameManager = new Mock <IChildrensGameManager>();
            var presenter       = new ChildrensGamePresenter(mockView.Object, mockRepo.Object, mockGameManager.Object);

            //Act
            presenter.GameViewNewGameButtonClicked(mockView.Object, EventArgs.Empty);

            //Assert
            mockView.Verify(m => m.ShowErrorMessage(It.IsAny <string>()), Times.Once);
        }
コード例 #4
0
        public void GameViewNewGameButtonClicked_WhenButtonClickedAndGameResultIsNotNull_ShouldUpdateViewWinner()
        {
            //Arrange
            var mockView        = new Mock <IChildrensGameView>();
            var mockRepo        = new Mock <IGameRepository>();
            var mockGameManager = new Mock <IChildrensGameManager>();

            mockRepo.Setup(m => m.GetGameParameter()).Returns(Task.FromResult(new GameParameter()));
            mockRepo.Setup(m => m.SetGameResult(It.IsAny <GameResult>())).Returns(Task.FromResult(new GameResultPostResponse()));
            mockGameManager.Setup(m => m.CalculateGameResult(It.IsAny <GameParameter>())).Returns(Task.FromResult(new GameResult()));
            var presenter = new ChildrensGamePresenter(mockView.Object, mockRepo.Object, mockGameManager.Object);

            //Act
            presenter.GameViewNewGameButtonClicked(mockView.Object, EventArgs.Empty);

            //Assert
            mockView.VerifySet(m => m.Winner = It.IsAny <string>(), Times.Once);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: jsuen123/ChildrensGame
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Initialise view
            var view = new ChildrensGameView();

            //Intialise repository
            IGameRepository repository = new GameRestRepository(Properties.Settings.Default.GameParameterAPIAddress);

            //Initialise game manager
            IChildrensGameManager gameManager = new ChildrensGameManager();

            //Initialise presenter
            var presenter = new ChildrensGamePresenter(view, repository, gameManager);

            Application.Run(view);
        }
コード例 #6
0
        public void GameViewNewGameButtonClicked_WhenButtonClicked_ShouldCallRepositorySetGameResult()
        {
            //Arrange
            var mockView        = new Mock <IChildrensGameView>();
            var mockRepo        = new Mock <IGameRepository>();
            var mockGameManager = new Mock <IChildrensGameManager>();

            mockView.Setup(m => m.HideLoading()).Verifiable();
            mockRepo.Setup(m => m.GetGameParameter()).Returns(Task.FromResult(new GameParameter()));
            mockRepo.Setup(m => m.SetGameResult(It.IsAny <GameResult>())).Returns(Task.FromResult(new GameResultPostResponse()));
            mockRepo.Setup(m => m.SetGameResult(It.IsAny <GameResult>())).Verifiable();
            var presenter = new ChildrensGamePresenter(mockView.Object, mockRepo.Object, mockGameManager.Object);

            //Act
            presenter.GameViewNewGameButtonClicked(mockView.Object, EventArgs.Empty);

            //Assert
            mockRepo.Verify(m => m.SetGameResult(It.IsAny <GameResult>()), Times.Once);
        }