public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IBucketService, IBucketRepository>();
            var model         = new ApiBucketServerRequestModel();
            var validatorMock = new Mock <IApiBucketServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiBucketServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Bucket()));
            var service = new BucketService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            validatorMock.Object,
                                            mock.DALMapperMockFactory.DALBucketMapperMock,
                                            mock.DALMapperMockFactory.DALFileMapperMock);

            UpdateResponse <ApiBucketServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiBucketServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BucketUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Beispiel #2
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IBucketRepository>();
            var model = new ApiBucketRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Bucket>())).Returns(Task.FromResult(new Bucket()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).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);

            UpdateResponse <ApiBucketResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.BucketModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiBucketRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Bucket>()));
        }