public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IPipelineStepService, IPipelineStepRepository>(); var model = new ApiPipelineStepServerRequestModel(); var validatorMock = new Mock <IApiPipelineStepServerRequestModelValidator>(); 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 PipelineStepService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock, mock.DALMapperMockFactory.DALPipelineStepDestinationMapperMock, mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock, mock.DALMapperMockFactory.DALPipelineStepStepRequirementMapperMock); 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 <PipelineStepDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IPipelineStepService, IPipelineStepRepository>(); var model = new ApiPipelineStepServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PipelineStep>())).Returns(Task.FromResult(new PipelineStep())); var service = new PipelineStepService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineStepModelValidatorMock.Object, mock.DALMapperMockFactory.DALPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock, mock.DALMapperMockFactory.DALPipelineStepDestinationMapperMock, mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock, mock.DALMapperMockFactory.DALPipelineStepStepRequirementMapperMock); CreateResponse <ApiPipelineStepServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.PipelineStepModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineStepServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PipelineStep>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineStepCreatedNotification>(), It.IsAny <CancellationToken>())); }
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; IPipelineStepService service = testServer.Host.Services.GetService(typeof(IPipelineStepService)) as IPipelineStepService; var model = new ApiPipelineStepServerRequestModel(); model.SetProperties("B", 1, 1); CreateResponse <ApiPipelineStepServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.PipelineStepDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPipelineStepServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Create([FromBody] ApiPipelineStepServerRequestModel model) { CreateResponse <ApiPipelineStepServerResponseModel> result = await this.PipelineStepService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PipelineSteps/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapServerResponseToRequest() { var mapper = new ApiPipelineStepServerModelMapper(); var model = new ApiPipelineStepServerResponseModel(); model.SetProperties(1, "A", 1, 1); ApiPipelineStepServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Name.Should().Be("A"); response.PipelineStepStatusId.Should().Be(1); response.ShipperId.Should().Be(1); }
private async Task <ApiPipelineStepServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiPipelineStepServerRequestModel> patch) { var record = await this.PipelineStepService.Get(id); if (record == null) { return(null); } else { ApiPipelineStepServerRequestModel request = this.PipelineStepModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiPipelineStepServerModelMapper(); var model = new ApiPipelineStepServerRequestModel(); model.SetProperties("A", 1, 1); JsonPatchDocument <ApiPipelineStepServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPipelineStepServerRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); response.PipelineStepStatusId.Should().Be(1); response.ShipperId.Should().Be(1); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPipelineStepServerRequestModel model) { ApiPipelineStepServerRequestModel request = await this.PatchModel(id, this.PipelineStepModelMapper.CreatePatch(model)) as ApiPipelineStepServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPipelineStepServerResponseModel> result = await this.PipelineStepService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPipelineStepServerRequestModel> patch) { ApiPipelineStepServerResponseModel record = await this.PipelineStepService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPipelineStepServerRequestModel model = await this.PatchModel(id, patch) as ApiPipelineStepServerRequestModel; UpdateResponse <ApiPipelineStepServerResponseModel> result = await this.PipelineStepService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }