public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IHandlerService, IHandlerRepository>(); var model = new ApiHandlerServerRequestModel(); var validatorMock = new Mock <IApiHandlerServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiHandlerServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new HandlerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); CreateResponse <ApiHandlerServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiHandlerServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Create() { var mock = new ServiceMockFacade <IHandlerRepository>(); var model = new ApiHandlerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Handler>())).Returns(Task.FromResult(new Handler())); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock); CreateResponse <ApiHandlerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiHandlerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Handler>())); }