public void RenderCommandsWithPassedZeroCommandStringsShouldCallConsoleWriteLineNever()
        {
            string[] commands = new string[0];
            var renderer = new ConsoleRenderer();

            renderer.RenderCommands(commands);
        }
        public void ExitCommandShouldhaveCorrectName()
        {
            var renderer = new ConsoleRenderer();
            var command = new ExitCommand(renderer);

            var expectedName = command.Name;

            Assert.AreEqual("exit", expectedName);
        }
        public void RenderCommandsWithPassedOneCommandStringShouldCallConsoleWriteLineOnce()
        {
            string[] commands = { "command" };
            var mockConsole = new Mock<IConsoleWriter>();
            var writer = mockConsole.Object;
            var renderer = new ConsoleRenderer(writer);

            renderer.RenderCommands(commands);

            mockConsole.Verify(c => c.WriteLine(It.IsAny<string>()), Times.Exactly(1));
        }
        public void RenderGameFieldWhenPassedFieldHavingNonNullCellsShouldWriteOnConsole()
        {
            var mockConsole = new Mock<IConsoleWriter>();
            var console = mockConsole.Object;

            var renderer = new ConsoleRenderer(console);
            var field = new GameField(2, 2);
            var filler = new Filler(new BalloonsFactory());
            field.Filler = filler;
            field.Fill();

            renderer.RenderGameField(field);

            mockConsole.Verify(c => c.Write(It.IsAny<string>()), Times.AtLeastOnce);
        }
        public void RenderCommandsWithPassedFiveCommandStringsShouldCallConsoleWriteLineFiveTimes()
        {
            string[] commands =
            {
                "command1",
                "command2",
                "command3",
                "command4",
                "command5",
            };
            var mockConsole = new Mock<IConsoleWriter>();
            var writer = mockConsole.Object;
            var renderer = new ConsoleRenderer(writer);

            renderer.RenderCommands(commands);

            mockConsole.Verify(c => c.WriteLine(It.IsAny<string>()), Times.Exactly(5));
        }
        /// <summary>
        /// This method instantiate all dependencies for the game.
        /// </summary>
        public static void StartGame()
        {
            // Console context dependancies
            IConsoleWriter consoleWriter = new ConsoleWriter();
            IConsoleReader consoleReader = new ConsoleReader();

            // Instantiate game dependancies
            IRenderer renderer = new ConsoleRenderer(consoleWriter);
            IInputHandler inputHandler = new ConsoleInputHandler(consoleWriter, consoleReader);
            IFieldFactory fieldFactory = new GameFieldFactory();
            IFieldMemoryManager fieldMemoryManager = new FieldMemoryManager();
            IBalloonsFactory balloonsFactory = new BalloonsFactory();
            IFiller matrixFiller = new Filler(balloonsFactory);
            ICommandManager commandManager = new CommandManager();

            // Printing initial screen goes here.
            renderer.RenderGameMessage(GameMessages.InitialGameMessage);
            renderer.RenderCommands(GameMessages.CommandsMessages);

            // Getting mode and difficulty goes here.
            GameMode gameMode = inputHandler.GetGameMode();
            GameDifficulty gameDifficulty = inputHandler.GetGameDifficulty();

            var reorderStrategy = GetReorderStrategy(gameMode);

            // Fluent interface implementation
            IBalloonsEngine engine = new BalloonsGameEngine()
                .Renderer(renderer)
                .Input(inputHandler)
                .FieldFactory(fieldFactory)
                .FieldMemoryManager(fieldMemoryManager)
                .BalloonsFactory(balloonsFactory)
                .CommandManager(commandManager)
                .ReorderBalloonsStrategy(reorderStrategy)
                .GameFieldFiller(matrixFiller);

            engine.InitializeGame(gameDifficulty);
            engine.StartGame();
        }
        public void RenderGameFieldWhenPassedNullShouldThrowException()
        {
            var renderer = new ConsoleRenderer();

            renderer.RenderGameField(null);
        }
        public void RenderGameFieldWhenPassedFieldHavingNullCellShouldThrowException()
        {
            var renderer = new ConsoleRenderer();
            var field = new GameField(2, 2);

            renderer.RenderGameField(field);
        }
        public void RenderGameTopPlayersWhenPassedZeroPlayerShouldInvokeConsoleWriteLineNever()
        {
            var players = new List<IPlayer>();
            var renderer = new ConsoleRenderer();

            renderer.RenderGameTopPlayers(players);
        }
        public void RenderGameTopPlayersWhenPassedThreePlayerShouldInvokeConsoleWriteLineMoreThanOnce()
        {
            var player = new Player();
            player.Name = "Player";
            player.Moves = 20;
            var player1 = new Player();
            player1.Name = "Player1";
            player1.Moves = 10;
            var player2 = new Player();
            player2.Name = "Player2";
            player2.Moves = 30;

            var players = new List<IPlayer>()
            {
                player,
                player1,
                player2
            };

            var mockConsole = new Mock<IConsoleWriter>();
            var writer = mockConsole.Object;
            var renderer = new ConsoleRenderer(writer);

            renderer.RenderGameTopPlayers(players);

            mockConsole.Verify(c => c.WriteLine(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>()), Times.AtLeastOnce);
        }
        public void RenderGameTopPlayersWhenPassedOnePlayerShouldInvokeConsoleWriteLineOnce()
        {
            var player = new Player();
            player.Name = "Player";
            player.Moves = 20;
            var players = new List<IPlayer>()
            {
                player
            };

            var mockConsole = new Mock<IConsoleWriter>();
            var writer = mockConsole.Object;
            var renderer = new ConsoleRenderer(writer);

            renderer.RenderGameTopPlayers(players);

            mockConsole.Verify(c => c.WriteLine(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(1));
        }
        public void RenderGameTopPlayersWhenPassedNullShouldthrowException()
        {
            var renderer = new ConsoleRenderer();

            renderer.RenderGameTopPlayers(null);
        }
        public void RenderGameMessageShuldChangeCursorColumnPosition()
        {
            var renderer = new ConsoleRenderer();

            renderer.RenderGameMessage(TestMessage);
            var expectedCursorPosition = Console.WindowWidth / 2 - TestMessage.Length / 2;
            var actualCursorPosition = Console.CursorLeft;

            Assert.AreEqual(expectedCursorPosition, actualCursorPosition);
        }
        public void RenderGameMessageShuldCallConsoleMethodWriteLineOnce()
        {
            var mockConsole = new Mock<IConsoleWriter>();
            var writer = mockConsole.Object;
            var renderer = new ConsoleRenderer(writer);

            renderer.RenderGameMessage(TestMessage);

            mockConsole.Verify(c => c.WriteLine(It.IsAny<string>()), Times.Exactly(1));
        }