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; IPipelineStepNoteService service = testServer.Host.Services.GetService(typeof(IPipelineStepNoteService)) as IPipelineStepNoteService; var model = new ApiPipelineStepNoteServerRequestModel(); model.SetProperties(1, "B", 1); CreateResponse <ApiPipelineStepNoteServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.PipelineStepNoteDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPipelineStepNoteServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerResponseToRequest() { var mapper = new ApiPipelineStepNoteServerModelMapper(); var model = new ApiPipelineStepNoteServerResponseModel(); model.SetProperties(1, 1, "A", 1); ApiPipelineStepNoteServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.EmployeeId.Should().Be(1); response.Note.Should().Be("A"); response.PipelineStepId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiPipelineStepNoteServerRequestModel model) { CreateResponse <ApiPipelineStepNoteServerResponseModel> result = await this.PipelineStepNoteService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PipelineStepNotes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiPipelineStepNoteServerModelMapper(); var model = new ApiPipelineStepNoteServerRequestModel(); model.SetProperties(1, "A", 1); JsonPatchDocument <ApiPipelineStepNoteServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPipelineStepNoteServerRequestModel(); patch.ApplyTo(response); response.EmployeeId.Should().Be(1); response.Note.Should().Be("A"); response.PipelineStepId.Should().Be(1); }
private async Task <ApiPipelineStepNoteServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiPipelineStepNoteServerRequestModel> patch) { var record = await this.PipelineStepNoteService.Get(id); if (record == null) { return(null); } else { ApiPipelineStepNoteServerRequestModel request = this.PipelineStepNoteModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IPipelineStepNoteService, IPipelineStepNoteRepository>(); var model = new ApiPipelineStepNoteServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PipelineStepNoteService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineStepNoteModelValidatorMock.Object, mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock); 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.PipelineStepNoteModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineStepNoteDeletedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPipelineStepNoteServerRequestModel model) { ApiPipelineStepNoteServerRequestModel request = await this.PatchModel(id, this.PipelineStepNoteModelMapper.CreatePatch(model)) as ApiPipelineStepNoteServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPipelineStepNoteServerResponseModel> result = await this.PipelineStepNoteService.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 <IPipelineStepNoteService, IPipelineStepNoteRepository>(); var model = new ApiPipelineStepNoteServerRequestModel(); var validatorMock = new Mock <IApiPipelineStepNoteServerRequestModelValidator>(); 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 PipelineStepNoteService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock); 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 <PipelineStepNoteDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPipelineStepNoteServerRequestModel> patch) { ApiPipelineStepNoteServerResponseModel record = await this.PipelineStepNoteService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPipelineStepNoteServerRequestModel model = await this.PatchModel(id, patch) as ApiPipelineStepNoteServerRequestModel; UpdateResponse <ApiPipelineStepNoteServerResponseModel> result = await this.PipelineStepNoteService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }