public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPostLinksRequestModel model) { this.CreationDateRules(); this.LinkTypeIdRules(); this.PostIdRules(); this.RelatedPostIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiPostLinksResponseModel> CreateRecord() { var model = new ApiPostLinksRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiPostLinksResponseModel> result = await this.Client.PostLinksCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLPostLinksMapper(); ApiPostLinksRequestModel model = new ApiPostLinksRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); BOPostLinks response = mapper.MapModelToBO(1, model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiPostLinksRequestModel model) { CreateResponse <ApiPostLinksResponseModel> result = await this.PostLinksService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PostLinks/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapResponseToRequest() { var mapper = new ApiPostLinksModelMapper(); var model = new ApiPostLinksResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinksRequestModel response = mapper.MapResponseToRequest(model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public virtual BOPostLinks MapModelToBO( int id, ApiPostLinksRequestModel model ) { BOPostLinks boPostLinks = new BOPostLinks(); boPostLinks.SetProperties( id, model.CreationDate, model.LinkTypeId, model.PostId, model.RelatedPostId); return(boPostLinks); }
public virtual async Task <CreateResponse <ApiPostLinksResponseModel> > Create( ApiPostLinksRequestModel model) { CreateResponse <ApiPostLinksResponseModel> response = new CreateResponse <ApiPostLinksResponseModel>(await this.postLinksModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolPostLinksMapper.MapModelToBO(default(int), model); var record = await this.postLinksRepository.Create(this.dalPostLinksMapper.MapBOToEF(bo)); response.SetRecord(this.bolPostLinksMapper.MapBOToModel(this.dalPostLinksMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiPostLinksRequestModel> PatchModel(int id, JsonPatchDocument <ApiPostLinksRequestModel> patch) { var record = await this.PostLinksService.Get(id); if (record == null) { return(null); } else { ApiPostLinksRequestModel request = this.PostLinksModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiPostLinksModelMapper(); var model = new ApiPostLinksRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); JsonPatchDocument <ApiPostLinksRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPostLinksRequestModel(); patch.ApplyTo(response); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
public async void Create() { var mock = new ServiceMockFacade <IPostLinksRepository>(); var model = new ApiPostLinksRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostLinks>())).Returns(Task.FromResult(new PostLinks())); var service = new PostLinksService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinksModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostLinksMapperMock, mock.DALMapperMockFactory.DALPostLinksMapperMock); CreateResponse <ApiPostLinksResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PostLinksModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostLinksRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostLinks>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPostLinksRepository>(); var model = new ApiPostLinksRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PostLinksService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinksModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostLinksMapperMock, mock.DALMapperMockFactory.DALPostLinksMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PostLinksModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiPostLinksResponseModel> > Update( int id, ApiPostLinksRequestModel model) { var validationResult = await this.postLinksModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolPostLinksMapper.MapModelToBO(id, model); await this.postLinksRepository.Update(this.dalPostLinksMapper.MapBOToEF(bo)); var record = await this.postLinksRepository.Get(id); return(new UpdateResponse <ApiPostLinksResponseModel>(this.bolPostLinksMapper.MapBOToModel(this.dalPostLinksMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPostLinksResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPostLinksRequestModel model) { ApiPostLinksRequestModel request = await this.PatchModel(id, this.PostLinksModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPostLinksResponseModel> result = await this.PostLinksService.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 <ApiPostLinksRequestModel> patch) { ApiPostLinksResponseModel record = await this.PostLinksService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPostLinksRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPostLinksResponseModel> result = await this.PostLinksService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiPostLinksResponseModel> > PostLinksUpdateAsync(int id, ApiPostLinksRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PostLinks/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiPostLinksResponseModel> >(httpResponse.Content.ContentToString())); }