public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBusinessEntityAddressRequestModel model) { this.AddressIDRules(); this.AddressTypeIDRules(); this.ModifiedDateRules(); this.RowguidRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiBusinessEntityAddressResponseModel> CreateRecord(ApiClient client) { var model = new ApiBusinessEntityAddressRequestModel(); model.SetProperties(2, 2, DateTime.Parse("1/1/1988 12:00:00 AM"), Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiBusinessEntityAddressResponseModel> result = await client.BusinessEntityAddressCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiBusinessEntityAddressRequestModel model) { CreateResponse <ApiBusinessEntityAddressResponseModel> result = await this.BusinessEntityAddressService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/BusinessEntityAddresses/{result.Record.BusinessEntityID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLBusinessEntityAddressMapper(); ApiBusinessEntityAddressRequestModel model = new ApiBusinessEntityAddressRequestModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); BOBusinessEntityAddress response = mapper.MapModelToBO(1, model); response.AddressID.Should().Be(1); response.AddressTypeID.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public virtual BOBusinessEntityAddress MapModelToBO( int businessEntityID, ApiBusinessEntityAddressRequestModel model ) { BOBusinessEntityAddress boBusinessEntityAddress = new BOBusinessEntityAddress(); boBusinessEntityAddress.SetProperties( businessEntityID, model.AddressID, model.AddressTypeID, model.ModifiedDate, model.Rowguid); return(boBusinessEntityAddress); }
private async Task <ApiBusinessEntityAddressRequestModel> PatchModel(int id, JsonPatchDocument <ApiBusinessEntityAddressRequestModel> patch) { var record = await this.BusinessEntityAddressService.Get(id); if (record == null) { return(null); } else { ApiBusinessEntityAddressRequestModel request = this.BusinessEntityAddressModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiBusinessEntityAddressResponseModel> > Create( ApiBusinessEntityAddressRequestModel model) { CreateResponse <ApiBusinessEntityAddressResponseModel> response = new CreateResponse <ApiBusinessEntityAddressResponseModel>(await this.businessEntityAddressModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolBusinessEntityAddressMapper.MapModelToBO(default(int), model); var record = await this.businessEntityAddressRepository.Create(this.dalBusinessEntityAddressMapper.MapBOToEF(bo)); response.SetRecord(this.bolBusinessEntityAddressMapper.MapBOToModel(this.dalBusinessEntityAddressMapper.MapEFToBO(record))); } return(response); }
public void CreatePatch() { var mapper = new ApiBusinessEntityAddressModelMapper(); var model = new ApiBusinessEntityAddressRequestModel(); model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); JsonPatchDocument <ApiBusinessEntityAddressRequestModel> patch = mapper.CreatePatch(model); var response = new ApiBusinessEntityAddressRequestModel(); patch.ApplyTo(response); response.AddressID.Should().Be(1); response.AddressTypeID.Should().Be(1); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); }
public async void Create() { var mock = new ServiceMockFacade <IBusinessEntityAddressRepository>(); var model = new ApiBusinessEntityAddressRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <BusinessEntityAddress>())).Returns(Task.FromResult(new BusinessEntityAddress())); var service = new BusinessEntityAddressService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BusinessEntityAddressModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock, mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock); CreateResponse <ApiBusinessEntityAddressResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BusinessEntityAddressModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBusinessEntityAddressRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <BusinessEntityAddress>())); }
public async void Delete() { var mock = new ServiceMockFacade <IBusinessEntityAddressRepository>(); var model = new ApiBusinessEntityAddressRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BusinessEntityAddressService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BusinessEntityAddressModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock, mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.BusinessEntityAddressModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiBusinessEntityAddressResponseModel> > Update( int businessEntityID, ApiBusinessEntityAddressRequestModel model) { var validationResult = await this.businessEntityAddressModelValidator.ValidateUpdateAsync(businessEntityID, model); if (validationResult.IsValid) { var bo = this.bolBusinessEntityAddressMapper.MapModelToBO(businessEntityID, model); await this.businessEntityAddressRepository.Update(this.dalBusinessEntityAddressMapper.MapBOToEF(bo)); var record = await this.businessEntityAddressRepository.Get(businessEntityID); return(new UpdateResponse <ApiBusinessEntityAddressResponseModel>(this.bolBusinessEntityAddressMapper.MapBOToModel(this.dalBusinessEntityAddressMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiBusinessEntityAddressResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiBusinessEntityAddressRequestModel model) { ApiBusinessEntityAddressRequestModel request = await this.PatchModel(id, this.BusinessEntityAddressModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiBusinessEntityAddressResponseModel> result = await this.BusinessEntityAddressService.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 <ApiBusinessEntityAddressRequestModel> patch) { ApiBusinessEntityAddressResponseModel record = await this.BusinessEntityAddressService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBusinessEntityAddressRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBusinessEntityAddressResponseModel> result = await this.BusinessEntityAddressService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }