Exemplo n.º 1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiPersonPhoneRequestModel model)
 {
     this.ModifiedDateRules();
     this.PhoneNumberRules();
     this.PhoneNumberTypeIDRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiPersonPhoneResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiPersonPhoneRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2);
            CreateResponse <ApiPersonPhoneResponseModel> result = await client.PersonPhoneCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiPersonPhoneModelMapper();
            var model  = new ApiPersonPhoneResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);
            ApiPersonPhoneRequestModel response = mapper.MapResponseToRequest(model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PhoneNumber.Should().Be("A");
            response.PhoneNumberTypeID.Should().Be(1);
        }
Exemplo n.º 4
0
        public void MapModelToBO()
        {
            var mapper = new BOLPersonPhoneMapper();
            ApiPersonPhoneRequestModel model = new ApiPersonPhoneRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);
            BOPersonPhone response = mapper.MapModelToBO(1, model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PhoneNumber.Should().Be("A");
            response.PhoneNumberTypeID.Should().Be(1);
        }
Exemplo n.º 5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiPersonPhoneRequestModel model)
        {
            CreateResponse <ApiPersonPhoneResponseModel> result = await this.PersonPhoneService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/PersonPhones/{result.Record.BusinessEntityID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOPersonPhone MapModelToBO(
            int businessEntityID,
            ApiPersonPhoneRequestModel model
            )
        {
            BOPersonPhone boPersonPhone = new BOPersonPhone();

            boPersonPhone.SetProperties(
                businessEntityID,
                model.ModifiedDate,
                model.PhoneNumber,
                model.PhoneNumberTypeID);
            return(boPersonPhone);
        }
        public void CreatePatch()
        {
            var mapper = new ApiPersonPhoneModelMapper();
            var model  = new ApiPersonPhoneRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);

            JsonPatchDocument <ApiPersonPhoneRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiPersonPhoneRequestModel();

            patch.ApplyTo(response);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PhoneNumber.Should().Be("A");
            response.PhoneNumberTypeID.Should().Be(1);
        }
Exemplo n.º 8
0
        private async Task <ApiPersonPhoneRequestModel> PatchModel(int id, JsonPatchDocument <ApiPersonPhoneRequestModel> patch)
        {
            var record = await this.PersonPhoneService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiPersonPhoneRequestModel request = this.PersonPhoneModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemplo n.º 9
0
        public virtual async Task <CreateResponse <ApiPersonPhoneResponseModel> > Create(
            ApiPersonPhoneRequestModel model)
        {
            CreateResponse <ApiPersonPhoneResponseModel> response = new CreateResponse <ApiPersonPhoneResponseModel>(await this.personPhoneModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolPersonPhoneMapper.MapModelToBO(default(int), model);
                var record = await this.personPhoneRepository.Create(this.dalPersonPhoneMapper.MapBOToEF(bo));

                response.SetRecord(this.bolPersonPhoneMapper.MapBOToModel(this.dalPersonPhoneMapper.MapEFToBO(record)));
            }

            return(response);
        }
Exemplo n.º 10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPersonPhoneRepository>();
            var model = new ApiPersonPhoneRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PersonPhone>())).Returns(Task.FromResult(new PersonPhone()));
            var service = new PersonPhoneService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PersonPhoneModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLPersonPhoneMapperMock,
                                                 mock.DALMapperMockFactory.DALPersonPhoneMapperMock);

            CreateResponse <ApiPersonPhoneResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PersonPhoneModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPersonPhoneRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PersonPhone>()));
        }
Exemplo n.º 11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPersonPhoneRepository>();
            var model = new ApiPersonPhoneRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PersonPhoneService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PersonPhoneModelValidatorMock.Object,
                                                 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.PersonPhoneModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Exemplo n.º 12
0
        public virtual async Task <UpdateResponse <ApiPersonPhoneResponseModel> > Update(
            int businessEntityID,
            ApiPersonPhoneRequestModel model)
        {
            var validationResult = await this.personPhoneModelValidator.ValidateUpdateAsync(businessEntityID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolPersonPhoneMapper.MapModelToBO(businessEntityID, model);
                await this.personPhoneRepository.Update(this.dalPersonPhoneMapper.MapBOToEF(bo));

                var record = await this.personPhoneRepository.Get(businessEntityID);

                return(new UpdateResponse <ApiPersonPhoneResponseModel>(this.bolPersonPhoneMapper.MapBOToModel(this.dalPersonPhoneMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiPersonPhoneResponseModel>(validationResult));
            }
        }
Exemplo n.º 13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiPersonPhoneRequestModel model)
        {
            ApiPersonPhoneRequestModel request = await this.PatchModel(id, this.PersonPhoneModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiPersonPhoneResponseModel> result = await this.PersonPhoneService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPersonPhoneRequestModel> patch)
        {
            ApiPersonPhoneResponseModel record = await this.PersonPhoneService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiPersonPhoneRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiPersonPhoneResponseModel> result = await this.PersonPhoneService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }