Example #1
0
        static void Main(string[] args)
        {
            var timeProvider = new SystemCurrentTimeProvider();

            var repo = new UserRepository();
            var getUser = new CreateOrRetrieveUserByName(repo);

            var output = new StandardOutput();
            var formatter = new PostFormatter(timeProvider);
            var printer = new PrintPosts(formatter, output);
            var printWall = new PrintWall(formatter, output);

            var publisher = new PublishPost(timeProvider);
            var follow = new FollowUser();

            var dispatcher = new CommandDispatcher(
                getUser, printer, publisher, follow, printWall);

            while(true)
            {
                Console.Write("> ");
                var input = Console.ReadLine();
                dispatcher.Run(input.Split(' '));
            }
        }
        public void RetrievesUsersThatExist()
        {
            var spy = new UserRepositorySpy();
            var command = new CreateOrRetrieveUserByName(spy);

            var user = command.Execute("Alice");

            Assert.Null(spy.AddCalledWith);
            Assert.Equal("Alice", user.Name);
        }
        public void CreatesAUserIfNotExisting()
        {
            var spy = new UserRepositorySpy();
            var command = new CreateOrRetrieveUserByName(spy);

            var user = command.Execute("Bob");

            Assert.Equal("Bob", spy.AddCalledWith.Name);
            Assert.Equal("Bob", user.Name);
        }
Example #4
0
        public void UsernameFollowUsernameFollowsUser()
        {
            var alice = new User("Alice");
            var bob = new User("Bob");
            var repo = new UserRepository();
            repo.Add(alice);
            repo.Add(bob);
            var retriever = new CreateOrRetrieveUserByName(repo);

            var spy = new PrintPostsSpy();
            var pSpy = new PublishPostSpy();
            var fSpy = new FollowUserSpy();
            var wSpy = new PrintWallSpy();
            var dispatcher = new CommandDispatcher(retriever, spy, pSpy, fSpy, wSpy);
            dispatcher.Run(new[] { "Alice", "follows", "Bob" });

            Assert.Equal(alice, fSpy.UserCalledWith);
            Assert.Equal(bob, fSpy.UserToFollowCalledWith);
        }