Ejemplo n.º 1
0
        public async void CreateProjectDataModelProperty_ReturnsCreatedProjectDataModelProperty()
        {
            _projectDataModelService
            .Setup(s => s.AddDataModelProperty(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                               It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool?>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(1);

            _projectDataModelService.Setup(s => s.GetProjectDataModelPropertyByName(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((int projectDataModelId, string name, CancellationToken cancellationToken) =>
                          new ProjectDataModelProperty
            {
                Id   = 1,
                Name = name,
                ProjectDataModelId = projectDataModelId
            });

            var controller = new ProjectDataModelController(_projectDataModelService.Object, _mapper, _logger.Object);

            var dto = new CreateProjectDataModelPropertyDto
            {
                Name = "Title"
            };
            var result = await controller.CreateProjectDataModelProperty(1, 1, dto);

            var okActionResult = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue    = Assert.IsType <ProjectDataModelPropertyDto>(okActionResult.Value);

            Assert.Equal(1, returnValue.Id);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateProjectDataModelProperty(int projectId, int modelId, CreateProjectDataModelPropertyDto newProperty)
        {
            _logger.LogInformation("Creating property for data model {modelId} in project {projectId}. Request body: {@newProperty}", modelId, projectId, newProperty);

            try
            {
                var propertyId = await _projectDataModelService.AddDataModelProperty(modelId,
                                                                                     newProperty.Name,
                                                                                     newProperty.Label,
                                                                                     newProperty.DataType,
                                                                                     newProperty.ControlType,
                                                                                     newProperty.IsRequired,
                                                                                     newProperty.RelatedProjectDataModelId,
                                                                                     newProperty.RelationalType,
                                                                                     newProperty.IsManaged);

                var property = await _projectDataModelService.GetProjectDataModelPropertyByName(modelId, newProperty.Name);

                var result = _mapper.Map <ProjectDataModelPropertyDto>(property);

                return(CreatedAtRoute("GetProjectDataModelPropertyById", new
                {
                    projectId,
                    modelId,
                    propertyId
                }, result));
            }
            catch (DuplicateProjectDataModelPropertyException dupEx)
            {
                _logger.LogWarning(dupEx, "Duplicate property name");
                return(BadRequest(dupEx.Message));
            }
            catch (ProjectDataModelNotFoundException modEx)
            {
                _logger.LogWarning(modEx, "Project data model not found");
                return(BadRequest(modEx.Message));
            }
        }
        public async Task <ProjectDataModelPropertyDto> CreateProjectDataModelProperty(int projectId, int modelId, CreateProjectDataModelPropertyDto dto)
        {
            var path = $"project/{projectId}/model/{modelId}/property";

            return(await Api.Post <CreateProjectDataModelPropertyDto, ProjectDataModelPropertyDto>(path, dto));
        }