Example #1
0
        static void Main(string[] args)
        {
            var          configuration = InitConfiguration();
            GameTemplate game          = new GuessNumberGame(new ConsoleInteraction(), configuration);

            game.Play();
        }
Example #2
0
        static void HW_RunNumberGuessingGame()
        {
            var game = new GuessNumberGame(guessingPlayer: GuessingPlayer.Machine);

            game.Start();

            Console.ReadLine();
        }
        public void IsMatch_NegativeNumber()
        {
            var lineBotAction = Substitute.For <ITextRenderer>();

            var isMatch = new GuessNumberGame().IsMatch("-117");

            Assert.IsFalse(isMatch);
        }
        public void IsMatch_PositiveNumber()
        {
            var lineBotAction = Substitute.For <ITextRenderer>();

            var isMatch = new GuessNumberGame().IsMatch("99");

            Assert.IsTrue(isMatch);
        }
        public void CheckPropertiesSettedWithConfiguration()
        {
            game = new GuessNumberGame(new ConsoleInteraction(), configuration);
            int expectedMaxValue = 101;
            int expectedMinValue = 0;

            Assert.AreEqual(expectedMinValue, game.MinNumberValue);
            Assert.AreEqual(expectedMaxValue, game.MaxNumberValue);
        }
Example #6
0
        static void HW_RunNumberGuessingGame()
        {
            GuessNumberGame game = new GuessNumberGame(guessingPlayer: GuessingPlayer.Human);

            game.Start();

            GuessNumberGame game1 = new GuessNumberGame(guessingPlayer: GuessingPlayer.Machine);

            game1.Start();
        }
Example #7
0
        static void Main(string[] args)
        {
            Main2.PureEvil();

            //todo explain named params
            GuessNumberGame game = new GuessNumberGame(100, 6, GuessingPlayer.Human);

            game.Start();
            Console.ReadLine();
        }
        private void StartGameWith(int target)
        {
            _renderer = Substitute.For <ITextRenderer>();
            var random = Substitute.For <Random>();

            random.Next(0).ReturnsForAnyArgs(target);
            _guessNumberGame = new GuessNumberGame()
            {
                Random = random
            };
            _guessNumberGame.TextRenderer = _renderer;
            _guessNumberGame.StartGame();
        }
        public void GameTest_GeneralBehaviourTest()
        {
            var testIteraction = new Mock <IGameInteraction>();

            testIteraction.SetupSequence(x => x.GetUserInput())
            .Returns("-1")
            .Returns("q");
            testIteraction.Setup(x => x.ExitRestartDialog()).Returns(false);

            game = new GuessNumberGame(testIteraction.Object, configuration);
            game.Play();

            testIteraction.Verify(x => x.GetUserInput(), Times.Exactly(2));
            testIteraction.Verify(x => x.ExitRestartDialog(), Times.Once());
            testIteraction.Verify(x => x.ShowGameResponse(It.IsAny <string>()), Times.Exactly(7));
        }
        public void GameTest_GuesedNumberAndUserNumberShouldMatch()
        {
            var configurationValues = new Dictionary <string, string>()
            {
                { "MinValue", "1" },
                { "MaxValue", "1" }
            };

            IConfiguration LocalConfiguration = new ConfigurationBuilder()
                                                .AddInMemoryCollection(configurationValues)
                                                .Build();

            var testIteraction = new Mock <IGameInteraction>();

            testIteraction.SetupSequence(x => x.GetUserInput())
            .Returns("1")
            .Returns("q");
            testIteraction.Setup(x => x.ExitRestartDialog()).Returns(false);

            var game = new GuessNumberGame(testIteraction.Object, LocalConfiguration);

            game.Play();

            testIteraction.Verify(x => x.ShowGameResponse(MessagesTemplates.Greetings), Times.Once);
            testIteraction.Verify(x => x.ShowGameResponse(MessagesTemplates.AskUserNumberMessage), Times.Once);
            testIteraction.Verify(x => x.ShowGameResponse(MessagesTemplates.GuessedNumberMessage), Times.Once);
            testIteraction.Verify(x => x.ShowGameResponse(MessagesTemplates.ExitOrRestart), Times.Once);
            testIteraction.Verify(x => x.ShowGameResponse(MessagesTemplates.ByeBye), Times.Once);
            testIteraction.Verify(x => x.GetUserInput(), Times.Once);
            testIteraction.Verify(x => x.ExitRestartDialog(), Times.Once());

            var minValueFromConfiguration = Int32.TryParse(configurationValues["MinValue"], out int minResult);
            var maxValueFromConfiguration = Int32.TryParse(configurationValues["MinValue"], out int maxResult);

            Assert.AreEqual((minResult, maxResult), (game.MinNumberValue, game.MaxNumberValue));
            Assert.IsFalse(game.NumberIsNotGuessed);
        }
 public void TestCleanUp()
 {
     game          = null;
     configuration = null;
 }