Exemplo n.º 1
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();

            var model = new ApiOfficerCapabilitiesServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <OfficerCapabilities>())).Returns(Task.FromResult(new OfficerCapabilities()));
            var service = new OfficerCapabilitiesService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.OfficerCapabilitiesModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.OfficerCapabilitiesModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOfficerCapabilitiesServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <OfficerCapabilities>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OfficerCapabilitiesCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemplo n.º 2
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IOfficerCapabilitiesService, IOfficerCapabilitiesRepository>();
            var model         = new ApiOfficerCapabilitiesServerRequestModel();
            var validatorMock = new Mock <IApiOfficerCapabilitiesServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiOfficerCapabilitiesServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new OfficerCapabilitiesService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         validatorMock.Object,
                                                         mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock);

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

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