Пример #1
0
        public void GivenAliceWantsToReadCharliesWallButCharlieHasNoMessagesOnHisWallWhenProcessUserInputIsCalledThenTheProgramDisplaysNothing()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            this.consoleMock.ConsoleRead().Returns("charlie");

            var program = new Program(this.consoleMock, parser, this.formaterFactoryMock);

            program.ProcessUserInput();

            this.consoleMock.DidNotReceive().ConsoleWrite(string.Empty);
        }
Пример #2
0
        public static void Main()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            var formaterFactory = new MessageFormaterFactory();
            var consoleWrapper = new ConsoleWrapper();

            var program = new Program(consoleWrapper, parser, formaterFactory);

            while (program.ProcessUserInput())
            {
            }
        }
Пример #3
0
        public void GivenAliceWantsToReadCharliesWallAndCharlieHasMessagesOnHisWallWhenProcessUserInputIsCalledThenTheProgramDisplaysCharliesWallMessagesAndHowLongHasCharliePostedEachMessage()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            var charlie = repository.Create("charlie");
            charlie.Post("message from charlie");

            this.consoleMock.ConsoleRead().Returns("charlie");

            var program = new Program(this.consoleMock, parser, new MessageFormaterFactory());

            program.ProcessUserInput();

            this.consoleMock.Received().ConsoleWrite("message from charlie (0 seconds ago)");
        }
Пример #4
0
        public void GivenCharlieAndAliceAreUsersInTheSystemAndCharlieFollowsAliceWhenAWallCommandOnCharlieIsRequestedThenCharliesWallShouldContainPostsFromAliceAndCharlie()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            var charlie = repository.Create("charlie");
            repository.Create("alice");

            var program = new Program(this.consoleMock, parser, new MessageFormaterFactory());

            this.consoleMock.ConsoleRead().Returns("charlie follows alice");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("charlie -> message from charlie");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("alice -> message from alice");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("charlie wall");
            program.ProcessUserInput();

            charlie.Wall.Count().Should().Be(2);
        }
Пример #5
0
        public void GivenTheUserTypesAPostCommandWhenProcessUserInputIsCalledThenTheUserWallShouldContainPostedMessage()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            this.consoleMock.ConsoleRead().Returns("Bob -> my message");

            var program = new Program(this.consoleMock, parser, this.formaterFactoryMock);

            program.ProcessUserInput();

            var user = repository.FindByIdentifier("Bob");

            user.Wall.Should().Contain(m => m.Body == "my message");
        }
Пример #6
0
        public void GivenTheUserTypesAPostCommandWhenProcessUserInputIsCalledThenPostOnUserWallIsInvokedIndirectely()
        {
            var broker = new MessageBroker(this.repositoryMock);

            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            this.consoleMock.ConsoleRead().Returns("Bob -> my message");

            this.repositoryMock.FindByIdentifier("Bob").Returns(this.bob);

            var program = new Program(this.consoleMock, parser, this.formaterFactoryMock);

            program.ProcessUserInput();

            this.userWallMock.Received().Post(this.bob, "my message");
        }
Пример #7
0
        public void GivenTheUserTypesAPostCommandWhenProcessUserInputIsCalledThenPostOnMessageBrokerIsInvokedIndirectely()
        {
            var commandFactory = new CommandFactory(this.brokerMock);
            var parser = new InputParser(commandFactory);

            this.consoleMock.ConsoleRead().Returns("Bob -> my message");

            var program = new Program(this.consoleMock, parser, this.formaterFactoryMock);

            program.ProcessUserInput();

            this.brokerMock.Received().Post("Bob", "my message");
        }
Пример #8
0
        public void GivenCharlieAndAliceAreUsersInTheSystemWhenCharlieFollowsAliceThenAliceFollowersShouldContainCharlie()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            var charlie = repository.Create("charlie");
            var alice = repository.Create("alice");

            this.consoleMock.ConsoleRead().Returns("charlie follows alice");

            var program = new Program(this.consoleMock, parser, this.formaterFactoryMock);

            program.ProcessUserInput();

            alice.Followers.Should().Contain(charlie);
        }
Пример #9
0
        public void GivenCharlieAndAliceAreUsersInTheSystemAndCharlieFollowsAliceWhenAWallCommandOnCharlieIsRequestedThenItDisplayCharliesWallStatingTheAuthorOfThePosts()
        {
            var repository = new UserRepository();
            var broker = new MessageBroker(repository);
            var commandFactory = new CommandFactory(broker);
            var parser = new InputParser(commandFactory);

            repository.Create("charlie");
            repository.Create("alice");

            var program = new Program(this.consoleMock, parser, new MessageFormaterFactory());

            this.consoleMock.ConsoleRead().Returns("charlie follows alice");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("charlie -> message from charlie");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("alice -> message from alice");
            program.ProcessUserInput();

            this.consoleMock.ConsoleRead().Returns("charlie wall");
            program.ProcessUserInput();

            this.consoleMock.Received().ConsoleWrite("charlie - message from charlie (0 seconds ago)");
            this.consoleMock.Received().ConsoleWrite("alice - message from alice (0 seconds ago)");
        }
 public void Setup()
 {
     this.factory = Substitute.For<ICommandFactory>();
     this.parser = new InputParser(this.factory);
 }