public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiTagSetRequestModel model) { this.DataVersionRules(); this.JSONRules(); this.NameRules(); this.SortOrderRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiTagSetResponseModel> CreateRecord() { var model = new ApiTagSetRequestModel(); model.SetProperties(BitConverter.GetBytes(2), "B", "B", 2); CreateResponse <ApiTagSetResponseModel> result = await this.Client.TagSetCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiTagSetRequestModel model) { CreateResponse <ApiTagSetResponseModel> result = await this.TagSetService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TagSets/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLTagSetMapper(); ApiTagSetRequestModel model = new ApiTagSetRequestModel(); model.SetProperties(BitConverter.GetBytes(1), "A", "A", 1); BOTagSet response = mapper.MapModelToBO("A", model); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.SortOrder.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiTagSetModelMapper(); var model = new ApiTagSetResponseModel(); model.SetProperties("A", BitConverter.GetBytes(1), "A", "A", 1); ApiTagSetRequestModel response = mapper.MapResponseToRequest(model); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.SortOrder.Should().Be(1); }
private async Task <ApiTagSetRequestModel> PatchModel(string id, JsonPatchDocument <ApiTagSetRequestModel> patch) { var record = await this.TagSetService.Get(id); if (record == null) { return(null); } else { ApiTagSetRequestModel request = this.TagSetModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiTagSetResponseModel> > Create( ApiTagSetRequestModel model) { CreateResponse <ApiTagSetResponseModel> response = new CreateResponse <ApiTagSetResponseModel>(await this.tagSetModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolTagSetMapper.MapModelToBO(default(string), model); var record = await this.tagSetRepository.Create(this.dalTagSetMapper.MapBOToEF(bo)); response.SetRecord(this.bolTagSetMapper.MapBOToModel(this.dalTagSetMapper.MapEFToBO(record))); } return(response); }
public virtual BOTagSet MapModelToBO( string id, ApiTagSetRequestModel model ) { BOTagSet boTagSet = new BOTagSet(); boTagSet.SetProperties( id, model.DataVersion, model.JSON, model.Name, model.SortOrder); return(boTagSet); }
public void CreatePatch() { var mapper = new ApiTagSetModelMapper(); var model = new ApiTagSetRequestModel(); model.SetProperties(BitConverter.GetBytes(1), "A", "A", 1); JsonPatchDocument <ApiTagSetRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTagSetRequestModel(); patch.ApplyTo(response); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.SortOrder.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <ITagSetRepository>(); var model = new ApiTagSetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TagSet>())).Returns(Task.FromResult(new TagSet())); var service = new TagSetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TagSetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTagSetMapperMock, mock.DALMapperMockFactory.DALTagSetMapperMock); CreateResponse <ApiTagSetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TagSetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTagSetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TagSet>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITagSetRepository>(); var model = new ApiTagSetRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new TagSetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TagSetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTagSetMapperMock, mock.DALMapperMockFactory.DALTagSetMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.TagSetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiTagSetResponseModel> > Update( string id, ApiTagSetRequestModel model) { var validationResult = await this.tagSetModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolTagSetMapper.MapModelToBO(id, model); await this.tagSetRepository.Update(this.dalTagSetMapper.MapBOToEF(bo)); var record = await this.tagSetRepository.Get(id); return(new UpdateResponse <ApiTagSetResponseModel>(this.bolTagSetMapper.MapBOToModel(this.dalTagSetMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTagSetResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiTagSetRequestModel model) { ApiTagSetRequestModel request = await this.PatchModel(id, this.TagSetModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTagSetResponseModel> result = await this.TagSetService.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 <ApiTagSetRequestModel> patch) { ApiTagSetResponseModel record = await this.TagSetService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTagSetRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTagSetResponseModel> result = await this.TagSetService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }