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 ApiLinkTypeRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiLinkTypeResponseModel> createResult = await client.LinkTypeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiLinkTypeResponseModel getResponse = await client.LinkTypeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.LinkTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiLinkTypeResponseModel verifyResponse = await client.LinkTypeGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiLinkTypeResponseModel> CreateRecord(ApiClient client) { var model = new ApiLinkTypeRequestModel(); model.SetProperties("B"); CreateResponse <ApiLinkTypeResponseModel> result = await client.LinkTypeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiLinkTypeModelMapper(); var model = new ApiLinkTypeResponseModel(); model.SetProperties(1, "A"); ApiLinkTypeRequestModel response = mapper.MapResponseToRequest(model); response.Type.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLLinkTypeMapper(); ApiLinkTypeRequestModel model = new ApiLinkTypeRequestModel(); model.SetProperties("A"); BOLinkType response = mapper.MapModelToBO(1, model); response.Type.Should().Be("A"); }
public virtual BOLinkType MapModelToBO( int id, ApiLinkTypeRequestModel model ) { BOLinkType boLinkType = new BOLinkType(); boLinkType.SetProperties( id, model.Type); return(boLinkType); }
public virtual async Task <IActionResult> Create([FromBody] ApiLinkTypeRequestModel model) { CreateResponse <ApiLinkTypeResponseModel> result = await this.LinkTypeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/LinkTypes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiLinkTypeModelMapper(); var model = new ApiLinkTypeRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiLinkTypeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiLinkTypeRequestModel(); patch.ApplyTo(response); response.Type.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiLinkTypeResponseModel> > Create( ApiLinkTypeRequestModel model) { CreateResponse <ApiLinkTypeResponseModel> response = new CreateResponse <ApiLinkTypeResponseModel>(await this.LinkTypeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolLinkTypeMapper.MapModelToBO(default(int), model); var record = await this.LinkTypeRepository.Create(this.DalLinkTypeMapper.MapBOToEF(bo)); response.SetRecord(this.BolLinkTypeMapper.MapBOToModel(this.DalLinkTypeMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiLinkTypeRequestModel> PatchModel(int id, JsonPatchDocument <ApiLinkTypeRequestModel> patch) { var record = await this.LinkTypeService.Get(id); if (record == null) { return(null); } else { ApiLinkTypeRequestModel request = this.LinkTypeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <ILinkTypeRepository>(); var model = new ApiLinkTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <LinkType>())).Returns(Task.FromResult(new LinkType())); var service = new LinkTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLinkTypeMapperMock, mock.DALMapperMockFactory.DALLinkTypeMapperMock); CreateResponse <ApiLinkTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <LinkType>())); }
public async void Delete() { var mock = new ServiceMockFacade <ILinkTypeRepository>(); var model = new ApiLinkTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new LinkTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLinkTypeMapperMock, mock.DALMapperMockFactory.DALLinkTypeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiLinkTypeResponseModel> > Update( int id, ApiLinkTypeRequestModel model) { var validationResult = await this.LinkTypeModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolLinkTypeMapper.MapModelToBO(id, model); await this.LinkTypeRepository.Update(this.DalLinkTypeMapper.MapBOToEF(bo)); var record = await this.LinkTypeRepository.Get(id); return(new UpdateResponse <ApiLinkTypeResponseModel>(this.BolLinkTypeMapper.MapBOToModel(this.DalLinkTypeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiLinkTypeResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiLinkTypeRequestModel model) { ApiLinkTypeRequestModel request = await this.PatchModel(id, this.LinkTypeModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiLinkTypeResponseModel> result = await this.LinkTypeService.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 <ApiLinkTypeRequestModel> patch) { ApiLinkTypeResponseModel record = await this.LinkTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiLinkTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiLinkTypeResponseModel> result = await this.LinkTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiLinkTypeResponseModel> > LinkTypeUpdateAsync(int id, ApiLinkTypeRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/LinkTypes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiLinkTypeResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateCreateAsync(ApiLinkTypeRequestModel model) { this.TypeRules(); return(await this.ValidateAsync(model)); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiLinkTypeRequestModel model) { this.TypeRules(); return(await this.ValidateAsync(model, id)); }