示例#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
        }
        public void AddAndGetNewUserAndTwoMessagesOk()
        {
            var messagesRepository = new MessagesRepository();

            const string username = "******";

            var timestamp1 = new DateTime(2001, 2, 3, 4, 5, 6);
            const string message1 = "testMessage1";

            var timestamp2 = new DateTime(2002, 2, 3, 4, 5, 6);
            const string message2 = "testMessage2";

            messagesRepository.Add(username, timestamp1, message1);
            messagesRepository.Add(username, timestamp2, message2);

            var actual = messagesRepository.Get(username).ToList();

            Assert.AreEqual(2, actual.Count);

            Assert.AreEqual(username, actual.Single(x => x.Message == message1).Sender);
            Assert.AreEqual(timestamp1, actual.Single(x => x.Message == message1).Timestamp);

            Assert.AreEqual(username, actual.Single(x => x.Message == message2).Sender);
            Assert.AreEqual(timestamp2, actual.Single(x => x.Message == message2).Timestamp);
        }
        public void GetNonExistingMessagesOk()
        {
            var messagesRepository = new MessagesRepository();

            const string username = "******";

            var actual = messagesRepository.Get(username).ToList();

            Assert.AreEqual(actual.Count, 0);
        }
        public void AddAndGetNewUserAndMessageOk()
        {
            var messagesRepository = new MessagesRepository();

            var timestamp = new DateTime(2001, 2, 3, 4, 5, 6);
            const string username = "******";
            const string message = "testMessage";

            messagesRepository.Add(username, timestamp, message);

            var actual = messagesRepository.Get(username).ToList();

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(username, actual.Single().Sender);
            Assert.AreEqual(timestamp, actual.Single().Timestamp);
            Assert.AreEqual(message, actual.Single().Message);
        }