示例#1
0
        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>()));
        }
示例#2
0
        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>()));
        }
示例#3
0
        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());
        }