public async void Create() { var mock = new ServiceMockFacade <IBucketRepository>(); var model = new ApiBucketRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Bucket>())).Returns(Task.FromResult(new Bucket())); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiBucketResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BucketModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBucketRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Bucket>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IBucketService, IBucketRepository>(); var model = new ApiBucketServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Bucket>())).Returns(Task.FromResult(new Bucket())); var service = new BucketService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.DALMapperMockFactory.DALBucketMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiBucketServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.BucketModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBucketServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Bucket>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BucketCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IBucketService, IBucketRepository>(); var model = new ApiBucketServerRequestModel(); var validatorMock = new Mock <IApiBucketServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiBucketServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new BucketService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALBucketMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiBucketServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBucketServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BucketCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }