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 ApiPostLinkRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiPostLinkResponseModel> createResult = await client.PostLinkCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiPostLinkResponseModel getResponse = await client.PostLinkGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.PostLinkDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPostLinkResponseModel verifyResponse = await client.PostLinkGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPostLinkRequestModel model) { this.CreationDateRules(); this.LinkTypeIdRules(); this.PostIdRules(); this.RelatedPostIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiPostLinkResponseModel> CreateRecord(ApiClient client) { var model = new ApiPostLinkRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2); CreateResponse <ApiPostLinkResponseModel> result = await client.PostLinkCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLPostLinkMapper(); ApiPostLinkRequestModel model = new ApiPostLinkRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); BOPostLink 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 void MapResponseToRequest() { var mapper = new ApiPostLinkModelMapper(); var model = new ApiPostLinkResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinkRequestModel 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 async Task <IActionResult> Create([FromBody] ApiPostLinkRequestModel model) { CreateResponse <ApiPostLinkResponseModel> result = await this.PostLinkService.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 virtual async Task <CreateResponse <ApiPostLinkResponseModel> > Create( ApiPostLinkRequestModel model) { CreateResponse <ApiPostLinkResponseModel> response = new CreateResponse <ApiPostLinkResponseModel>(await this.PostLinkModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolPostLinkMapper.MapModelToBO(default(int), model); var record = await this.PostLinkRepository.Create(this.DalPostLinkMapper.MapBOToEF(bo)); response.SetRecord(this.BolPostLinkMapper.MapBOToModel(this.DalPostLinkMapper.MapEFToBO(record))); } return(response); }
public virtual BOPostLink MapModelToBO( int id, ApiPostLinkRequestModel model ) { BOPostLink boPostLink = new BOPostLink(); boPostLink.SetProperties( id, model.CreationDate, model.LinkTypeId, model.PostId, model.RelatedPostId); return(boPostLink); }
private async Task <ApiPostLinkRequestModel> PatchModel(int id, JsonPatchDocument <ApiPostLinkRequestModel> patch) { var record = await this.PostLinkService.Get(id); if (record == null) { return(null); } else { ApiPostLinkRequestModel request = this.PostLinkModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiPostLinkModelMapper(); var model = new ApiPostLinkRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); JsonPatchDocument <ApiPostLinkRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPostLinkRequestModel(); 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 <IPostLinkRepository>(); var model = new ApiPostLinkRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostLink>())).Returns(Task.FromResult(new PostLink())); var service = new PostLinkService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostLinkMapperMock, mock.DALMapperMockFactory.DALPostLinkMapperMock); CreateResponse <ApiPostLinkResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostLinkRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostLink>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPostLinkRepository>(); var model = new ApiPostLinkRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PostLinkService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostLinkMapperMock, mock.DALMapperMockFactory.DALPostLinkMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PostLinkModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiPostLinkResponseModel> > Update( int id, ApiPostLinkRequestModel model) { var validationResult = await this.PostLinkModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolPostLinkMapper.MapModelToBO(id, model); await this.PostLinkRepository.Update(this.DalPostLinkMapper.MapBOToEF(bo)); var record = await this.PostLinkRepository.Get(id); return(new UpdateResponse <ApiPostLinkResponseModel>(this.BolPostLinkMapper.MapBOToModel(this.DalPostLinkMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPostLinkResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPostLinkRequestModel model) { ApiPostLinkRequestModel request = await this.PatchModel(id, this.PostLinkModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPostLinkResponseModel> result = await this.PostLinkService.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 <ApiPostLinkRequestModel> patch) { ApiPostLinkResponseModel record = await this.PostLinkService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPostLinkRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPostLinkResponseModel> result = await this.PostLinkService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiPostLinkResponseModel> > PostLinkUpdateAsync(int id, ApiPostLinkRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PostLinks/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiPostLinkResponseModel> >(httpResponse.Content.ContentToString())); }