コード例 #1
0
        public void NotCallGetByIdMethod_WhenPassedIdIsNull()
        {
            // Arrange
            var mockedEfWrappert = new Mock <IEfDbSetWrapper <Individual> >();

            mockedEfWrappert.Setup(x => x.GetById(It.IsAny <Guid>())).Verifiable();
            var mockedDbContext = new Mock <IUnitOfWork>();

            var service = new IndividualService(mockedEfWrappert.Object, mockedDbContext.Object);

            // Act
            service.ConfirmFriendship("testUserId", null);

            // Assert
            mockedEfWrappert.Verify(x => x.GetById(It.IsAny <Guid>()), Times.Never);
        }
コード例 #2
0
        public void NotCallUpdateMethod_WhenParamsDoesntMatch()
        {
            // Arrange
            var data             = new List <Individual>();
            var mockedEfWrappert = new Mock <IEfDbSetWrapper <Individual> >();

            mockedEfWrappert.Setup(x => x.GetById(It.IsAny <Guid>())).Returns((Individual)null);
            mockedEfWrappert.SetupGet(m => m.All).Returns(data.AsQueryable());
            mockedEfWrappert.Setup(x => x.Update(It.IsAny <Individual>())).Verifiable();
            var mockedDbContext = new Mock <IUnitOfWork>();

            var service = new IndividualService(mockedEfWrappert.Object, mockedDbContext.Object);

            // Act
            service.ConfirmFriendship("testUserId", Guid.NewGuid());

            // Assert
            mockedEfWrappert.Verify(x => x.Update(It.IsAny <Individual>()), Times.Never);
        }
コード例 #3
0
        public void CallUpdateMethod_WhenParamsMatch()
        {
            // Arrange
            var username = "******";
            var user     = new User();

            user.UserName = username;
            var individual = new Individual();

            individual.User = user;

            var id     = Guid.NewGuid();
            var friend = new Individual();

            friend.Id = id;

            var data = new List <Individual>();

            data.Add(individual);
            data.Add(friend);

            var mockedEfWrappert = new Mock <IEfDbSetWrapper <Individual> >();

            mockedEfWrappert.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(friend);
            mockedEfWrappert.SetupGet(m => m.All).Returns(data.AsQueryable());
            mockedEfWrappert.Setup(x => x.Update(It.IsAny <Individual>())).Verifiable();
            var mockedDbContext = new Mock <IUnitOfWork>();

            var service = new IndividualService(mockedEfWrappert.Object, mockedDbContext.Object);

            // Act
            service.ConfirmFriendship(username, id);

            // Assert
            mockedEfWrappert.Verify(x => x.Update(It.IsAny <Individual>()), Times.Exactly(2));
        }