コード例 #1
0
        static void Main(string[] args)
        {
            var consoleOutputManager = new ConsoleOutputManager();
            var timeProvider = new TimeProvider();
            var messageRepository = new MessagesRepository();
            var followingRepository = new FollowingRepository();

            consoleOutputManager.WriteLine("Welcome to RetroTwitter");
            consoleOutputManager.WriteLine();
            ShowInstructions(consoleOutputManager);
            consoleOutputManager.WriteLine();

            consoleOutputManager.WriteLine("What do you want to do today?");

            var commandFactory = new CommandCreatorsFactory(consoleOutputManager, timeProvider, messageRepository, followingRepository);
            while (true)
            {
                consoleOutputManager.Write(">");
                var commandString = consoleOutputManager.ReadLine();
                var command = commandFactory.ParseStringToCommand(commandString);
                if (command != null)
                {
                    command.Execute();
                }
                else
                {
                    consoleOutputManager.WriteLine("Sorry, I didn't catch that.");
                }
            }

            consoleOutputManager.WriteLine("RetroTwitter is terminating and all the collected data are being destroyed.");

            // ReSharper disable once FunctionNeverReturns
        }
コード例 #2
0
        public void ConstructorOk()
        {
            var outputManagerMock = new Mock<IOutputManager>();
            var timeProviderMock = new Mock<ITimeProvider>();
            var followingRepositoryMock = new Mock<IFollowingRepository>();
            var messagesRepositoryMock = new Mock<IMessagesRepository>();

            var createdObject = new CommandCreatorsFactory(outputManagerMock.Object, timeProviderMock.Object, messagesRepositoryMock.Object, followingRepositoryMock.Object);

            Assert.AreEqual(4, createdObject.CommandCreators.Count);
            Assert.AreEqual(1, createdObject.CommandCreators.Count(x => x.GetType() == typeof(PostMessageCommandCreator)));
            Assert.AreEqual(1, createdObject.CommandCreators.Count(x => x.GetType() == typeof(ListMessagesCommandCreator)));
            Assert.AreEqual(1, createdObject.CommandCreators.Count(x => x.GetType() == typeof(FollowUserCommandCreator)));
            Assert.AreEqual(1, createdObject.CommandCreators.Count(x => x.GetType() == typeof(ShowWallOfUserCommandCreator)));
        }
コード例 #3
0
        public void FirstParsingCommandIsReturnedWhenSecondOk()
        {
            const string command = "a";
            var mockedExpectedCommand = new Mock<RetroTwitter.Commands.ICommand>().Object;

            commandCreator1Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Single() == command)));
            commandCreator2Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Single() == command))).Returns(mockedExpectedCommand);

            var actual =
                new CommandCreatorsFactory(new List<ICommandCreator>
                {
                    commandCreator1Mock.Object,
                    commandCreator2Mock.Object
                })
                .ParseStringToCommand(command);

            Assert.AreEqual(mockedExpectedCommand, actual);
        }
コード例 #4
0
        public void MoreThanThreeWordsStringParsesOk()
        {
            const string command = "a b c d";

            commandCreator1Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Length == 3 && y[0] == "a" && y[1] == "b" && y[2] == "c d")));

            var actual =
                new CommandCreatorsFactory(new List<ICommandCreator>
                {
                    commandCreator1Mock.Object
                })
                .ParseStringToCommand(command);

            Assert.AreEqual(null, actual);
        }
コード例 #5
0
        public void ZeroWordsStringParsesOk()
        {
            const string command = "";

            commandCreator1Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Length == 0)));

            var actual =
                new CommandCreatorsFactory(new List<ICommandCreator>
                {
                    commandCreator1Mock.Object
                })
                .ParseStringToCommand(command);

            Assert.AreEqual(null, actual);
        }
コード例 #6
0
        public void NoParsingCommandReturnsNullOk()
        {
            const string command = "a";

            commandCreator1Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Single() == command)));
            commandCreator2Mock.Setup(x => x.TryCreate(It.Is<string[]>(y => y.Single() == command)));

            var actual =
                new CommandCreatorsFactory(new List<ICommandCreator>
                {
                    commandCreator1Mock.Object,
                    commandCreator2Mock.Object
                })
                .ParseStringToCommand(command);

            Assert.AreEqual(null, actual);
        }