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 ApiPostTypeRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiPostTypeResponseModel> createResult = await client.PostTypeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiPostTypeResponseModel getResponse = await client.PostTypeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.PostTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPostTypeResponseModel verifyResponse = await client.PostTypeGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiPostTypeResponseModel> CreateRecord(ApiClient client) { var model = new ApiPostTypeRequestModel(); model.SetProperties("B"); CreateResponse <ApiPostTypeResponseModel> result = await client.PostTypeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLPostTypeMapper(); ApiPostTypeRequestModel model = new ApiPostTypeRequestModel(); model.SetProperties("A"); BOPostType response = mapper.MapModelToBO(1, model); response.Type.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiPostTypeModelMapper(); var model = new ApiPostTypeResponseModel(); model.SetProperties(1, "A"); ApiPostTypeRequestModel response = mapper.MapResponseToRequest(model); response.Type.Should().Be("A"); }
public virtual BOPostType MapModelToBO( int id, ApiPostTypeRequestModel model ) { BOPostType boPostType = new BOPostType(); boPostType.SetProperties( id, model.Type); return(boPostType); }
public virtual async Task<IActionResult> Create([FromBody] ApiPostTypeRequestModel model) { CreateResponse<ApiPostTypeResponseModel> result = await this.PostTypeService.Create(model); if (result.Success) { return this.Created($"{this.Settings.ExternalBaseUrl}/api/PostTypes/{result.Record.Id}", result); } else { return this.StatusCode(StatusCodes.Status422UnprocessableEntity, result); } }
public void CreatePatch() { var mapper = new ApiPostTypeModelMapper(); var model = new ApiPostTypeRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiPostTypeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPostTypeRequestModel(); patch.ApplyTo(response); response.Type.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiPostTypeResponseModel> > Create( ApiPostTypeRequestModel model) { CreateResponse <ApiPostTypeResponseModel> response = new CreateResponse <ApiPostTypeResponseModel>(await this.PostTypeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolPostTypeMapper.MapModelToBO(default(int), model); var record = await this.PostTypeRepository.Create(this.DalPostTypeMapper.MapBOToEF(bo)); response.SetRecord(this.BolPostTypeMapper.MapBOToModel(this.DalPostTypeMapper.MapEFToBO(record))); } return(response); }
private async Task<ApiPostTypeRequestModel> PatchModel(int id, JsonPatchDocument<ApiPostTypeRequestModel> patch) { var record = await this.PostTypeService.Get(id); if (record == null) { return null; } else { ApiPostTypeRequestModel request = this.PostTypeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return request; } }
public async void Delete() { var mock = new ServiceMockFacade <IPostTypeRepository>(); var model = new ApiPostTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PostTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostTypeMapperMock, mock.DALMapperMockFactory.DALPostTypeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PostTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Create() { var mock = new ServiceMockFacade <IPostTypeRepository>(); var model = new ApiPostTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostType>())).Returns(Task.FromResult(new PostType())); var service = new PostTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostTypeMapperMock, mock.DALMapperMockFactory.DALPostTypeMapperMock); CreateResponse <ApiPostTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PostTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostType>())); }
public virtual async Task <UpdateResponse <ApiPostTypeResponseModel> > Update( int id, ApiPostTypeRequestModel model) { var validationResult = await this.PostTypeModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolPostTypeMapper.MapModelToBO(id, model); await this.PostTypeRepository.Update(this.DalPostTypeMapper.MapBOToEF(bo)); var record = await this.PostTypeRepository.Get(id); return(new UpdateResponse <ApiPostTypeResponseModel>(this.BolPostTypeMapper.MapBOToModel(this.DalPostTypeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPostTypeResponseModel>(validationResult)); } }
public virtual async Task<IActionResult> Update(int id, [FromBody] ApiPostTypeRequestModel model) { ApiPostTypeRequestModel request = await this.PatchModel(id, this.PostTypeModelMapper.CreatePatch(model)); if (request == null) { return this.StatusCode(StatusCodes.Status404NotFound); } else { UpdateResponse<ApiPostTypeResponseModel> result = await this.PostTypeService.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<ApiPostTypeRequestModel> patch) { ApiPostTypeResponseModel record = await this.PostTypeService.Get(id); if (record == null) { return this.StatusCode(StatusCodes.Status404NotFound); } else { ApiPostTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse<ApiPostTypeResponseModel> result = await this.PostTypeService.Update(id, model); if (result.Success) { return this.Ok(result); } else { return this.StatusCode(StatusCodes.Status422UnprocessableEntity, result); } } }
public virtual async Task <UpdateResponse <ApiPostTypeResponseModel> > PostTypeUpdateAsync(int id, ApiPostTypeRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PostTypes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiPostTypeResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPostTypeRequestModel model) { this.TypeRules(); return(await this.ValidateAsync(model, id)); }
public async Task <ValidationResult> ValidateCreateAsync(ApiPostTypeRequestModel model) { this.TypeRules(); return(await this.ValidateAsync(model)); }