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 ApiTenantRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiTenantResponseModel> createResult = await client.TenantCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTenantResponseModel getResponse = await client.TenantGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TenantDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTenantResponseModel verifyResponse = await client.TenantGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiTenantRequestModel model) { this.DataVersionRules(); this.JSONRules(); this.NameRules(); this.ProjectIdsRules(); this.TenantTagsRules(); return(await this.ValidateAsync(model, id)); }
public void MapModelToBO() { var mapper = new BOLTenantMapper(); ApiTenantRequestModel model = new ApiTenantRequestModel(); model.SetProperties("A"); BOTenant response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiTenantModelMapper(); var model = new ApiTenantResponseModel(); model.SetProperties(1, "A"); ApiTenantRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
private async Task <ApiTenantResponseModel> CreateRecord(ApiClient client) { var model = new ApiTenantRequestModel(); model.SetProperties("B"); CreateResponse <ApiTenantResponseModel> result = await client.TenantCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
private async Task <ApiTenantResponseModel> CreateRecord() { var model = new ApiTenantRequestModel(); model.SetProperties(BitConverter.GetBytes(2), "B", "B", "B", "B"); CreateResponse <ApiTenantResponseModel> result = await this.Client.TenantCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual BOTenant MapModelToBO( int id, ApiTenantRequestModel model ) { BOTenant boTenant = new BOTenant(); boTenant.SetProperties( id, model.Name); return(boTenant); }
public virtual async Task <IActionResult> Create([FromBody] ApiTenantRequestModel model) { CreateResponse <ApiTenantResponseModel> result = await this.TenantService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Tenants/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiTenantModelMapper(); var model = new ApiTenantRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiTenantRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTenantRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiTenantModelMapper(); var model = new ApiTenantResponseModel(); model.SetProperties("A", BitConverter.GetBytes(1), "A", "A", "A", "A"); ApiTenantRequestModel response = mapper.MapResponseToRequest(model); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.ProjectIds.Should().Be("A"); response.TenantTags.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLTenantMapper(); ApiTenantRequestModel model = new ApiTenantRequestModel(); model.SetProperties(BitConverter.GetBytes(1), "A", "A", "A", "A"); BOTenant response = mapper.MapModelToBO("A", model); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.ProjectIds.Should().Be("A"); response.TenantTags.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiTenantResponseModel> > Create( ApiTenantRequestModel model) { CreateResponse <ApiTenantResponseModel> response = new CreateResponse <ApiTenantResponseModel>(await this.TenantModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolTenantMapper.MapModelToBO(default(int), model); var record = await this.TenantRepository.Create(this.DalTenantMapper.MapBOToEF(bo)); response.SetRecord(this.BolTenantMapper.MapBOToModel(this.DalTenantMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiTenantRequestModel> PatchModel(int id, JsonPatchDocument <ApiTenantRequestModel> patch) { var record = await this.TenantService.Get(id); if (record == null) { return(null); } else { ApiTenantRequestModel request = this.TenantModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOTenant MapModelToBO( string id, ApiTenantRequestModel model ) { BOTenant boTenant = new BOTenant(); boTenant.SetProperties( id, model.DataVersion, model.JSON, model.Name, model.ProjectIds, model.TenantTags); return(boTenant); }
public void CreatePatch() { var mapper = new ApiTenantModelMapper(); var model = new ApiTenantRequestModel(); model.SetProperties(BitConverter.GetBytes(1), "A", "A", "A", "A"); JsonPatchDocument <ApiTenantRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTenantRequestModel(); patch.ApplyTo(response); response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.ProjectIds.Should().Be("A"); response.TenantTags.Should().Be("A"); }
public async void Delete() { var mock = new ServiceMockFacade<ITenantRepository>(); var model = new ApiTenantRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny<string>())).Returns(Task.CompletedTask); var service = new TenantService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TenantModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTenantMapperMock, mock.DALMapperMockFactory.DALTenantMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny<string>())); mock.ModelValidatorMockFactory.TenantModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny<string>())); }
public async void Create() { var mock = new ServiceMockFacade<ITenantRepository>(); var model = new ApiTenantRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny<Tenant>())).Returns(Task.FromResult(new Tenant())); var service = new TenantService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TenantModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTenantMapperMock, mock.DALMapperMockFactory.DALTenantMapperMock); CreateResponse<ApiTenantResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TenantModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny<ApiTenantRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny<Tenant>())); }
public virtual async Task <UpdateResponse <ApiTenantResponseModel> > Update( int id, ApiTenantRequestModel model) { var validationResult = await this.TenantModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolTenantMapper.MapModelToBO(id, model); await this.TenantRepository.Update(this.DalTenantMapper.MapBOToEF(bo)); var record = await this.TenantRepository.Get(id); return(new UpdateResponse <ApiTenantResponseModel>(this.BolTenantMapper.MapBOToModel(this.DalTenantMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTenantResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTenantRequestModel model) { ApiTenantRequestModel request = await this.PatchModel(id, this.TenantModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTenantResponseModel> result = await this.TenantService.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 <ApiTenantRequestModel> patch) { ApiTenantResponseModel record = await this.TenantService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTenantRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTenantResponseModel> result = await this.TenantService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTenantResponseModel> > TenantUpdateAsync(int id, ApiTenantRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Tenants/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTenantResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTenantRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }
public async Task <ValidationResult> ValidateCreateAsync(ApiTenantRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model)); }