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 ApiOrganizationRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiOrganizationResponseModel> createResult = await client.OrganizationCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiOrganizationResponseModel getResponse = await client.OrganizationGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.OrganizationDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiOrganizationResponseModel verifyResponse = await client.OrganizationGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiOrganizationResponseModel MapBOToModel( BOOrganization boOrganization) { var model = new ApiOrganizationResponseModel(); model.SetProperties(boOrganization.Id, boOrganization.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiOrganizationModelMapper(); var model = new ApiOrganizationResponseModel(); model.SetProperties(1, "A"); ApiOrganizationRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLOrganizationMapper(); BOOrganization bo = new BOOrganization(); bo.SetProperties(1, "A"); ApiOrganizationResponseModel response = mapper.MapBOToModel(bo); response.Id.Should().Be(1); response.Name.Should().Be("A"); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiOrganizationResponseModel response = await client.OrganizationGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiOrganizationResponseModel response = await this.OrganizationService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByName(string name) { ApiOrganizationResponseModel response = await this.OrganizationService.ByName(name); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IOrganizationRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Organization>(null)); var service = new OrganizationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLOrganizationMapperMock, mock.DALMapperMockFactory.DALOrganizationMapperMock, mock.BOLMapperMockFactory.BOLTeamMapperMock, mock.DALMapperMockFactory.DALTeamMapperMock); ApiOrganizationResponseModel 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()); ApiOrganizationResponseModel model = await client.OrganizationGetAsync(1); ApiOrganizationModelMapper mapper = new ApiOrganizationModelMapper(); UpdateResponse <ApiOrganizationResponseModel> updateResponse = await client.OrganizationUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void ByName_Exists() { var mock = new ServiceMockFacade <IOrganizationRepository>(); var record = new Organization(); mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record)); var service = new OrganizationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.OrganizationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLOrganizationMapperMock, mock.DALMapperMockFactory.DALOrganizationMapperMock, mock.BOLMapperMockFactory.BOLTeamMapperMock, mock.DALMapperMockFactory.DALTeamMapperMock); ApiOrganizationResponseModel response = await service.ByName(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>())); }
public async void Create_Errors() { OrganizationControllerMockFacade mock = new OrganizationControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiOrganizationResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiOrganizationResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiOrganizationRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiOrganizationResponseModel> >(mockResponse.Object)); OrganizationController controller = new OrganizationController(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 ApiOrganizationRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiOrganizationRequestModel>())); }
public async void All_Exists() { OrganizationControllerMockFacade mock = new OrganizationControllerMockFacade(); var record = new ApiOrganizationResponseModel(); var records = new List <ApiOrganizationResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); OrganizationController controller = new OrganizationController(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 <ApiOrganizationResponseModel>; 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 <ApiOrganizationRequestModel> patch) { ApiOrganizationResponseModel record = await this.OrganizationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiOrganizationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiOrganizationResponseModel> result = await this.OrganizationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiOrganizationResponseModel response = await this.Client.OrganizationGetAsync(1); response.Should().NotBeNull(); }