public async void Create()
        {
            var mock  = new ServiceMockFacade <IPipelineRepository>();
            var model = new ApiPipelineRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pipeline>())).Returns(Task.FromResult(new Pipeline()));
            var service = new PipelineService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLPipelineMapperMock,
                                              mock.DALMapperMockFactory.DALPipelineMapperMock);

            CreateResponse <ApiPipelineResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pipeline>()));
        }
Exemple #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IPipelineService, IPipelineRepository>();

            var model = new ApiPipelineServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pipeline>())).Returns(Task.FromResult(new Pipeline()));
            var service = new PipelineService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALPipelineMapperMock);

            CreateResponse <ApiPipelineServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.PipelineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pipeline>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemple #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPipelineService, IPipelineRepository>();
            var model         = new ApiPipelineServerRequestModel();
            var validatorMock = new Mock <IApiPipelineServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new PipelineService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              validatorMock.Object,
                                              mock.DALMapperMockFactory.DALPipelineMapperMock);

            CreateResponse <ApiPipelineServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Exemple #4
0
        public async Task <ActionResult <Pipeline> > CreateAsync(Pipeline pipeline)
        {
            await _pipelineService.Create(pipeline);

            return(CreatedAtRoute("GetPipeline", new { id = pipeline.PipelineId.ToString() }, pipeline));
        }