Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        public void Throw_Argument_Null_Exception_When_Followee_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.SaveUserFollowee("123", null));
        }
Ejemplo n.º 5
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.º 6
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);
        }