Esempio n. 1
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IBusinessEntityRepository>();
            var model = new ApiBusinessEntityRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <BusinessEntity>())).Returns(Task.FromResult(new BusinessEntity()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new BusinessEntity()));
            var service = new BusinessEntityService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.BusinessEntityModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityMapperMock,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock,
                                                    mock.BOLMapperMockFactory.BOLPersonMapperMock,
                                                    mock.DALMapperMockFactory.DALPersonMapperMock);

            UpdateResponse <ApiBusinessEntityResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.BusinessEntityModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiBusinessEntityRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <BusinessEntity>()));
        }
        private async Task <ApiBusinessEntityResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiBusinessEntityRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"));
            CreateResponse <ApiBusinessEntityResponseModel> result = await client.BusinessEntityCreateAsync(model);

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

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            ApiBusinessEntityRequestModel response = mapper.MapResponseToRequest(model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Esempio n. 4
0
        public virtual async Task <IActionResult> Create([FromBody] ApiBusinessEntityRequestModel model)
        {
            CreateResponse <ApiBusinessEntityResponseModel> result = await this.BusinessEntityService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/BusinessEntities/{result.Record.BusinessEntityID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Esempio n. 5
0
        public virtual BOBusinessEntity MapModelToBO(
            int businessEntityID,
            ApiBusinessEntityRequestModel model
            )
        {
            BOBusinessEntity boBusinessEntity = new BOBusinessEntity();

            boBusinessEntity.SetProperties(
                businessEntityID,
                model.ModifiedDate,
                model.Rowguid);
            return(boBusinessEntity);
        }
        public void CreatePatch()
        {
            var mapper = new ApiBusinessEntityModelMapper();
            var model  = new ApiBusinessEntityRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

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

            patch.ApplyTo(response);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
Esempio n. 7
0
        public virtual async Task <CreateResponse <ApiBusinessEntityResponseModel> > Create(
            ApiBusinessEntityRequestModel model)
        {
            CreateResponse <ApiBusinessEntityResponseModel> response = new CreateResponse <ApiBusinessEntityResponseModel>(await this.BusinessEntityModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolBusinessEntityMapper.MapModelToBO(default(int), model);
                var record = await this.BusinessEntityRepository.Create(this.DalBusinessEntityMapper.MapBOToEF(bo));

                response.SetRecord(this.BolBusinessEntityMapper.MapBOToModel(this.DalBusinessEntityMapper.MapEFToBO(record)));
            }

            return(response);
        }
Esempio n. 8
0
        private async Task <ApiBusinessEntityRequestModel> PatchModel(int id, JsonPatchDocument <ApiBusinessEntityRequestModel> patch)
        {
            var record = await this.BusinessEntityService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiBusinessEntityRequestModel request = this.BusinessEntityModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Esempio n. 9
0
        public virtual async Task <UpdateResponse <ApiBusinessEntityResponseModel> > Update(
            int businessEntityID,
            ApiBusinessEntityRequestModel model)
        {
            var validationResult = await this.BusinessEntityModelValidator.ValidateUpdateAsync(businessEntityID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolBusinessEntityMapper.MapModelToBO(businessEntityID, model);
                await this.BusinessEntityRepository.Update(this.DalBusinessEntityMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiBusinessEntityResponseModel>(this.BolBusinessEntityMapper.MapBOToModel(this.DalBusinessEntityMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiBusinessEntityResponseModel>(validationResult));
            }
        }
Esempio n. 10
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiBusinessEntityRequestModel model)
        {
            ApiBusinessEntityRequestModel request = await this.PatchModel(id, this.BusinessEntityModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Esempio n. 11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IBusinessEntityRepository>();
            var model = new ApiBusinessEntityRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new BusinessEntityService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.BusinessEntityModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityMapperMock,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock,
                                                    mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock,
                                                    mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock,
                                                    mock.BOLMapperMockFactory.BOLPersonMapperMock,
                                                    mock.DALMapperMockFactory.DALPersonMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.BusinessEntityModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Esempio n. 12
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiBusinessEntityRequestModel> patch)
        {
            ApiBusinessEntityResponseModel record = await this.BusinessEntityService.Get(id);

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

                UpdateResponse <ApiBusinessEntityResponseModel> result = await this.BusinessEntityService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBusinessEntityRequestModel model)
 {
     this.ModifiedDateRules();
     this.RowguidRules();
     return(await this.ValidateAsync(model, id));
 }