public virtual async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); var mapper = new ApiPipelineStepNoteServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IPipelineStepNoteService service = testServer.Host.Services.GetService(typeof(IPipelineStepNoteService)) as IPipelineStepNoteService; ApiPipelineStepNoteServerResponseModel model = await service.Get(1); ApiPipelineStepNoteClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(1, "B", 1); UpdateResponse <ApiPipelineStepNoteClientResponseModel> updateResponse = await client.PipelineStepNoteUpdateAsync(model.Id, request); context.Entry(context.Set <PipelineStepNote>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <PipelineStepNote>().ToList()[0].EmployeeId.Should().Be(1); context.Set <PipelineStepNote>().ToList()[0].Note.Should().Be("B"); context.Set <PipelineStepNote>().ToList()[0].PipelineStepId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.EmployeeId.Should().Be(1); updateResponse.Record.Note.Should().Be("B"); updateResponse.Record.PipelineStepId.Should().Be(1); }
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 async virtual Task <IActionResult> Get(int id) { ApiPipelineStepNoteServerResponseModel response = await this.PipelineStepNoteService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IPipelineStepNoteService, IPipelineStepNoteRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PipelineStepNote>(null)); var service = new PipelineStepNoteService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PipelineStepNoteModelValidatorMock.Object, mock.DALMapperMockFactory.DALPipelineStepNoteMapperMock); ApiPipelineStepNoteServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { PipelineStepNoteControllerMockFacade mock = new PipelineStepNoteControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPipelineStepNoteServerResponseModel> >(null as ApiPipelineStepNoteServerResponseModel); var mockRecord = new ApiPipelineStepNoteServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPipelineStepNoteServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPipelineStepNoteServerResponseModel> >(mockResponse.Object)); PipelineStepNoteController controller = new PipelineStepNoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiPipelineStepNoteServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPipelineStepNoteServerRequestModel>())); }
public async void All_Exists() { PipelineStepNoteControllerMockFacade mock = new PipelineStepNoteControllerMockFacade(); var record = new ApiPipelineStepNoteServerResponseModel(); var records = new List <ApiPipelineStepNoteServerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); PipelineStepNoteController controller = new PipelineStepNoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiPipelineStepNoteServerResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
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)); } } }