public FamiliesControllerTests()
        {
            var list = new List <Family>
            {
                new Family {
                    Id = 1, Name = "test 1", BusinessId = 2
                },
                new Family {
                    Id = 2, Name = "test 2", BusinessId = 1
                }
            }.AsQueryable();

            var mockContext        = Substitute.For <TtContext>();
            var familyRepository   = Substitute.For <Repository <Family> >(mockContext);
            var businessRepository = Substitute.For <Repository <Business> >(mockContext);

            _service = Substitute.For <FamilyService>(familyRepository, businessRepository);
            _service.GetList().Returns(list);
            _service.GetItem(Arg.Any <int>()).Returns(new Family {
                Id = 1, Name = "test 1", BusinessId = 1
            });
            _service.Create(Arg.Any <Family>());
            _service.Update(Arg.Any <int>(), Arg.Any <Family>());
            _service.Delete(Arg.Any <int>());

            var mockLogger = Substitute.For <ILoggerFactory>();

            _controller = new FamiliesController(_service, mockLogger);
        }
예제 #2
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IFamilyRepository>();
            var model = new ApiFamilyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
예제 #3
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IFamilyService, IFamilyRepository>();
            var model = new ApiFamilyServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FamilyDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
예제 #4
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IFamilyService, IFamilyRepository>();
            var model         = new ApiFamilyServerRequestModel();
            var validatorMock = new Mock <IApiFamilyServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            validatorMock.Object,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FamilyDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
        public void FamilyService_Delete_Throws_On_Null_Family()
        {
            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<ArgumentNullException>(() => _service.Delete(null));
        }
        public void FamilyService_Delete_Calls_UnitOfWork_Commit_Method()
        {
            // Create test data
            var newFamily = new Family
                                    {
                                        WifeId = TestConstants.ID_WifeId,
                                        HusbandId = TestConstants.ID_HusbandId
                                    };

            //Create Mock
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Family>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Act
            _service.Delete(newFamily);

            //Assert
            _mockUnitOfWork.Verify(db => db.Commit());
        }
        public void FamilyService_Delete_Calls_Repsoitory_Delete_Method_With_The_Same_Family_Object_It_Recieved()
        {
            // Create test data
            var newFamily = new Family
                                    {
                                        WifeId = TestConstants.ID_WifeId,
                                        HusbandId = TestConstants.ID_HusbandId
                                    };

            //Create Mock
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Family>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Act
            _service.Delete(newFamily);

            //Assert
            mockRepository.Verify(r => r.Delete(newFamily));
        }