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 ApiChainRequestModel(); createModel.SetProperties(1, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", 1); CreateResponse <ApiChainResponseModel> createResult = await client.ChainCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiChainResponseModel getResponse = await client.ChainGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.ChainDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiChainResponseModel verifyResponse = await client.ChainGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiChainResponseModel MapBOToModel( BOChain boChain) { var model = new ApiChainResponseModel(); model.SetProperties(boChain.Id, boChain.ChainStatusId, boChain.ExternalId, boChain.Name, boChain.TeamId); return(model); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiChainResponseModel response = await client.ChainGetAsync(1); response.Should().NotBeNull(); }
public void MapResponseToRequest() { var mapper = new ApiChainModelMapper(); var model = new ApiChainResponseModel(); model.SetProperties(1, 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", 1); ApiChainRequestModel response = mapper.MapResponseToRequest(model); response.ChainStatusId.Should().Be(1); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); response.TeamId.Should().Be(1); }
public async virtual Task <IActionResult> Get(int id) { ApiChainResponseModel response = await this.ChainService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByExternalId(Guid externalId) { ApiChainResponseModel response = await this.ChainService.ByExternalId(externalId); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapBOToModel() { var mapper = new BOLChainMapper(); BOChain bo = new BOChain(); bo.SetProperties(1, 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", 1); ApiChainResponseModel response = mapper.MapBOToModel(bo); response.ChainStatusId.Should().Be(1); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Id.Should().Be(1); response.Name.Should().Be("A"); response.TeamId.Should().Be(1); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiChainResponseModel model = await client.ChainGetAsync(1); ApiChainModelMapper mapper = new ApiChainModelMapper(); UpdateResponse <ApiChainResponseModel> updateResponse = await client.ChainUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IChainRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Chain>(null)); var service = new ChainService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ChainModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLChainMapperMock, mock.DALMapperMockFactory.DALChainMapperMock, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock); ApiChainResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByExternalId_Not_Exists() { var mock = new ServiceMockFacade <IChainRepository>(); mock.RepositoryMock.Setup(x => x.ByExternalId(It.IsAny <Guid>())).Returns(Task.FromResult <Chain>(null)); var service = new ChainService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ChainModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLChainMapperMock, mock.DALMapperMockFactory.DALChainMapperMock, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock); ApiChainResponseModel response = await service.ByExternalId(default(Guid)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByExternalId(It.IsAny <Guid>())); }
public async void Create_Errors() { ChainControllerMockFacade mock = new ChainControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiChainResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiChainResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiChainRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiChainResponseModel> >(mockResponse.Object)); ChainController controller = new ChainController(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 ApiChainRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiChainRequestModel>())); }
public async void All_Exists() { ChainControllerMockFacade mock = new ChainControllerMockFacade(); var record = new ApiChainResponseModel(); var records = new List <ApiChainResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ChainController controller = new ChainController(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 <ApiChainResponseModel>; 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 <ApiChainRequestModel> patch) { ApiChainResponseModel record = await this.ChainService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiChainRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiChainResponseModel> result = await this.ChainService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiChainResponseModel response = await this.Client.ChainGetAsync(1); response.Should().NotBeNull(); }