public void MapModelToBO()
        {
            var mapper = new BOLConfigurationMapper();
            ApiConfigurationRequestModel model = new ApiConfigurationRequestModel();

            model.SetProperties("A");
            BOConfiguration response = mapper.MapModelToBO("A", model);

            response.JSON.Should().Be("A");
        }
        private async Task <ApiConfigurationResponseModel> CreateRecord()
        {
            var model = new ApiConfigurationRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiConfigurationResponseModel> result = await this.Client.ConfigurationCreateAsync(model);

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

            model.SetProperties("A", "A");
            ApiConfigurationRequestModel response = mapper.MapResponseToRequest(model);

            response.JSON.Should().Be("A");
        }
        public virtual BOConfiguration MapModelToBO(
            string id,
            ApiConfigurationRequestModel model
            )
        {
            BOConfiguration boConfiguration = new BOConfiguration();

            boConfiguration.SetProperties(
                id,
                model.JSON);
            return(boConfiguration);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiConfigurationRequestModel model)
        {
            CreateResponse <ApiConfigurationResponseModel> result = await this.ConfigurationService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Configurations/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiConfigurationModelMapper();
            var model  = new ApiConfigurationRequestModel();

            model.SetProperties("A");

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

            patch.ApplyTo(response);
            response.JSON.Should().Be("A");
        }
        private async Task <ApiConfigurationRequestModel> PatchModel(string id, JsonPatchDocument <ApiConfigurationRequestModel> patch)
        {
            var record = await this.ConfigurationService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiConfigurationRequestModel request = this.ConfigurationModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiConfigurationResponseModel> > Create(
            ApiConfigurationRequestModel model)
        {
            CreateResponse <ApiConfigurationResponseModel> response = new CreateResponse <ApiConfigurationResponseModel>(await this.configurationModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolConfigurationMapper.MapModelToBO(default(string), model);
                var record = await this.configurationRepository.Create(this.dalConfigurationMapper.MapBOToEF(bo));

                response.SetRecord(this.bolConfigurationMapper.MapBOToModel(this.dalConfigurationMapper.MapEFToBO(record)));
            }

            return(response);
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IConfigurationRepository>();
            var model = new ApiConfigurationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Configuration>())).Returns(Task.FromResult(new Configuration()));
            var service = new ConfigurationService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.ConfigurationModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLConfigurationMapperMock,
                                                   mock.DALMapperMockFactory.DALConfigurationMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ConfigurationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiConfigurationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Configuration>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IConfigurationRepository>();
            var model = new ApiConfigurationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new ConfigurationService(mock.LoggerMock.Object,
                                                   mock.RepositoryMock.Object,
                                                   mock.ModelValidatorMockFactory.ConfigurationModelValidatorMock.Object,
                                                   mock.BOLMapperMockFactory.BOLConfigurationMapperMock,
                                                   mock.DALMapperMockFactory.DALConfigurationMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.ConfigurationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public virtual async Task <UpdateResponse <ApiConfigurationResponseModel> > Update(
            string id,
            ApiConfigurationRequestModel model)
        {
            var validationResult = await this.configurationModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolConfigurationMapper.MapModelToBO(id, model);
                await this.configurationRepository.Update(this.dalConfigurationMapper.MapBOToEF(bo));

                var record = await this.configurationRepository.Get(id);

                return(new UpdateResponse <ApiConfigurationResponseModel>(this.bolConfigurationMapper.MapBOToModel(this.dalConfigurationMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiConfigurationResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiConfigurationRequestModel model)
        {
            ApiConfigurationRequestModel request = await this.PatchModel(id, this.ConfigurationModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiConfigurationRequestModel> patch)
        {
            ApiConfigurationResponseModel record = await this.ConfigurationService.Get(id);

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

                UpdateResponse <ApiConfigurationResponseModel> result = await this.ConfigurationService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiConfigurationRequestModel model)
 {
     this.JSONRules();
     return(await this.ValidateAsync(model, id));
 }
 public async Task <ValidationResult> ValidateCreateAsync(ApiConfigurationRequestModel model)
 {
     this.JSONRules();
     return(await this.ValidateAsync(model));
 }