public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiLibraryVariableSetRequestModel model)
 {
     this.ContentTypeRules();
     this.JSONRules();
     this.NameRules();
     this.VariableSetIdRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #2
0
        private async Task <ApiLibraryVariableSetResponseModel> CreateRecord()
        {
            var model = new ApiLibraryVariableSetRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLLibraryVariableSetMapper();
            ApiLibraryVariableSetRequestModel model = new ApiLibraryVariableSetRequestModel();

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

            response.ContentType.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.VariableSetId.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiLibraryVariableSetRequestModel model)
        {
            CreateResponse <ApiLibraryVariableSetResponseModel> result = await this.LibraryVariableSetService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/LibraryVariableSets/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #5
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiLibraryVariableSetModelMapper();
            var model  = new ApiLibraryVariableSetResponseModel();

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

            response.ContentType.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.VariableSetId.Should().Be("A");
        }
        public virtual BOLibraryVariableSet MapModelToBO(
            string id,
            ApiLibraryVariableSetRequestModel model
            )
        {
            BOLibraryVariableSet boLibraryVariableSet = new BOLibraryVariableSet();

            boLibraryVariableSet.SetProperties(
                id,
                model.ContentType,
                model.JSON,
                model.Name,
                model.VariableSetId);
            return(boLibraryVariableSet);
        }
Beispiel #7
0
        public virtual async Task <CreateResponse <ApiLibraryVariableSetResponseModel> > Create(
            ApiLibraryVariableSetRequestModel model)
        {
            CreateResponse <ApiLibraryVariableSetResponseModel> response = new CreateResponse <ApiLibraryVariableSetResponseModel>(await this.libraryVariableSetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolLibraryVariableSetMapper.MapModelToBO(default(string), model);
                var record = await this.libraryVariableSetRepository.Create(this.dalLibraryVariableSetMapper.MapBOToEF(bo));

                response.SetRecord(this.bolLibraryVariableSetMapper.MapBOToModel(this.dalLibraryVariableSetMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiLibraryVariableSetRequestModel request = this.LibraryVariableSetModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Beispiel #9
0
        public void CreatePatch()
        {
            var mapper = new ApiLibraryVariableSetModelMapper();
            var model  = new ApiLibraryVariableSetRequestModel();

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

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

            patch.ApplyTo(response);
            response.ContentType.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.VariableSetId.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ILibraryVariableSetRepository>();
            var model = new ApiLibraryVariableSetRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <LibraryVariableSet>())).Returns(Task.FromResult(new LibraryVariableSet()));
            var service = new LibraryVariableSetService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.LibraryVariableSetModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLLibraryVariableSetMapperMock,
                                                        mock.DALMapperMockFactory.DALLibraryVariableSetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LibraryVariableSetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLibraryVariableSetRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <LibraryVariableSet>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILibraryVariableSetRepository>();
            var model = new ApiLibraryVariableSetRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new LibraryVariableSetService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.LibraryVariableSetModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLLibraryVariableSetMapperMock,
                                                        mock.DALMapperMockFactory.DALLibraryVariableSetMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.LibraryVariableSetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Beispiel #12
0
        public virtual async Task <UpdateResponse <ApiLibraryVariableSetResponseModel> > Update(
            string id,
            ApiLibraryVariableSetRequestModel model)
        {
            var validationResult = await this.libraryVariableSetModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolLibraryVariableSetMapper.MapModelToBO(id, model);
                await this.libraryVariableSetRepository.Update(this.dalLibraryVariableSetMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiLibraryVariableSetResponseModel>(this.bolLibraryVariableSetMapper.MapBOToModel(this.dalLibraryVariableSetMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiLibraryVariableSetResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(string id, [FromBody] ApiLibraryVariableSetRequestModel model)
        {
            ApiLibraryVariableSetRequestModel request = await this.PatchModel(id, this.LibraryVariableSetModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiLibraryVariableSetResponseModel> result = await this.LibraryVariableSetService.Update(id, model);

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