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 ApiPaymentTypeRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiPaymentTypeResponseModel> createResult = await client.PaymentTypeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiPaymentTypeResponseModel getResponse = await client.PaymentTypeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.PaymentTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPaymentTypeResponseModel verifyResponse = await client.PaymentTypeGetAsync(2); verifyResponse.Should().BeNull(); }
public void MapModelToBO() { var mapper = new BOLPaymentTypeMapper(); ApiPaymentTypeRequestModel model = new ApiPaymentTypeRequestModel(); model.SetProperties("A"); BOPaymentType response = mapper.MapModelToBO(1, model); response.Name.Should().Be("A"); }
private async Task <ApiPaymentTypeResponseModel> CreateRecord() { var model = new ApiPaymentTypeRequestModel(); model.SetProperties("B"); CreateResponse <ApiPaymentTypeResponseModel> result = await this.Client.PaymentTypeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiPaymentTypeModelMapper(); var model = new ApiPaymentTypeResponseModel(); model.SetProperties(1, "A"); ApiPaymentTypeRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public virtual BOPaymentType MapModelToBO( int id, ApiPaymentTypeRequestModel model ) { BOPaymentType boPaymentType = new BOPaymentType(); boPaymentType.SetProperties( id, model.Name); return(boPaymentType); }
public virtual async Task <IActionResult> Create([FromBody] ApiPaymentTypeRequestModel model) { CreateResponse <ApiPaymentTypeResponseModel> result = await this.PaymentTypeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PaymentTypes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiPaymentTypeModelMapper(); var model = new ApiPaymentTypeRequestModel(); model.SetProperties("A"); JsonPatchDocument <ApiPaymentTypeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPaymentTypeRequestModel(); patch.ApplyTo(response); response.Name.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiPaymentTypeResponseModel> > Create( ApiPaymentTypeRequestModel model) { CreateResponse <ApiPaymentTypeResponseModel> response = new CreateResponse <ApiPaymentTypeResponseModel>(await this.paymentTypeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolPaymentTypeMapper.MapModelToBO(default(int), model); var record = await this.paymentTypeRepository.Create(this.dalPaymentTypeMapper.MapBOToEF(bo)); response.SetRecord(this.bolPaymentTypeMapper.MapBOToModel(this.dalPaymentTypeMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiPaymentTypeRequestModel> PatchModel(int id, JsonPatchDocument <ApiPaymentTypeRequestModel> patch) { var record = await this.PaymentTypeService.Get(id); if (record == null) { return(null); } else { ApiPaymentTypeRequestModel request = this.PaymentTypeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Create() { var mock = new ServiceMockFacade <IPaymentTypeRepository>(); var model = new ApiPaymentTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PaymentType>())).Returns(Task.FromResult(new PaymentType())); var service = new PaymentTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PaymentTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPaymentTypeMapperMock, mock.DALMapperMockFactory.DALPaymentTypeMapperMock, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); CreateResponse <ApiPaymentTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PaymentTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPaymentTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PaymentType>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPaymentTypeRepository>(); var model = new ApiPaymentTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PaymentTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PaymentTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPaymentTypeMapperMock, mock.DALMapperMockFactory.DALPaymentTypeMapperMock, mock.BOLMapperMockFactory.BOLSaleMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PaymentTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiPaymentTypeResponseModel> > Update( int id, ApiPaymentTypeRequestModel model) { var validationResult = await this.paymentTypeModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolPaymentTypeMapper.MapModelToBO(id, model); await this.paymentTypeRepository.Update(this.dalPaymentTypeMapper.MapBOToEF(bo)); var record = await this.paymentTypeRepository.Get(id); return(new UpdateResponse <ApiPaymentTypeResponseModel>(this.bolPaymentTypeMapper.MapBOToModel(this.dalPaymentTypeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPaymentTypeResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPaymentTypeRequestModel model) { ApiPaymentTypeRequestModel request = await this.PatchModel(id, this.PaymentTypeModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPaymentTypeResponseModel> result = await this.PaymentTypeService.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 <ApiPaymentTypeRequestModel> patch) { ApiPaymentTypeResponseModel record = await this.PaymentTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPaymentTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPaymentTypeResponseModel> result = await this.PaymentTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPaymentTypeRequestModel model) { this.NameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <UpdateResponse <ApiPaymentTypeResponseModel> > PaymentTypeUpdateAsync(int id, ApiPaymentTypeRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/PaymentTypes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiPaymentTypeResponseModel> >(httpResponse.Content.ContentToString())); }