예제 #1
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IOfficerService, IOfficerRepository>();

            var model = new ApiOfficerServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Officer>())).Returns(Task.FromResult(new Officer()));
            var service = new OfficerService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALNoteMapperMock,
                                             mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock,
                                             mock.DALMapperMockFactory.DALUnitOfficerMapperMock,
                                             mock.DALMapperMockFactory.DALVehicleOfficerMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.OfficerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOfficerServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Officer>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OfficerCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
예제 #2
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IOfficerService, IOfficerRepository>();
            var model         = new ApiOfficerServerRequestModel();
            var validatorMock = new Mock <IApiOfficerServerRequestModelValidator>();

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

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

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