public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IOffCapabilityService, IOffCapabilityRepository>(); var model = new ApiOffCapabilityServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <OffCapability>())).Returns(Task.FromResult(new OffCapability())); var service = new OffCapabilityService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.OffCapabilityModelValidatorMock.Object, mock.DALMapperMockFactory.DALOffCapabilityMapperMock, mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock); CreateResponse <ApiOffCapabilityServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.OffCapabilityModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOffCapabilityServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <OffCapability>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OffCapabilityCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IOffCapabilityService, IOffCapabilityRepository>(); var model = new ApiOffCapabilityServerRequestModel(); var validatorMock = new Mock <IApiOffCapabilityServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiOffCapabilityServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new OffCapabilityService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALOffCapabilityMapperMock, mock.DALMapperMockFactory.DALOfficerCapabilitiesMapperMock); CreateResponse <ApiOffCapabilityServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOffCapabilityServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OffCapabilityCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }