private async Task <ApiPhoneNumberTypeResponseModel> CreateRecord() { var model = new ApiPhoneNumberTypeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B"); CreateResponse <ApiPhoneNumberTypeResponseModel> result = await this.Client.PhoneNumberTypeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiPhoneNumberTypeModelMapper(); var model = new ApiPhoneNumberTypeResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiPhoneNumberTypeRequestModel response = mapper.MapResponseToRequest(model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLPhoneNumberTypeMapper(); ApiPhoneNumberTypeRequestModel model = new ApiPhoneNumberTypeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); BOPhoneNumberType response = mapper.MapModelToBO(1, model); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); }
public virtual async Task <IActionResult> Create([FromBody] ApiPhoneNumberTypeRequestModel model) { CreateResponse <ApiPhoneNumberTypeResponseModel> result = await this.PhoneNumberTypeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PhoneNumberTypes/{result.Record.PhoneNumberTypeID}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOPhoneNumberType MapModelToBO( int phoneNumberTypeID, ApiPhoneNumberTypeRequestModel model ) { BOPhoneNumberType boPhoneNumberType = new BOPhoneNumberType(); boPhoneNumberType.SetProperties( phoneNumberTypeID, model.ModifiedDate, model.Name); return(boPhoneNumberType); }
public void CreatePatch() { var mapper = new ApiPhoneNumberTypeModelMapper(); var model = new ApiPhoneNumberTypeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); JsonPatchDocument <ApiPhoneNumberTypeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiPhoneNumberTypeRequestModel(); patch.ApplyTo(response); response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiPhoneNumberTypeResponseModel> > Create( ApiPhoneNumberTypeRequestModel model) { CreateResponse <ApiPhoneNumberTypeResponseModel> response = new CreateResponse <ApiPhoneNumberTypeResponseModel>(await this.PhoneNumberTypeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolPhoneNumberTypeMapper.MapModelToBO(default(int), model); var record = await this.PhoneNumberTypeRepository.Create(this.DalPhoneNumberTypeMapper.MapBOToEF(bo)); response.SetRecord(this.BolPhoneNumberTypeMapper.MapBOToModel(this.DalPhoneNumberTypeMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiPhoneNumberTypeRequestModel> PatchModel(int id, JsonPatchDocument <ApiPhoneNumberTypeRequestModel> patch) { var record = await this.PhoneNumberTypeService.Get(id); if (record == null) { return(null); } else { ApiPhoneNumberTypeRequestModel request = this.PhoneNumberTypeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <UpdateResponse <ApiPhoneNumberTypeResponseModel> > Update( int phoneNumberTypeID, ApiPhoneNumberTypeRequestModel model) { var validationResult = await this.PhoneNumberTypeModelValidator.ValidateUpdateAsync(phoneNumberTypeID, model); if (validationResult.IsValid) { var bo = this.BolPhoneNumberTypeMapper.MapModelToBO(phoneNumberTypeID, model); await this.PhoneNumberTypeRepository.Update(this.DalPhoneNumberTypeMapper.MapBOToEF(bo)); var record = await this.PhoneNumberTypeRepository.Get(phoneNumberTypeID); return(new UpdateResponse <ApiPhoneNumberTypeResponseModel>(this.BolPhoneNumberTypeMapper.MapBOToModel(this.DalPhoneNumberTypeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiPhoneNumberTypeResponseModel>(validationResult)); } }
public async void Create() { var mock = new ServiceMockFacade <IPhoneNumberTypeRepository>(); var model = new ApiPhoneNumberTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PhoneNumberType>())).Returns(Task.FromResult(new PhoneNumberType())); var service = new PhoneNumberTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PhoneNumberTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPhoneNumberTypeMapperMock, mock.DALMapperMockFactory.DALPhoneNumberTypeMapperMock, mock.BOLMapperMockFactory.BOLPersonPhoneMapperMock, mock.DALMapperMockFactory.DALPersonPhoneMapperMock); CreateResponse <ApiPhoneNumberTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.PhoneNumberTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPhoneNumberTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PhoneNumberType>())); }
public async void Delete() { var mock = new ServiceMockFacade <IPhoneNumberTypeRepository>(); var model = new ApiPhoneNumberTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new PhoneNumberTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PhoneNumberTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPhoneNumberTypeMapperMock, mock.DALMapperMockFactory.DALPhoneNumberTypeMapperMock, mock.BOLMapperMockFactory.BOLPersonPhoneMapperMock, mock.DALMapperMockFactory.DALPersonPhoneMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.PhoneNumberTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPhoneNumberTypeRequestModel model) { ApiPhoneNumberTypeRequestModel request = await this.PatchModel(id, this.PhoneNumberTypeModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiPhoneNumberTypeResponseModel> result = await this.PhoneNumberTypeService.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 <ApiPhoneNumberTypeRequestModel> patch) { ApiPhoneNumberTypeResponseModel record = await this.PhoneNumberTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPhoneNumberTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiPhoneNumberTypeResponseModel> result = await this.PhoneNumberTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPhoneNumberTypeRequestModel model) { this.ModifiedDateRules(); this.NameRules(); return(await this.ValidateAsync(model, id)); }