public void Build_GenerateMockUserRepository()
        {
            var result = new MockUserRepositoryBuilder()
                         .Build();

            Assert.NotNull(result);
        }
        public void WithAddUser_SetUpAddUserMethod_VerifyCollaborators(IUser user)
        {
            var result = new MockUserRepositoryBuilder()
                         .WithAddUser()
                         .Build();

            Action addUser = () => result.AddUser(user);

            addUser.Should().NotThrow <Exception>();
        }
        public void WithGetUser_SetUpGetUserMethod_VerifyCollaborators(IUser user)
        {
            var result = new MockUserRepositoryBuilder()
                         .WithGetUser(user)
                         .Build();

            Assert.Equal
            (
                user,
                result.GetUser(user.Name)
            );
        }
        public void WithHasUser_SetUpHasUserMethod_VerifyCollaborators(bool hasUser)
        {
            var result = new MockUserRepositoryBuilder()
                         .WithHasUser(hasUser)
                         .Build();

            Assert.Equal
            (
                hasUser,
                result.HasUser("AnyUser")
            );
        }
Esempio n. 5
0
        public void ProcessCommand_NonExistingUser_VerifyCollaborators()
        {
            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(false)
                                 .Build();

            new ReadingHandler(userRepository).ProcessCommand("James");

            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()));
            Mock.Get(userRepository)
            .Verify(m => m.GetUser(It.IsAny <string>()), Times.Never);
        }
        public void ProcessCommand_NonExistingUser_VerifyCollaborators()
        {
            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(false)
                                 .WithAddUser()
                                 .Build();

            new PostingHandler(userRepository)
            .ProcessCommand("James -> Hello, Hello");

            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()));
            Mock.Get(userRepository)
            .Verify(m => m.AddUser(It.IsAny <IUser>()));
        }
        public void ProcessCommand_ExistingUser_UserFollowsThemselves_VerifyCollaborators()
        {
            var user = Mock.Of <IUser>();

            Mock.Get(user)
            .Setup(m => m.SubscribeToTimeLine(It.IsAny <IUser>()));

            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(false)
                                 .WithGetUser(user)
                                 .Build();


            new FollowingHandler(userRepository).ProcessCommand("Sophie follows Sophie");


            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()), Times.Never);
            Mock.Get(user)
            .Verify(m => m.SubscribeToTimeLine(It.IsAny <IUser>()), Times.Never);
        }
        public void ProcessCommand_ExistingUsers_VerifyCollaborators()
        {
            var user = Mock.Of <IUser>();

            Mock.Get(user)
            .Setup(m => m.SubscribeToTimeLine(It.IsAny <IUser>()));

            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(true)
                                 .WithGetUser(user)
                                 .Build();

            new FollowingHandler(userRepository).ProcessCommand("James follows Bob");

            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()), Times.Exactly(2));
            Mock.Get(userRepository)
            .Verify(m => m.GetUser(It.IsAny <string>()), Times.Exactly(2));
            Mock.Get(user)
            .Verify(m => m.SubscribeToTimeLine(It.IsAny <IUser>()));
        }
        public void ProcessCommand_ExistingUser_VerifyCollaborators()
        {
            var user = Mock.Of <IUser>();

            Mock.Get(user)
            .Setup(m => m.PublishMessage(It.IsAny <DateTimeOffset>(), It.IsAny <string>()));

            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(true)
                                 .WithGetUser(user)
                                 .Build();

            new PostingHandler(userRepository).ProcessCommand("James -> Hello, Hello");

            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()));
            Mock.Get(userRepository)
            .Verify(m => m.GetUser(It.IsAny <string>()));
            Mock.Get(user)
            .Verify(m => m.PublishMessage(It.IsAny <DateTimeOffset>(), It.IsAny <string>()));
        }
Esempio n. 10
0
        public void ProcessCommand_ExistingUser_VerifyCollaborators()
        {
            var user = Mock.Of <IUser>();

            Mock.Get(user)
            .Setup(m => m.AggregatedTimeLine(It.IsAny <DateTimeOffset>(), It.IsAny <ITimeSpanDisplayFormatter>()))
            .Returns("> James\r\nHello World. (1 minute ago)\r\nMy name is James. (3 minute ago)\r\nI am Ugandan. (4 minute ago)");

            var userRepository = new MockUserRepositoryBuilder()
                                 .WithHasUser(true)
                                 .WithGetUser(user)
                                 .Build();

            new ReadingHandler(userRepository).ProcessCommand("James");

            Mock.Get(userRepository)
            .Verify(m => m.HasUser(It.IsAny <string>()));
            Mock.Get(userRepository)
            .Verify(m => m.GetUser(It.IsAny <string>()));
            Mock.Get(user)
            .Verify(m => m.AggregatedTimeLine(It.IsAny <DateTimeOffset>(), It.IsAny <ITimeSpanDisplayFormatter>()));
        }