Example #1
0
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiDashboardConfigurationRequestModel model)
 {
     this.IncludedEnvironmentIdsRules();
     this.IncludedProjectIdsRules();
     this.IncludedTenantIdsRules();
     this.IncludedTenantTagsRules();
     this.JSONRules();
     return(await this.ValidateAsync(model, id));
 }
Example #2
0
        private async Task <ApiDashboardConfigurationResponseModel> CreateRecord()
        {
            var model = new ApiDashboardConfigurationRequestModel();

            model.SetProperties("B", "B", "B", "B", "B");
            CreateResponse <ApiDashboardConfigurationResponseModel> result = await this.Client.DashboardConfigurationCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiDashboardConfigurationRequestModel model)
        {
            CreateResponse <ApiDashboardConfigurationResponseModel> result = await this.DashboardConfigurationService.Create(model);

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

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

            response.IncludedEnvironmentIds.Should().Be("A");
            response.IncludedProjectIds.Should().Be("A");
            response.IncludedTenantIds.Should().Be("A");
            response.IncludedTenantTags.Should().Be("A");
            response.JSON.Should().Be("A");
        }
Example #5
0
        public void MapModelToBO()
        {
            var mapper = new BOLDashboardConfigurationMapper();
            ApiDashboardConfigurationRequestModel model = new ApiDashboardConfigurationRequestModel();

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

            response.IncludedEnvironmentIds.Should().Be("A");
            response.IncludedProjectIds.Should().Be("A");
            response.IncludedTenantIds.Should().Be("A");
            response.IncludedTenantTags.Should().Be("A");
            response.JSON.Should().Be("A");
        }
        public virtual async Task <CreateResponse <ApiDashboardConfigurationResponseModel> > Create(
            ApiDashboardConfigurationRequestModel model)
        {
            CreateResponse <ApiDashboardConfigurationResponseModel> response = new CreateResponse <ApiDashboardConfigurationResponseModel>(await this.dashboardConfigurationModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolDashboardConfigurationMapper.MapModelToBO(default(string), model);
                var record = await this.dashboardConfigurationRepository.Create(this.dalDashboardConfigurationMapper.MapBOToEF(bo));

                response.SetRecord(this.bolDashboardConfigurationMapper.MapBOToModel(this.dalDashboardConfigurationMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiDashboardConfigurationRequestModel> PatchModel(string id, JsonPatchDocument <ApiDashboardConfigurationRequestModel> patch)
        {
            var record = await this.DashboardConfigurationService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiDashboardConfigurationRequestModel request = this.DashboardConfigurationModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual BODashboardConfiguration MapModelToBO(
            string id,
            ApiDashboardConfigurationRequestModel model
            )
        {
            BODashboardConfiguration boDashboardConfiguration = new BODashboardConfiguration();

            boDashboardConfiguration.SetProperties(
                id,
                model.IncludedEnvironmentIds,
                model.IncludedProjectIds,
                model.IncludedTenantIds,
                model.IncludedTenantTags,
                model.JSON);
            return(boDashboardConfiguration);
        }
        public void CreatePatch()
        {
            var mapper = new ApiDashboardConfigurationModelMapper();
            var model  = new ApiDashboardConfigurationRequestModel();

            model.SetProperties("A", "A", "A", "A", "A");

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

            patch.ApplyTo(response);
            response.IncludedEnvironmentIds.Should().Be("A");
            response.IncludedProjectIds.Should().Be("A");
            response.IncludedTenantIds.Should().Be("A");
            response.IncludedTenantTags.Should().Be("A");
            response.JSON.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IDashboardConfigurationRepository>();
            var model = new ApiDashboardConfigurationRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <DashboardConfiguration>())).Returns(Task.FromResult(new DashboardConfiguration()));
            var service = new DashboardConfigurationService(mock.LoggerMock.Object,
                                                            mock.RepositoryMock.Object,
                                                            mock.ModelValidatorMockFactory.DashboardConfigurationModelValidatorMock.Object,
                                                            mock.BOLMapperMockFactory.BOLDashboardConfigurationMapperMock,
                                                            mock.DALMapperMockFactory.DALDashboardConfigurationMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.DashboardConfigurationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDashboardConfigurationRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <DashboardConfiguration>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IDashboardConfigurationRepository>();
            var model = new ApiDashboardConfigurationRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new DashboardConfigurationService(mock.LoggerMock.Object,
                                                            mock.RepositoryMock.Object,
                                                            mock.ModelValidatorMockFactory.DashboardConfigurationModelValidatorMock.Object,
                                                            mock.BOLMapperMockFactory.BOLDashboardConfigurationMapperMock,
                                                            mock.DALMapperMockFactory.DALDashboardConfigurationMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolDashboardConfigurationMapper.MapModelToBO(id, model);
                await this.dashboardConfigurationRepository.Update(this.dalDashboardConfigurationMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiDashboardConfigurationResponseModel>(this.bolDashboardConfigurationMapper.MapBOToModel(this.dalDashboardConfigurationMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiDashboardConfigurationResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiDashboardConfigurationRequestModel model)
        {
            ApiDashboardConfigurationRequestModel request = await this.PatchModel(id, this.DashboardConfigurationModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiDashboardConfigurationResponseModel> result = await this.DashboardConfigurationService.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 <ApiDashboardConfigurationRequestModel> patch)
        {
            ApiDashboardConfigurationResponseModel record = await this.DashboardConfigurationService.Get(id);

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

                UpdateResponse <ApiDashboardConfigurationResponseModel> result = await this.DashboardConfigurationService.Update(id, model);

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