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);
        }
Example #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IFamilyRepository>();
            var model = new ApiFamilyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Family>())).Returns(Task.FromResult(new Family()));
            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);

            CreateResponse <ApiFamilyResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFamilyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Family>()));
        }
Example #3
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IFamilyService, IFamilyRepository>();

            var model = new ApiFamilyServerRequestModel();

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

            CreateResponse <ApiFamilyServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFamilyServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Family>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FamilyCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #4
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IFamilyService, IFamilyRepository>();
            var model         = new ApiFamilyServerRequestModel();
            var validatorMock = new Mock <IApiFamilyServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiFamilyServerRequestModel>())).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);

            CreateResponse <ApiFamilyServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFamilyServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FamilyCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }