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 ApiSelfReferenceRequestModel(); createModel.SetProperties(2, 2); CreateResponse <ApiSelfReferenceResponseModel> createResult = await client.SelfReferenceCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiSelfReferenceResponseModel getResponse = await client.SelfReferenceGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.SelfReferenceDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiSelfReferenceResponseModel verifyResponse = await client.SelfReferenceGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiSelfReferenceResponseModel MapBOToModel( BOSelfReference boSelfReference) { var model = new ApiSelfReferenceResponseModel(); model.SetProperties(boSelfReference.Id, boSelfReference.SelfReferenceId, boSelfReference.SelfReferenceId2); return(model); }
public void MapResponseToRequest() { var mapper = new ApiSelfReferenceModelMapper(); var model = new ApiSelfReferenceResponseModel(); model.SetProperties(1, 1, 1); ApiSelfReferenceRequestModel response = mapper.MapResponseToRequest(model); response.SelfReferenceId.Should().Be(1); response.SelfReferenceId2.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLSelfReferenceMapper(); BOSelfReference bo = new BOSelfReference(); bo.SetProperties(1, 1, 1); ApiSelfReferenceResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.SelfReferenceId.Should().Be(1); response.SelfReferenceId2.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()); ApiSelfReferenceResponseModel response = await client.SelfReferenceGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiSelfReferenceResponseModel response = await this.SelfReferenceService.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 <ISelfReferenceRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <SelfReference>(null)); var service = new SelfReferenceService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SelfReferenceModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSelfReferenceMapperMock, mock.DALMapperMockFactory.DALSelfReferenceMapperMock); ApiSelfReferenceResponseModel 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()); ApiSelfReferenceResponseModel model = await client.SelfReferenceGetAsync(1); ApiSelfReferenceModelMapper mapper = new ApiSelfReferenceModelMapper(); UpdateResponse <ApiSelfReferenceResponseModel> updateResponse = await client.SelfReferenceUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { SelfReferenceControllerMockFacade mock = new SelfReferenceControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiSelfReferenceResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiSelfReferenceResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSelfReferenceRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSelfReferenceResponseModel> >(mockResponse.Object)); SelfReferenceController controller = new SelfReferenceController(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 ApiSelfReferenceRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSelfReferenceRequestModel>())); }
public async void All_Exists() { SelfReferenceControllerMockFacade mock = new SelfReferenceControllerMockFacade(); var record = new ApiSelfReferenceResponseModel(); var records = new List <ApiSelfReferenceResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); SelfReferenceController controller = new SelfReferenceController(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 <ApiSelfReferenceResponseModel>; 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 <ApiSelfReferenceRequestModel> patch) { ApiSelfReferenceResponseModel record = await this.SelfReferenceService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSelfReferenceRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSelfReferenceResponseModel> result = await this.SelfReferenceService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiSelfReferenceResponseModel response = await this.Client.SelfReferenceGetAsync(1); response.Should().NotBeNull(); }