public async Task <IActionResult> GetRelationshipBySpecificationIdAndName(HttpRequest request)
        {
            request.Query.TryGetValue("specificationId", out Microsoft.Extensions.Primitives.StringValues specId);

            string specificationId = specId.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(specificationId))
            {
                _logger.Error("The specification id was not provided to GetRelationshipsBySpecificationIdAndName");

                return(new BadRequestObjectResult("No specification id was provided to GetRelationshipsBySpecificationIdAndName"));
            }

            request.Query.TryGetValue("name", out Microsoft.Extensions.Primitives.StringValues name);

            string relationshipName = name.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(relationshipName))
            {
                _logger.Error("The name was not provided to GetRelationshipsBySpecificationIdAndName");

                return(new BadRequestObjectResult("No name was provided to GetRelationshipsBySpecificationIdAndName"));
            }

            DefinitionSpecificationRelationship relationship = await _datasetRepository.GetRelationshipBySpecificationIdAndName(specificationId, name);

            if (relationship != null)
            {
                return(new OkObjectResult(relationship));
            }

            return(new NotFoundResult());
        }
Exemple #2
0
        public async Task <IActionResult> GetRelationshipBySpecificationIdAndName(string specificationId, string name)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                _logger.Error("The specification id was not provided to GetRelationshipsBySpecificationIdAndName");

                return(new BadRequestObjectResult("No specification id was provided to GetRelationshipsBySpecificationIdAndName"));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                _logger.Error("The name was not provided to GetRelationshipsBySpecificationIdAndName");

                return(new BadRequestObjectResult("No name was provided to GetRelationshipsBySpecificationIdAndName"));
            }

            DefinitionSpecificationRelationship relationship = await _datasetRepository.GetRelationshipBySpecificationIdAndName(specificationId, name);

            if (relationship != null)
            {
                return(new OkObjectResult(relationship));
            }

            return(new NotFoundResult());
        }
        static IDatasetRepository CreateDatasetRepository(bool isValid = true)
        {
            IDatasetRepository repository = Substitute.For <IDatasetRepository>();

            repository
            .GetRelationshipBySpecificationIdAndName(Arg.Is("spec-id"), Arg.Is("test name"))
            .Returns(isValid ? (DefinitionSpecificationRelationship)null: new DefinitionSpecificationRelationship());

            return(repository);
        }
Exemple #4
0
        public CreateDefinitionSpecificationRelationshipModelValidator(IDatasetRepository datasetRepository)
        {
            _datasetRepository = datasetRepository;

            RuleFor(model => model.DatasetDefinitionId)
            .NotEmpty()
            .WithMessage("Missing dataset definition id.");

            RuleFor(model => model.SpecificationId)
            .NotEmpty()
            .WithMessage("Missing specification id.");

            RuleFor(model => model.Name)
            .Custom((name, context) => {
                CreateDefinitionSpecificationRelationshipModel relationshipModel = context.ParentContext.InstanceToValidate as CreateDefinitionSpecificationRelationshipModel;
                if (string.IsNullOrWhiteSpace(relationshipModel.Name))
                {
                    context.AddFailure("Missing name provided");
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(relationshipModel.SpecificationId))
                    {
                        DefinitionSpecificationRelationship relationship = _datasetRepository.GetRelationshipBySpecificationIdAndName(relationshipModel.SpecificationId, relationshipModel.Name).Result;

                        if (relationship != null)
                        {
                            context.AddFailure($"You must give a unique relationship name");
                        }
                    }
                }
            });

            RuleFor(model => model.Description)
            .NotEmpty()
            .WithMessage("Missing description provided.");
        }