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; IColumnSameAsFKTableService service = testServer.Host.Services.GetService(typeof(IColumnSameAsFKTableService)) as IColumnSameAsFKTableService; var model = new ApiColumnSameAsFKTableServerRequestModel(); model.SetProperties(1, 1); CreateResponse <ApiColumnSameAsFKTableServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.ColumnSameAsFKTableDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiColumnSameAsFKTableServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
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 ApiColumnSameAsFKTableServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IColumnSameAsFKTableService service = testServer.Host.Services.GetService(typeof(IColumnSameAsFKTableService)) as IColumnSameAsFKTableService; ApiColumnSameAsFKTableServerResponseModel model = await service.Get(1); ApiColumnSameAsFKTableClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(1, 1); UpdateResponse <ApiColumnSameAsFKTableClientResponseModel> updateResponse = await client.ColumnSameAsFKTableUpdateAsync(model.Id, request); context.Entry(context.Set <ColumnSameAsFKTable>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <ColumnSameAsFKTable>().ToList()[0].Person.Should().Be(1); context.Set <ColumnSameAsFKTable>().ToList()[0].PersonId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Person.Should().Be(1); updateResponse.Record.PersonId.Should().Be(1); }
public void MapServerResponseToRequest() { var mapper = new ApiColumnSameAsFKTableServerModelMapper(); var model = new ApiColumnSameAsFKTableServerResponseModel(); model.SetProperties(1, 1, 1); ApiColumnSameAsFKTableServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Person.Should().Be(1); response.PersonId.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiColumnSameAsFKTableServerResponseModel response = await this.ColumnSameAsFKTableService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IColumnSameAsFKTableService, IColumnSameAsFKTableRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ColumnSameAsFKTable>(null)); var service = new ColumnSameAsFKTableService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ColumnSameAsFKTableModelValidatorMock.Object, mock.DALMapperMockFactory.DALColumnSameAsFKTableMapperMock); ApiColumnSameAsFKTableServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { ColumnSameAsFKTableControllerMockFacade mock = new ColumnSameAsFKTableControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiColumnSameAsFKTableServerResponseModel> >(null as ApiColumnSameAsFKTableServerResponseModel); var mockRecord = new ApiColumnSameAsFKTableServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiColumnSameAsFKTableServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiColumnSameAsFKTableServerResponseModel> >(mockResponse.Object)); ColumnSameAsFKTableController controller = new ColumnSameAsFKTableController(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 ApiColumnSameAsFKTableServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiColumnSameAsFKTableServerRequestModel>())); }
public async void All_Exists() { ColumnSameAsFKTableControllerMockFacade mock = new ColumnSameAsFKTableControllerMockFacade(); var record = new ApiColumnSameAsFKTableServerResponseModel(); var records = new List <ApiColumnSameAsFKTableServerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); ColumnSameAsFKTableController controller = new ColumnSameAsFKTableController(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 <ApiColumnSameAsFKTableServerResponseModel>; 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 <ApiColumnSameAsFKTableServerRequestModel> patch) { ApiColumnSameAsFKTableServerResponseModel record = await this.ColumnSameAsFKTableService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiColumnSameAsFKTableServerRequestModel model = await this.PatchModel(id, patch) as ApiColumnSameAsFKTableServerRequestModel; UpdateResponse <ApiColumnSameAsFKTableServerResponseModel> result = await this.ColumnSameAsFKTableService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }