public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiShipMethodRequestModel model) { this.ModifiedDateRules(); this.NameRules(); this.RowguidRules(); this.ShipBaseRules(); this.ShipRateRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiShipMethodResponseModel> CreateRecord() { var model = new ApiShipMethodRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 2m, 2m); CreateResponse <ApiShipMethodResponseModel> result = await this.Client.ShipMethodCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiShipMethodRequestModel model) { CreateResponse <ApiShipMethodResponseModel> result = await this.ShipMethodService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ShipMethods/{result.Record.ShipMethodID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapResponseToRequest() { var mapper = new ApiShipMethodModelMapper(); var model = new ApiShipMethodResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1m, 1m); ApiShipMethodRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.ShipBase.Should().Be(1m); response.ShipRate.Should().Be(1m); }
public virtual async Task <CreateResponse <ApiShipMethodResponseModel> > Create( ApiShipMethodRequestModel model) { CreateResponse <ApiShipMethodResponseModel> response = new CreateResponse <ApiShipMethodResponseModel>(await this.ShipMethodModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolShipMethodMapper.MapModelToBO(default(int), model); var record = await this.ShipMethodRepository.Create(this.DalShipMethodMapper.MapBOToEF(bo)); response.SetRecord(this.BolShipMethodMapper.MapBOToModel(this.DalShipMethodMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiShipMethodRequestModel> PatchModel(int id, JsonPatchDocument <ApiShipMethodRequestModel> patch) { var record = await this.ShipMethodService.Get(id); if (record == null) { return(null); } else { ApiShipMethodRequestModel request = this.ShipMethodModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiShipMethodModelMapper(); var model = new ApiShipMethodRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1m, 1m); JsonPatchDocument<ApiShipMethodRequestModel> patch = mapper.CreatePatch(model); var response = new ApiShipMethodRequestModel(); patch.ApplyTo(response); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.ShipBase.Should().Be(1m); response.ShipRate.Should().Be(1m); }
public virtual BOShipMethod MapModelToBO( int shipMethodID, ApiShipMethodRequestModel model ) { BOShipMethod boShipMethod = new BOShipMethod(); boShipMethod.SetProperties( shipMethodID, model.ModifiedDate, model.Name, model.Rowguid, model.ShipBase, model.ShipRate); return(boShipMethod); }
public virtual async Task <UpdateResponse <ApiShipMethodResponseModel> > Update( int shipMethodID, ApiShipMethodRequestModel model) { var validationResult = await this.ShipMethodModelValidator.ValidateUpdateAsync(shipMethodID, model); if (validationResult.IsValid) { var bo = this.BolShipMethodMapper.MapModelToBO(shipMethodID, model); await this.ShipMethodRepository.Update(this.DalShipMethodMapper.MapBOToEF(bo)); var record = await this.ShipMethodRepository.Get(shipMethodID); return(new UpdateResponse <ApiShipMethodResponseModel>(this.BolShipMethodMapper.MapBOToModel(this.DalShipMethodMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiShipMethodResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <IShipMethodRepository>(); var model = new ApiShipMethodRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ShipMethod>())).Returns(Task.FromResult(new ShipMethod())); var service = new ShipMethodService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ShipMethodModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLShipMethodMapperMock, mock.DALMapperMockFactory.DALShipMethodMapperMock, mock.BOLMapperMockFactory.BOLPurchaseOrderHeaderMapperMock, mock.DALMapperMockFactory.DALPurchaseOrderHeaderMapperMock); CreateResponse <ApiShipMethodResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ShipMethodModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiShipMethodRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ShipMethod>())); }
public async void Delete() { var mock = new ServiceMockFacade <IShipMethodRepository>(); var model = new ApiShipMethodRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ShipMethodService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ShipMethodModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLShipMethodMapperMock, mock.DALMapperMockFactory.DALShipMethodMapperMock, mock.BOLMapperMockFactory.BOLPurchaseOrderHeaderMapperMock, mock.DALMapperMockFactory.DALPurchaseOrderHeaderMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ShipMethodModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiShipMethodRequestModel model) { ApiShipMethodRequestModel request = await this.PatchModel(id, this.ShipMethodModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiShipMethodResponseModel> result = await this.ShipMethodService.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 <ApiShipMethodRequestModel> patch) { ApiShipMethodResponseModel record = await this.ShipMethodService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiShipMethodRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiShipMethodResponseModel> result = await this.ShipMethodService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }