public void Invoke_SaveChanges_When_UserFollowee_Exists()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, fakeDateTimeProvider);

            var userFollowee = new UserFollowee {
                UserId = "123", FolloweeId = "456"
            };
            var userFolloweeCollection = new List <UserFollowee> {
                userFollowee
            };

            fakeUserFolloweeRepo.Setup(s => s.All).Returns(userFolloweeCollection.AsQueryable);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);
            fakeUnit.Setup(s => s.SaveChanges()).Verifiable();

            //Act
            sut.DeleteUserFollowee(userFollowee.UserId, userFollowee.FolloweeId);

            //Assert
            fakeUnit.Verify(v => v.SaveChanges(), Times.Once);
        }
Ejemplo n.º 2
0
        public void Invoke_Add_In_UserFolloweeRepo_When_Followee_Is_New()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeFolloweeRepo     = new Mock <IGenericRepository <Followee> >();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, fakeDateTimeProvider);

            var followee = new Followee {
                FolloweeId = "456"
            };
            var userFolloweeToAdd = new FolloweeFromApiDto {
                FolloweeId = "789"
            };
            var followeeCollection = new List <Followee> {
                followee
            };

            fakeFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(followeeCollection.AsQueryable());
            fakeUnit.Setup(u => u.Followees).Returns(fakeFolloweeRepo.Object);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);
            fakeFolloweeService.Setup(s => s.Create(userFolloweeToAdd)).Returns(new Followee {
                FolloweeId = userFolloweeToAdd.FolloweeId
            });
            //Act
            sut.SaveUserFollowee("123", userFolloweeToAdd);

            //Assert
            fakeUserFolloweeRepo.Verify(v => v.Add(It.IsAny <UserFollowee>()), Times.Once());
        }
Ejemplo n.º 3
0
        public void Invoke_SaveChanges_When_Followee_Exists_But_Deleted()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var dateTimeProvider     = new TestDateTimeProvider();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeFolloweeRepo     = new Mock <IGenericRepository <Followee> >();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, dateTimeProvider);

            var followee = new Followee {
                FolloweeId = "789", IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var userFolloweeToAdd = new FolloweeFromApiDto {
                FolloweeId = "789"
            };
            var followeeCollection = new List <Followee> {
                followee
            };

            fakeFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(followeeCollection.AsQueryable());
            fakeUnit.Setup(u => u.Followees).Returns(fakeFolloweeRepo.Object);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);
            fakeUnit.Setup(s => s.SaveChanges()).Verifiable();

            //Act
            sut.SaveUserFollowee("456", userFolloweeToAdd);

            //Assert
            fakeUnit.Verify(v => v.SaveChanges(), Times.Exactly(2)); // once for saving the changes of Deleted state and once for the UserFollowee
        }
Ejemplo n.º 4
0
        public void Change_DeletedOn_When_Followee_Exist_But_Deleted()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var dateTimeProvider     = new TestDateTimeProvider();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeFolloweeRepo     = new Mock <IGenericRepository <Followee> >();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, dateTimeProvider);

            var followee = new Followee {
                FolloweeId = "789", IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var userFolloweeToAdd = new FolloweeFromApiDto {
                FolloweeId = "789"
            };
            var followeeCollection = new List <Followee> {
                followee
            };

            fakeFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(followeeCollection.AsQueryable());
            fakeUnit.Setup(u => u.Followees).Returns(fakeFolloweeRepo.Object);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);

            //Act
            sut.SaveUserFollowee("456", userFolloweeToAdd);

            //Assert
            Assert.AreEqual(dateTimeProvider.Now, followee.ModifiedOn.Value);
        }
Ejemplo n.º 5
0
        public void Return_False_When_User_Saved_This_Followee()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, fakeDateTimeProvider);

            var userFollowee = new UserFollowee {
                UserId = "123", FolloweeId = "456"
            };
            var userFolloweeCollection = new List <UserFollowee> {
                userFollowee
            };

            fakeUserFolloweeRepo.Setup(s => s.All).Returns(userFolloweeCollection.AsQueryable());
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);

            //Act
            var expectedResult = sut.AnyUserSavedThisFolloweeById("123");

            //Assert
            Assert.IsFalse(expectedResult);
        }
