public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IHandlerPipelineStepService service = testServer.Host.Services.GetService(typeof(IHandlerPipelineStepService)) as IHandlerPipelineStepService;
            var model = new ApiHandlerPipelineStepServerRequestModel();

            model.SetProperties(1, 1);
            CreateResponse <ApiHandlerPipelineStepServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.HandlerPipelineStepDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiHandlerPipelineStepServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Beispiel #2
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiHandlerPipelineStepServerModelMapper();
            var model  = new ApiHandlerPipelineStepServerResponseModel();

            model.SetProperties(1, 1, 1);
            ApiHandlerPipelineStepServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.HandlerId.Should().Be(1);
            response.PipelineStepId.Should().Be(1);
        }
Beispiel #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiHandlerPipelineStepServerRequestModel model)
        {
            CreateResponse <ApiHandlerPipelineStepServerResponseModel> result = await this.HandlerPipelineStepService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/HandlerPipelineSteps/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #4
0
        public void CreatePatch()
        {
            var mapper = new ApiHandlerPipelineStepServerModelMapper();
            var model  = new ApiHandlerPipelineStepServerRequestModel();

            model.SetProperties(1, 1);

            JsonPatchDocument <ApiHandlerPipelineStepServerRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiHandlerPipelineStepServerRequestModel();

            patch.ApplyTo(response);
            response.HandlerId.Should().Be(1);
            response.PipelineStepId.Should().Be(1);
        }
Beispiel #5
0
        private async Task <ApiHandlerPipelineStepServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiHandlerPipelineStepServerRequestModel> patch)
        {
            var record = await this.HandlerPipelineStepService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiHandlerPipelineStepServerRequestModel request = this.HandlerPipelineStepModelMapper.MapServerResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #6
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>();
            var model = new ApiHandlerPipelineStepServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new HandlerPipelineStepService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerPipelineStepDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Beispiel #7
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiHandlerPipelineStepServerRequestModel model)
        {
            ApiHandlerPipelineStepServerRequestModel request = await this.PatchModel(id, this.HandlerPipelineStepModelMapper.CreatePatch(model)) as ApiHandlerPipelineStepServerRequestModel;

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiHandlerPipelineStepServerResponseModel> result = await this.HandlerPipelineStepService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #8
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>();
            var model         = new ApiHandlerPipelineStepServerRequestModel();
            var validatorMock = new Mock <IApiHandlerPipelineStepServerRequestModelValidator>();

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

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerPipelineStepDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Beispiel #9
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiHandlerPipelineStepServerRequestModel> patch)
        {
            ApiHandlerPipelineStepServerResponseModel record = await this.HandlerPipelineStepService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiHandlerPipelineStepServerRequestModel model = await this.PatchModel(id, patch) as ApiHandlerPipelineStepServerRequestModel;

                UpdateResponse <ApiHandlerPipelineStepServerResponseModel> result = await this.HandlerPipelineStepService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }