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 async Task <ValidationResult> ValidateUpdateAsync(int id, ApiChainRequestModel model) { this.ChainStatusIdRules(); this.ExternalIdRules(); this.NameRules(); this.TeamIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiChainResponseModel> CreateRecord(ApiClient client) { var model = new ApiChainRequestModel(); model.SetProperties(1, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", 1); CreateResponse <ApiChainResponseModel> result = await client.ChainCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLChainMapper(); ApiChainRequestModel model = new ApiChainRequestModel(); model.SetProperties(1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", 1); BOChain response = mapper.MapModelToBO(1, 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 virtual async Task <IActionResult> Create([FromBody] ApiChainRequestModel model) { CreateResponse <ApiChainResponseModel> result = await this.ChainService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Chains/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOChain MapModelToBO( int id, ApiChainRequestModel model ) { BOChain boChain = new BOChain(); boChain.SetProperties( id, model.ChainStatusId, model.ExternalId, model.Name, model.TeamId); return(boChain); }
public virtual async Task <CreateResponse <ApiChainResponseModel> > Create( ApiChainRequestModel model) { CreateResponse <ApiChainResponseModel> response = new CreateResponse <ApiChainResponseModel>(await this.chainModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolChainMapper.MapModelToBO(default(int), model); var record = await this.chainRepository.Create(this.dalChainMapper.MapBOToEF(bo)); response.SetRecord(this.bolChainMapper.MapBOToModel(this.dalChainMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiChainRequestModel> PatchModel(int id, JsonPatchDocument <ApiChainRequestModel> patch) { var record = await this.ChainService.Get(id); if (record == null) { return(null); } else { ApiChainRequestModel request = this.ChainModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiChainModelMapper(); var model = new ApiChainRequestModel(); model.SetProperties(1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", 1); JsonPatchDocument <ApiChainRequestModel> patch = mapper.CreatePatch(model); var response = new ApiChainRequestModel(); patch.ApplyTo(response); 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 virtual async Task <UpdateResponse <ApiChainResponseModel> > Update( int id, ApiChainRequestModel model) { var validationResult = await this.chainModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolChainMapper.MapModelToBO(id, model); await this.chainRepository.Update(this.dalChainMapper.MapBOToEF(bo)); var record = await this.chainRepository.Get(id); return(new UpdateResponse <ApiChainResponseModel>(this.bolChainMapper.MapBOToModel(this.dalChainMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiChainResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <IChainRepository>(); var model = new ApiChainRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Chain>())).Returns(Task.FromResult(new Chain())); 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); CreateResponse <ApiChainResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ChainModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiChainRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Chain>())); }
public async void Delete() { var mock = new ServiceMockFacade <IChainRepository>(); var model = new ApiChainRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); 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); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ChainModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiChainRequestModel model) { ApiChainRequestModel request = await this.PatchModel(id, this.ChainModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiChainResponseModel> result = await this.ChainService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
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 virtual async Task <UpdateResponse <ApiChainResponseModel> > ChainUpdateAsync(int id, ApiChainRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Chains/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiChainResponseModel> >(httpResponse.Content.ContentToString())); }