public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiCommunityActionTemplateRequestModel model) { this.ExternalIdRules(); this.JSONRules(); this.NameRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiCommunityActionTemplateResponseModel> CreateRecord() { var model = new ApiCommunityActionTemplateRequestModel(); model.SetProperties(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B", "B"); CreateResponse <ApiCommunityActionTemplateResponseModel> result = await this.Client.CommunityActionTemplateCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLCommunityActionTemplateMapper(); ApiCommunityActionTemplateRequestModel model = new ApiCommunityActionTemplateRequestModel(); model.SetProperties(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A"); BOCommunityActionTemplate response = mapper.MapModelToBO("A", model); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiCommunityActionTemplateRequestModel model) { CreateResponse <ApiCommunityActionTemplateResponseModel> result = await this.CommunityActionTemplateService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/CommunityActionTemplates/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOCommunityActionTemplate MapModelToBO( string id, ApiCommunityActionTemplateRequestModel model ) { BOCommunityActionTemplate boCommunityActionTemplate = new BOCommunityActionTemplate(); boCommunityActionTemplate.SetProperties( id, model.ExternalId, model.JSON, model.Name); return(boCommunityActionTemplate); }
public virtual async Task <CreateResponse <ApiCommunityActionTemplateResponseModel> > Create( ApiCommunityActionTemplateRequestModel model) { CreateResponse <ApiCommunityActionTemplateResponseModel> response = new CreateResponse <ApiCommunityActionTemplateResponseModel>(await this.communityActionTemplateModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolCommunityActionTemplateMapper.MapModelToBO(default(string), model); var record = await this.communityActionTemplateRepository.Create(this.dalCommunityActionTemplateMapper.MapBOToEF(bo)); response.SetRecord(this.bolCommunityActionTemplateMapper.MapBOToModel(this.dalCommunityActionTemplateMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiCommunityActionTemplateModelMapper(); var model = new ApiCommunityActionTemplateRequestModel(); model.SetProperties(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A"); JsonPatchDocument <ApiCommunityActionTemplateRequestModel> patch = mapper.CreatePatch(model); var response = new ApiCommunityActionTemplateRequestModel(); patch.ApplyTo(response); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); }
private async Task <ApiCommunityActionTemplateRequestModel> PatchModel(string id, JsonPatchDocument <ApiCommunityActionTemplateRequestModel> patch) { var record = await this.CommunityActionTemplateService.Get(id); if (record == null) { return(null); } else { ApiCommunityActionTemplateRequestModel request = this.CommunityActionTemplateModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <ICommunityActionTemplateRepository>(); var model = new ApiCommunityActionTemplateRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <CommunityActionTemplate>())).Returns(Task.FromResult(new CommunityActionTemplate())); var service = new CommunityActionTemplateService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommunityActionTemplateModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommunityActionTemplateMapperMock, mock.DALMapperMockFactory.DALCommunityActionTemplateMapperMock); CreateResponse <ApiCommunityActionTemplateResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.CommunityActionTemplateModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCommunityActionTemplateRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <CommunityActionTemplate>())); }
public async void Delete() { var mock = new ServiceMockFacade <ICommunityActionTemplateRepository>(); var model = new ApiCommunityActionTemplateRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new CommunityActionTemplateService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CommunityActionTemplateModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLCommunityActionTemplateMapperMock, mock.DALMapperMockFactory.DALCommunityActionTemplateMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.CommunityActionTemplateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiCommunityActionTemplateResponseModel> > Update( string id, ApiCommunityActionTemplateRequestModel model) { var validationResult = await this.communityActionTemplateModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolCommunityActionTemplateMapper.MapModelToBO(id, model); await this.communityActionTemplateRepository.Update(this.dalCommunityActionTemplateMapper.MapBOToEF(bo)); var record = await this.communityActionTemplateRepository.Get(id); return(new UpdateResponse <ApiCommunityActionTemplateResponseModel>(this.bolCommunityActionTemplateMapper.MapBOToModel(this.dalCommunityActionTemplateMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiCommunityActionTemplateResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiCommunityActionTemplateRequestModel model) { ApiCommunityActionTemplateRequestModel request = await this.PatchModel(id, this.CommunityActionTemplateModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiCommunityActionTemplateResponseModel> result = await this.CommunityActionTemplateService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiCommunityActionTemplateRequestModel> patch) { ApiCommunityActionTemplateResponseModel record = await this.CommunityActionTemplateService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiCommunityActionTemplateRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiCommunityActionTemplateResponseModel> result = await this.CommunityActionTemplateService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }