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 ApiRowVersionCheckRequestModel(); createModel.SetProperties("B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiRowVersionCheckResponseModel> createResult = await client.RowVersionCheckCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiRowVersionCheckResponseModel getResponse = await client.RowVersionCheckGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.RowVersionCheckDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiRowVersionCheckResponseModel verifyResponse = await client.RowVersionCheckGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiRowVersionCheckResponseModel> CreateRecord(ApiClient client) { var model = new ApiRowVersionCheckRequestModel(); model.SetProperties("B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiRowVersionCheckResponseModel> result = await client.RowVersionCheckCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLRowVersionCheckMapper(); ApiRowVersionCheckRequestModel model = new ApiRowVersionCheckRequestModel(); model.SetProperties("A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); BORowVersionCheck response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); response.RowVersion.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public void MapResponseToRequest() { var mapper = new ApiRowVersionCheckModelMapper(); var model = new ApiRowVersionCheckResponseModel(); model.SetProperties(1, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiRowVersionCheckRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); response.RowVersion.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public virtual BORowVersionCheck MapModelToBO( int id, ApiRowVersionCheckRequestModel model ) { BORowVersionCheck boRowVersionCheck = new BORowVersionCheck(); boRowVersionCheck.SetProperties( id, model.Name, model.RowVersion); return(boRowVersionCheck); }
public virtual async Task <IActionResult> Create([FromBody] ApiRowVersionCheckRequestModel model) { CreateResponse <ApiRowVersionCheckResponseModel> result = await this.RowVersionCheckService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/RowVersionChecks/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiRowVersionCheckModelMapper(); var model = new ApiRowVersionCheckRequestModel(); model.SetProperties("A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); JsonPatchDocument <ApiRowVersionCheckRequestModel> patch = mapper.CreatePatch(model); var response = new ApiRowVersionCheckRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); response.RowVersion.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public virtual async Task <CreateResponse <ApiRowVersionCheckResponseModel> > Create( ApiRowVersionCheckRequestModel model) { CreateResponse <ApiRowVersionCheckResponseModel> response = new CreateResponse <ApiRowVersionCheckResponseModel>(await this.RowVersionCheckModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolRowVersionCheckMapper.MapModelToBO(default(int), model); var record = await this.RowVersionCheckRepository.Create(this.DalRowVersionCheckMapper.MapBOToEF(bo)); response.SetRecord(this.BolRowVersionCheckMapper.MapBOToModel(this.DalRowVersionCheckMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiRowVersionCheckRequestModel> PatchModel(int id, JsonPatchDocument <ApiRowVersionCheckRequestModel> patch) { var record = await this.RowVersionCheckService.Get(id); if (record == null) { return(null); } else { ApiRowVersionCheckRequestModel request = this.RowVersionCheckModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IRowVersionCheckRepository>(); var model = new ApiRowVersionCheckRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <RowVersionCheck>())).Returns(Task.FromResult(new RowVersionCheck())); var service = new RowVersionCheckService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.RowVersionCheckModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLRowVersionCheckMapperMock, mock.DALMapperMockFactory.DALRowVersionCheckMapperMock); CreateResponse <ApiRowVersionCheckResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.RowVersionCheckModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiRowVersionCheckRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <RowVersionCheck>())); }
public async void Delete() { var mock = new ServiceMockFacade <IRowVersionCheckRepository>(); var model = new ApiRowVersionCheckRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new RowVersionCheckService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.RowVersionCheckModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLRowVersionCheckMapperMock, mock.DALMapperMockFactory.DALRowVersionCheckMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.RowVersionCheckModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiRowVersionCheckResponseModel> > Update( int id, ApiRowVersionCheckRequestModel model) { var validationResult = await this.RowVersionCheckModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolRowVersionCheckMapper.MapModelToBO(id, model); await this.RowVersionCheckRepository.Update(this.DalRowVersionCheckMapper.MapBOToEF(bo)); var record = await this.RowVersionCheckRepository.Get(id); return(new UpdateResponse <ApiRowVersionCheckResponseModel>(this.BolRowVersionCheckMapper.MapBOToModel(this.DalRowVersionCheckMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiRowVersionCheckResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiRowVersionCheckRequestModel model) { ApiRowVersionCheckRequestModel request = await this.PatchModel(id, this.RowVersionCheckModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiRowVersionCheckResponseModel> result = await this.RowVersionCheckService.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 <ApiRowVersionCheckRequestModel> patch) { ApiRowVersionCheckResponseModel record = await this.RowVersionCheckService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiRowVersionCheckRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiRowVersionCheckResponseModel> result = await this.RowVersionCheckService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiRowVersionCheckResponseModel> > RowVersionCheckUpdateAsync(int id, ApiRowVersionCheckRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/RowVersionChecks/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiRowVersionCheckResponseModel> >(httpResponse.Content.ContentToString())); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiRowVersionCheckRequestModel model) { this.NameRules(); this.RowVersionRules(); return(await this.ValidateAsync(model, id)); }