public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiEmailAddressRequestModel model) { this.EmailAddress1Rules(); this.EmailAddressIDRules(); this.ModifiedDateRules(); this.RowguidRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiEmailAddressResponseModel> CreateRecord() { var model = new ApiEmailAddressRequestModel(); model.SetProperties("B", 2, DateTime.Parse("1/1/1988 12:00:00 AM"), Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); CreateResponse <ApiEmailAddressResponseModel> result = await this.Client.EmailAddressCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiEmailAddressModelMapper(); var model = new ApiEmailAddressResponseModel(); model.SetProperties(1, "A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); ApiEmailAddressRequestModel response = mapper.MapResponseToRequest(model); response.EmailAddress1.Should().Be("A"); response.EmailAddressID.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 async Task <IActionResult> Create([FromBody] ApiEmailAddressRequestModel model) { CreateResponse <ApiEmailAddressResponseModel> result = await this.EmailAddressService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/EmailAddresses/{result.Record.BusinessEntityID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual async Task <CreateResponse <ApiEmailAddressResponseModel> > Create( ApiEmailAddressRequestModel model) { CreateResponse <ApiEmailAddressResponseModel> response = new CreateResponse <ApiEmailAddressResponseModel>(await this.EmailAddressModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolEmailAddressMapper.MapModelToBO(default(int), model); var record = await this.EmailAddressRepository.Create(this.DalEmailAddressMapper.MapBOToEF(bo)); response.SetRecord(this.BolEmailAddressMapper.MapBOToModel(this.DalEmailAddressMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiEmailAddressRequestModel> PatchModel(int id, JsonPatchDocument <ApiEmailAddressRequestModel> patch) { var record = await this.EmailAddressService.Get(id); if (record == null) { return(null); } else { ApiEmailAddressRequestModel request = this.EmailAddressModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOEmailAddress MapModelToBO( int businessEntityID, ApiEmailAddressRequestModel model ) { BOEmailAddress boEmailAddress = new BOEmailAddress(); boEmailAddress.SetProperties( businessEntityID, model.EmailAddress1, model.EmailAddressID, model.ModifiedDate, model.Rowguid); return(boEmailAddress); }
public void CreatePatch() { var mapper = new ApiEmailAddressModelMapper(); var model = new ApiEmailAddressRequestModel(); model.SetProperties("A", 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); JsonPatchDocument <ApiEmailAddressRequestModel> patch = mapper.CreatePatch(model); var response = new ApiEmailAddressRequestModel(); patch.ApplyTo(response); response.EmailAddress1.Should().Be("A"); response.EmailAddressID.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 <IEmailAddressRepository>(); var model = new ApiEmailAddressRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EmailAddress>())).Returns(Task.FromResult(new EmailAddress())); var service = new EmailAddressService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLEmailAddressMapperMock, mock.DALMapperMockFactory.DALEmailAddressMapperMock); CreateResponse <ApiEmailAddressResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEmailAddressRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <EmailAddress>())); }
public async void Delete() { var mock = new ServiceMockFacade <IEmailAddressRepository>(); var model = new ApiEmailAddressRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new EmailAddressService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLEmailAddressMapperMock, mock.DALMapperMockFactory.DALEmailAddressMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiEmailAddressResponseModel> > Update( int businessEntityID, ApiEmailAddressRequestModel model) { var validationResult = await this.EmailAddressModelValidator.ValidateUpdateAsync(businessEntityID, model); if (validationResult.IsValid) { var bo = this.BolEmailAddressMapper.MapModelToBO(businessEntityID, model); await this.EmailAddressRepository.Update(this.DalEmailAddressMapper.MapBOToEF(bo)); var record = await this.EmailAddressRepository.Get(businessEntityID); return(new UpdateResponse <ApiEmailAddressResponseModel>(this.BolEmailAddressMapper.MapBOToModel(this.DalEmailAddressMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiEmailAddressResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiEmailAddressRequestModel model) { ApiEmailAddressRequestModel request = await this.PatchModel(id, this.EmailAddressModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiEmailAddressResponseModel> result = await this.EmailAddressService.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 <ApiEmailAddressRequestModel> patch) { ApiEmailAddressResponseModel record = await this.EmailAddressService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiEmailAddressRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiEmailAddressResponseModel> result = await this.EmailAddressService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }