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 ApiBucketRequestModel(); createModel.SetProperties(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiBucketResponseModel> createResult = await client.BucketCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiBucketResponseModel getResponse = await client.BucketGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.BucketDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiBucketResponseModel verifyResponse = await client.BucketGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiBucketResponseModel> CreateRecord() { var model = new ApiBucketRequestModel(); model.SetProperties(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiBucketResponseModel> result = await this.Client.BucketCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiBucketModelMapper(); var model = new ApiBucketResponseModel(); model.SetProperties(1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); ApiBucketRequestModel response = mapper.MapResponseToRequest(model); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLBucketMapper(); ApiBucketRequestModel model = new ApiBucketRequestModel(); model.SetProperties(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); BOBucket response = mapper.MapModelToBO(1, model); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiBucketRequestModel model) { CreateResponse <ApiBucketResponseModel> result = await this.BucketService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Buckets/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOBucket MapModelToBO( int id, ApiBucketRequestModel model ) { BOBucket boBucket = new BOBucket(); boBucket.SetProperties( id, model.ExternalId, model.Name); return(boBucket); }
public void CreatePatch() { var mapper = new ApiBucketModelMapper(); var model = new ApiBucketRequestModel(); model.SetProperties(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); JsonPatchDocument <ApiBucketRequestModel> patch = mapper.CreatePatch(model); var response = new ApiBucketRequestModel(); patch.ApplyTo(response); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
private async Task <ApiBucketRequestModel> PatchModel(int id, JsonPatchDocument <ApiBucketRequestModel> patch) { var record = await this.BucketService.Get(id); if (record == null) { return(null); } else { ApiBucketRequestModel request = this.BucketModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiBucketResponseModel> > Create( ApiBucketRequestModel model) { CreateResponse <ApiBucketResponseModel> response = new CreateResponse <ApiBucketResponseModel>(await this.bucketModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolBucketMapper.MapModelToBO(default(int), model); var record = await this.bucketRepository.Create(this.dalBucketMapper.MapBOToEF(bo)); response.SetRecord(this.bolBucketMapper.MapBOToModel(this.dalBucketMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <IBucketRepository>(); var model = new ApiBucketRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Bucket>())).Returns(Task.FromResult(new Bucket())); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiBucketResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BucketModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBucketRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Bucket>())); }
public async void Delete() { var mock = new ServiceMockFacade <IBucketRepository>(); var model = new ApiBucketRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.BucketModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiBucketResponseModel> > Update( int id, ApiBucketRequestModel model) { var validationResult = await this.bucketModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolBucketMapper.MapModelToBO(id, model); await this.bucketRepository.Update(this.dalBucketMapper.MapBOToEF(bo)); var record = await this.bucketRepository.Get(id); return(new UpdateResponse <ApiBucketResponseModel>(this.bolBucketMapper.MapBOToModel(this.dalBucketMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiBucketResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiBucketRequestModel model) { ApiBucketRequestModel request = await this.PatchModel(id, this.BucketModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiBucketResponseModel> result = await this.BucketService.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 <ApiBucketRequestModel> patch) { ApiBucketResponseModel record = await this.BucketService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBucketRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBucketResponseModel> result = await this.BucketService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiBucketResponseModel> > BucketUpdateAsync(int id, ApiBucketRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Buckets/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiBucketResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBucketRequestModel model) { this.ExternalIdRules(); this.NameRules(); return(await this.ValidateAsync(model, id)); }