Ejemplo n.º 6
0
        public void Return_False_When_UserFollowee_Does_Not_Exist()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = Mock.Of <IFolloweeService>();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService, fakeDateTimeProvider);

            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();

            var userFollowee = new UserFollowee {
                UserId = "123", FolloweeId = "456"
            };

            var userFolloweeCollection = new List <UserFollowee> {
                userFollowee
            };

            fakeUserFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(userFolloweeCollection.AsQueryable());
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);

            //Act
            var exists = sut.UserFolloweeExistsInDeleted(userFollowee.UserId, "789");

            //Assert
            Assert.IsFalse(exists);
        }
        public void Throw_Argument_Null_Exception_When_FolloweeId_Is_Null()
        {
            //Arrange
            var fakeUnit             = Mock.Of <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = Mock.Of <IFolloweeService>();

            var sut = new UserFolloweeService(fakeUnit, fakeFolloweeService, fakeDateTimeProvider);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => sut.DeleteUserFollowee("123", null));
        }
Ejemplo n.º 8
0
        public void Throw_Argument_Null_Exception_When_UserId_Is_Null()
        {
            //Arrange
            var fakeUnit             = Mock.Of <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = Mock.Of <IFolloweeService>();
            var followee             = new FolloweeFromApiDto();
            var sut = new UserFolloweeService(fakeUnit, fakeFolloweeService, fakeDateTimeProvider);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => sut.SaveUserFollowee(null, followee));
        }
Ejemplo n.º 9
0
        public void Change_Deleted_State_When_Followee_Exists_UserFollowee_Is_Deleted()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var dateTimeProvider     = new TestDateTimeProvider();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeFolloweeRepo     = new Mock <IGenericRepository <Followee> >();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, dateTimeProvider);

            var followee = new Followee {
                FolloweeId = "789", IsDeleted = false
            };
            var userFolloweeToAdd = new FolloweeFromApiDto {
                FolloweeId = "789"
            };
            var followeeCollection = new List <Followee> {
                followee
            };
            var userFollowee = new UserFollowee {
                UserId = "456", FolloweeId = userFolloweeToAdd.FolloweeId, IsDeleted = true, DeletedOn = dateTimeProvider.DeletedOn
            };
            var userFolloweeCollection = new List <UserFollowee> {
                userFollowee
            };

            fakeUserFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(userFolloweeCollection.AsQueryable());
            fakeFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(followeeCollection.AsQueryable());
            fakeUnit.Setup(u => u.Followees).Returns(fakeFolloweeRepo.Object);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);

            //Act
            sut.SaveUserFollowee("456", userFolloweeToAdd);

            //Assert
            Assert.IsFalse(userFollowee.IsDeleted);
            Assert.IsNull(userFollowee.DeletedOn);
        }
Ejemplo n.º 10
0
        public void Invoke_SaveChanges_When_Followee_Exists_UserFollowee_Is_New()
        {
            //Arrange
            var fakeUnit             = new Mock <IUnitOfWork>();
            var fakeDateTimeProvider = Mock.Of <IDateTimeProvider>();
            var fakeFolloweeService  = new Mock <IFolloweeService>();
            var fakeFolloweeRepo     = new Mock <IGenericRepository <Followee> >();
            var fakeUserFolloweeRepo = new Mock <IGenericRepository <UserFollowee> >();
            var sut = new UserFolloweeService(fakeUnit.Object, fakeFolloweeService.Object, fakeDateTimeProvider);

            var followee = new Followee {
                FolloweeId = "789", IsDeleted = false
            };
            var userFolloweeToAdd = new FolloweeFromApiDto {
                FolloweeId = "789"
            };
            var followeeCollection = new List <Followee> {
                followee
            };
            var userFollowee = new UserFollowee {
                UserId = "456", FolloweeId = "444"
            };
            var userFolloweeCollection = new List <UserFollowee> {
                userFollowee
            };

            fakeUserFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(userFolloweeCollection.AsQueryable());
            fakeFolloweeRepo.Setup(r => r.AllAndDeleted).Returns(followeeCollection.AsQueryable());
            fakeUnit.Setup(u => u.Followees).Returns(fakeFolloweeRepo.Object);
            fakeUnit.Setup(u => u.UserFollowees).Returns(fakeUserFolloweeRepo.Object);

            //Act
            sut.SaveUserFollowee("456", userFolloweeToAdd);

            //Assert
            fakeUnit.Verify(v => v.SaveChanges(), Times.Once);
        }