public void EntryInCode_Positive()
 {
     using (ServiceMock mocks = new ServiceMock()) {
         EntryPositionChecker entryChecker = Setup(mocks);
         Assert.IsTrue(entryChecker.EntryInCode(code, 1));
         Assert.IsTrue(entryChecker.EntryInCode(code, 2));
         Assert.IsTrue(entryChecker.EntryInCode(code, 3));
         Assert.IsTrue(entryChecker.EntryInCode(code, 4));
     }
 }
 public void EntryInCode_Negative()
 {
     using (ServiceMock mocks = new ServiceMock()) {
         EntryPositionChecker entryChecker = Setup(mocks);
         Assert.IsFalse(entryChecker.EntryInCode(code, 55));
         Assert.IsFalse(entryChecker.EntryInCode(code, 6));
         Assert.IsFalse(entryChecker.EntryInCode(code, 700));
         Assert.IsFalse(entryChecker.EntryInCode(code, 8));
     }
 }
Exemplo n.º 3
0
        public void TestCodeLength()
        {
            using (ServiceMock mocks = new ServiceMock()) {
                int length = Faker.RandomNumber.Next(1, 9999);
                mocks.MockConfigService(length);

                InitializeGame sut  = new InitializeGame();
                SecretCode     code = sut.InitializeSecretCode();
                Assert.AreEqual(length, code.Values.Length);
            }
        }
Exemplo n.º 4
0
        public void RunClearsConsole_HappyPath()
        {
            using (ServiceMock mocks = new ServiceMock()) {
                mocks.MockConfigService(4, 1, 6);
                var consoleMock = new Mock <IConsoleManager> ();
                consoleMock.Setup(p => p.Clear()).Verifiable();
                consoleMock.Setup(p => p.ReadLine()).Returns("1234");
                mocks.MockService <IConsoleManager> (consoleMock.Object);

                Game game = new Game();
                game.Run(code);
                consoleMock.Verify(foo => foo.Clear());
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.CODE_HINT));
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.VICTORY_MESSAGE));
            }
        }
Exemplo n.º 5
0
        public void TestCodeBounds()
        {
            using (ServiceMock mocks = new ServiceMock()) {
                int min    = RandomNumber.Next(1, 900);
                int max    = min + RandomNumber.Next(9000, 999999);
                int length = 2000;
                mocks.MockConfigService(length, min, max);

                InitializeGame sut  = new InitializeGame();
                SecretCode     code = sut.InitializeSecretCode();
                for (int i = 0; i < length; i++)
                {
                    Assert.LessOrEqual(code.Values[i], max);
                    Assert.GreaterOrEqual(code.Values[i], min);
                }
            }
        }
Exemplo n.º 6
0
        public void RunClearsConsole_InputValidationHookedUp()
        {
            using (ServiceMock mocks = new ServiceMock()) {
                mocks.MockConfigService(4, 1, 6);
                var consoleMock = new Mock <IConsoleManager> ();
                consoleMock.Setup(p => p.Clear()).Verifiable();
                consoleMock.Setup(p => p.ReadLine()).Returns(new Queue <string> (new [] {
                    "Bacon",
                    "9999",
                    "1234"
                }).Dequeue);
                mocks.MockService <IConsoleManager> (consoleMock.Object);

                Game game = new Game();
                game.Run(code);
                consoleMock.Verify(foo => foo.Clear());
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.CODE_HINT));
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.PLAYER_ENTRY_WRONG_LENGTH));
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.PLAYER_ENTRY_NOT_NUMERIC));
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.VICTORY_MESSAGE));
            }
        }
Exemplo n.º 7
0
        public static void MockConfigService(this ServiceMock mocks,
                                             int codeSize,
                                             int minValue         = 0,
                                             int maxValue         = 0,
                                             char correctPosition = '+',
                                             char wrongPosition   = '-')
        {
            var configProviderMock = new Mock <ConfigProvider> ();

            configProviderMock.SetupGet(_ => _.CODE_MIN_VALUE).Returns(minValue);
            configProviderMock.SetupGet(_ => _.CODE_MAX_VALUE).Returns(maxValue);
            configProviderMock.SetupGet(_ => _.CODE_LENGTH).Returns(codeSize);
            configProviderMock.SetupGet(_ => _.CORRECT_POSITION).Returns(correctPosition);
            configProviderMock.SetupGet(_ => _.WRONG_POSITION).Returns(wrongPosition);
            configProviderMock.SetupGet(_ => _.NUMBER_OF_GUESSES).Returns(Constants.GamePlay.NUMBER_OF_GUESSES);
            configProviderMock.SetupGet(_ => _.GAME_OVER_MESSAGE).Returns(Constants.GamePlay.GAME_OVER_MESSAGE);
            configProviderMock.SetupGet(_ => _.VICTORY_MESSAGE).Returns(Constants.GamePlay.VICTORY_MESSAGE);
            configProviderMock.SetupGet(_ => _.PLAY_AGAIN_MESSAGE).Returns(Constants.GamePlay.PLAY_AGAIN_MESSAGE);
            configProviderMock.SetupGet(_ => _.CODE_HINT).Returns(Constants.GamePlay.CODE_HINT);
            configProviderMock.SetupGet(_ => _.PLAYER_ENTRY_NOT_NUMERIC).Returns(Constants.GamePlay.PLAYER_ENTRY_NOT_NUMERIC);
            configProviderMock.SetupGet(_ => _.PLAYER_ENTRY_WRONG_LENGTH).Returns(Constants.GamePlay.PLAYER_ENTRY_WRONG_LENGTH);

            mocks.MockService <IConfigProvider> (configProviderMock.Object);
        }
Exemplo n.º 8
0
        public void RunClearsConsole_PoitionEntryHookedUp()
        {
            using (ServiceMock mocks = new ServiceMock()) {
                mocks.MockConfigService(4, 1, 6);
                var consoleMock = new Mock <IConsoleManager> ();
                consoleMock.Setup(p => p.Clear()).Verifiable();
                consoleMock.Setup(p => p.ReadLine()).Returns(new Queue <string> (new [] {
                    "1253",
                    "1355",
                    "1235",
                    "1234"
                }).Dequeue);
                mocks.MockService <IConsoleManager> (consoleMock.Object);

                Game game = new Game();
                game.Run(code);
                consoleMock.Verify(foo => foo.Clear());
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.CODE_HINT));
                consoleMock.Verify(foo => foo.WriteLine("++-"));
                consoleMock.Verify(foo => foo.WriteLine("+-"));
                consoleMock.Verify(foo => foo.WriteLine("+++"));
                consoleMock.Verify(foo => foo.WriteLine(Constants.GamePlay.VICTORY_MESSAGE));
            }
        }
 private EntryPositionChecker Setup(ServiceMock mocks)
 {
     mocks.MockConfigService(4, 1, 4);
     return(new EntryPositionChecker());
 }