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 ApiChainStatusRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiChainStatusResponseModel> createResult = await client.ChainStatusCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiChainStatusResponseModel getResponse = await client.ChainStatusGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.ChainStatusDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiChainStatusResponseModel verifyResponse = await client.ChainStatusGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiChainStatusResponseModel> CreateRecord() { var model = new ApiChainStatusRequestModel(); model.SetProperties("B"); CreateResponse <ApiChainStatusResponseModel> result = await this.Client.ChainStatusCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLChainStatusMapper(); ApiChainStatusRequestModel model = new ApiChainStatusRequestModel(); model.SetProperties("A"); BOChainStatus response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiChainStatusModelMapper(); var model = new ApiChainStatusResponseModel(); model.SetProperties(1, "A"); ApiChainStatusRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public virtual BOChainStatus MapModelToBO( int id, ApiChainStatusRequestModel model ) { BOChainStatus boChainStatus = new BOChainStatus(); boChainStatus.SetProperties( id, model.Name); return(boChainStatus); }
public void CreatePatch() { var mapper = new ApiChainStatusModelMapper(); var model = new ApiChainStatusRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiChainStatusRequestModel> patch = mapper.CreatePatch(model); var response = new ApiChainStatusRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiChainStatusRequestModel model) { CreateResponse <ApiChainStatusResponseModel> result = await this.ChainStatusService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ChainStatuses/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual async Task <CreateResponse <ApiChainStatusResponseModel> > Create( ApiChainStatusRequestModel model) { CreateResponse <ApiChainStatusResponseModel> response = new CreateResponse <ApiChainStatusResponseModel>(await this.chainStatusModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolChainStatusMapper.MapModelToBO(default(int), model); var record = await this.chainStatusRepository.Create(this.dalChainStatusMapper.MapBOToEF(bo)); response.SetRecord(this.bolChainStatusMapper.MapBOToModel(this.dalChainStatusMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiChainStatusRequestModel> PatchModel(int id, JsonPatchDocument <ApiChainStatusRequestModel> patch) { var record = await this.ChainStatusService.Get(id); if (record == null) { return(null); } else { ApiChainStatusRequestModel request = this.ChainStatusModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IChainStatusRepository>(); var model = new ApiChainStatusRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ChainStatus>())).Returns(Task.FromResult(new ChainStatus())); var service = new ChainStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLChainStatusMapperMock, mock.DALMapperMockFactory.DALChainStatusMapperMock, mock.BOLMapperMockFactory.BOLChainMapperMock, mock.DALMapperMockFactory.DALChainMapperMock); CreateResponse <ApiChainStatusResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiChainStatusRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ChainStatus>())); }
public async void Delete() { var mock = new ServiceMockFacade <IChainStatusRepository>(); var model = new ApiChainStatusRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ChainStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLChainStatusMapperMock, mock.DALMapperMockFactory.DALChainStatusMapperMock, mock.BOLMapperMockFactory.BOLChainMapperMock, mock.DALMapperMockFactory.DALChainMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiChainStatusResponseModel> > Update( int id, ApiChainStatusRequestModel model) { var validationResult = await this.chainStatusModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolChainStatusMapper.MapModelToBO(id, model); await this.chainStatusRepository.Update(this.dalChainStatusMapper.MapBOToEF(bo)); var record = await this.chainStatusRepository.Get(id); return(new UpdateResponse <ApiChainStatusResponseModel>(this.bolChainStatusMapper.MapBOToModel(this.dalChainStatusMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiChainStatusResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiChainStatusRequestModel model) { ApiChainStatusRequestModel request = await this.PatchModel(id, this.ChainStatusModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiChainStatusResponseModel> result = await this.ChainStatusService.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 <ApiChainStatusRequestModel> patch) { ApiChainStatusResponseModel record = await this.ChainStatusService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiChainStatusRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiChainStatusResponseModel> result = await this.ChainStatusService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiChainStatusRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <UpdateResponse <ApiChainStatusResponseModel> > ChainStatusUpdateAsync(int id, ApiChainStatusRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/ChainStatuses/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiChainStatusResponseModel> >(httpResponse.Content.ContentToString())); }