public async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var createModel = new ApiCompositePrimaryKeyRequestModel(); createModel.SetProperties(2); CreateResponse <ApiCompositePrimaryKeyResponseModel> createResult = await client.CompositePrimaryKeyCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiCompositePrimaryKeyResponseModel getResponse = await client.CompositePrimaryKeyGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.CompositePrimaryKeyDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiCompositePrimaryKeyResponseModel verifyResponse = await client.CompositePrimaryKeyGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiCompositePrimaryKeyResponseModel MapBOToModel( BOCompositePrimaryKey boCompositePrimaryKey) { var model = new ApiCompositePrimaryKeyResponseModel(); model.SetProperties(boCompositePrimaryKey.Id, boCompositePrimaryKey.Id2); return(model); }
public void MapResponseToRequest() { var mapper = new ApiCompositePrimaryKeyModelMapper(); var model = new ApiCompositePrimaryKeyResponseModel(); model.SetProperties(1, 1); ApiCompositePrimaryKeyRequestModel response = mapper.MapResponseToRequest(model); response.Id2.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLCompositePrimaryKeyMapper(); BOCompositePrimaryKey bo = new BOCompositePrimaryKey(); bo.SetProperties(1, 1); ApiCompositePrimaryKeyResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.Id2.Should().Be(1); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiCompositePrimaryKeyResponseModel response = await client.CompositePrimaryKeyGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiCompositePrimaryKeyResponseModel response = await this.CompositePrimaryKeyService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <ICompositePrimaryKeyRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <CompositePrimaryKey>(null)); var service = new CompositePrimaryKeyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CompositePrimaryKeyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCompositePrimaryKeyMapperMock, mock.DALMapperMockFactory.DALCompositePrimaryKeyMapperMock); ApiCompositePrimaryKeyResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiCompositePrimaryKeyResponseModel model = await client.CompositePrimaryKeyGetAsync(1); ApiCompositePrimaryKeyModelMapper mapper = new ApiCompositePrimaryKeyModelMapper(); UpdateResponse <ApiCompositePrimaryKeyResponseModel> updateResponse = await client.CompositePrimaryKeyUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { CompositePrimaryKeyControllerMockFacade mock = new CompositePrimaryKeyControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiCompositePrimaryKeyResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiCompositePrimaryKeyResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCompositePrimaryKeyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCompositePrimaryKeyResponseModel> >(mockResponse.Object)); CompositePrimaryKeyController controller = new CompositePrimaryKeyController(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 ApiCompositePrimaryKeyRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCompositePrimaryKeyRequestModel>())); }
public async void All_Exists() { CompositePrimaryKeyControllerMockFacade mock = new CompositePrimaryKeyControllerMockFacade(); var record = new ApiCompositePrimaryKeyResponseModel(); var records = new List <ApiCompositePrimaryKeyResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); CompositePrimaryKeyController controller = new CompositePrimaryKeyController(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); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCompositePrimaryKeyResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiCompositePrimaryKeyRequestModel> patch) { ApiCompositePrimaryKeyResponseModel record = await this.CompositePrimaryKeyService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCompositePrimaryKeyRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCompositePrimaryKeyResponseModel> result = await this.CompositePrimaryKeyService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }