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; IOtherTransportService service = testServer.Host.Services.GetService(typeof(IOtherTransportService)) as IOtherTransportService; var model = new ApiOtherTransportServerRequestModel(); model.SetProperties(1, 1); CreateResponse <ApiOtherTransportServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.OtherTransportDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiOtherTransportServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerResponseToRequest() { var mapper = new ApiOtherTransportServerModelMapper(); var model = new ApiOtherTransportServerResponseModel(); model.SetProperties(1, 1, 1); ApiOtherTransportServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.HandlerId.Should().Be(1); response.PipelineStepId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiOtherTransportServerRequestModel model) { CreateResponse <ApiOtherTransportServerResponseModel> result = await this.OtherTransportService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/OtherTransports/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiOtherTransportServerModelMapper(); var model = new ApiOtherTransportServerRequestModel(); model.SetProperties(1, 1); JsonPatchDocument <ApiOtherTransportServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiOtherTransportServerRequestModel(); patch.ApplyTo(response); response.HandlerId.Should().Be(1); response.PipelineStepId.Should().Be(1); }
private async Task <ApiOtherTransportServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiOtherTransportServerRequestModel> patch) { var record = await this.OtherTransportService.Get(id); if (record == null) { return(null); } else { ApiOtherTransportServerRequestModel request = this.OtherTransportModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IOtherTransportService, IOtherTransportRepository>(); var model = new ApiOtherTransportServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new OtherTransportService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.OtherTransportModelValidatorMock.Object, mock.DALMapperMockFactory.DALOtherTransportMapperMock); 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.OtherTransportModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OtherTransportDeletedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiOtherTransportServerRequestModel model) { ApiOtherTransportServerRequestModel request = await this.PatchModel(id, this.OtherTransportModelMapper.CreatePatch(model)) as ApiOtherTransportServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiOtherTransportServerResponseModel> result = await this.OtherTransportService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IOtherTransportService, IOtherTransportRepository>(); var model = new ApiOtherTransportServerRequestModel(); var validatorMock = new Mock <IApiOtherTransportServerRequestModelValidator>(); 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 OtherTransportService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALOtherTransportMapperMock); 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 <OtherTransportDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiOtherTransportServerRequestModel> patch) { ApiOtherTransportServerResponseModel record = await this.OtherTransportService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiOtherTransportServerRequestModel model = await this.PatchModel(id, patch) as ApiOtherTransportServerRequestModel; UpdateResponse <ApiOtherTransportServerResponseModel> result = await this.OtherTransportService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }