Пример #1
0
        public void WhenBankrupt_RespondsCorrectly()
        {
            var mockGameRepository   = new MockGameRepository();
            var mockCircleRepository = new MockCircleRepository();
            var mockRandomProvider   = new MockRandomProvider();
            var interactor           = new SpinCircle(mockGameRepository, mockCircleRepository, mockRandomProvider);
            var gameIdentifier       = Guid.Parse("00000000-0000-0000-0000-000000000001");

            mockGameRepository.Games.Add(gameIdentifier, new Game(new string[] { "Alice", "Bob" }, "TestPhrase"));
            mockCircleRepository.Circle = GetCircle();
            const int indexBankrupt = 0;

            mockRandomProvider.Values.Add((0, 13), indexBankrupt);
            var requestModel = new SpinCircle.RequestModel()
            {
                GameIdentifier = gameIdentifier
            };
            var presenter = new Presenter <SpinCircle.ResponseModel>();

            interactor.HandleRequest(requestModel, presenter);
            var responseModel = presenter.ResponseModel;

            Assert.Equal("Bankrupt", responseModel.ResultDescription);
            Assert.False(responseModel.RequestLetter);
            Assert.Equal("Bob", responseModel.CurrentPlayerName);
        }
        public void FullShortGameTest()
        {
            var mockCircleRepository = new MockCircleRepository();
            var mockGameRepository   = new MockGameRepository();
            var mockPhraseRepository = new MockPhraseRepository();
            var mockRandomProvider   = new MockRandomProvider();

            mockCircleRepository.Circle = GetCircle();
            mockPhraseRepository.Phrase = "Short Game Test";
            const int indexOneThousand = 7;

            mockRandomProvider.Values.Add((0, 13), indexOneThousand);
            var startNewGamePresenter  = new Presenter <StartNewGame.ResponseModel>();
            var startNewGameInteractor = new StartNewGame(mockPhraseRepository, mockGameRepository);

            startNewGameInteractor.HandleRequest(new StartNewGame.RequestModel()
            {
                PlayerNames = new string[]
                {
                    "Alice", "Bob", "Charlie"
                }
            }, startNewGamePresenter);
            var spinCirclePresenter  = new Presenter <SpinCircle.ResponseModel>();
            var spinCircleInteractor = new SpinCircle(mockGameRepository, mockCircleRepository, mockRandomProvider);

            spinCircleInteractor.HandleRequest(new SpinCircle.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier
            }, spinCirclePresenter);
            var pickLetterPresenter  = new Presenter <PickLetter.ResponseModel>();
            var pickLetterInteractor = new PickLetter(mockGameRepository);

            pickLetterInteractor.HandleRequest(new PickLetter.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier,
                Letter         = 'e'
            }, pickLetterPresenter);
            var guessPhrasePresenter  = new Presenter <GuessPhrase.ResponseModel>();
            var guessPhraseInteractor = new GuessPhrase(mockGameRepository);

            guessPhraseInteractor.HandleRequest(new GuessPhrase.RequestModel()
            {
                GameIdentifier = startNewGamePresenter.ResponseModel.GameIdentifier,
                Guess          = "Short Game Test"
            }, guessPhrasePresenter);
            Assert.Equal("Short Game Test", guessPhrasePresenter.ResponseModel.Phrase);
            Assert.Equal("Alice", guessPhrasePresenter.ResponseModel.CurrentPlayerName);
            Assert.Equal(2000, guessPhrasePresenter.ResponseModel.Reward);
            Assert.True(mockGameRepository.Games.Single().Value.IsOver);
        }