예제 #1
0
        public void apply_to_should_add_expand_parameter_description(string name)
        {
            // arrange
            var dollarPrefix       = name[0] == '$';
            var description        = NewApiDescription();
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions = Expand
            };
            var settings   = new TestODataQueryOptionSettings(typeof(string), dollarPrefix);
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Single().Should().BeEquivalentTo(
                new
            {
                Name                = name,
                Source              = Query,
                Type                = typeof(string),
                DefaultValue        = default(object),
                IsRequired          = false,
                ModelMetadata       = new { Description = "Test" },
                ParameterDescriptor = new
                {
                    Name          = name,
                    ParameterType = typeof(string),
                },
            },
                options => options.ExcludingMissingMembers());
            settings.MockDescriptionProvider.Verify(p => p.Describe(Expand, It.IsAny <ODataQueryOptionDescriptionContext>()), Once());
        }
예제 #2
0
        public void apply_to_should_use_default_query_settings()
        {
            // arrange
            var description          = NewApiDescription();
            var defaultQuerySettings = new DefaultQuerySettings()
            {
                EnableCount   = true,
                EnableExpand  = true,
                EnableFilter  = true,
                EnableOrderBy = true,
                EnableSelect  = true,
            };
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions = AllowedQueryOptions.None
            };
            var settings   = new TestODataQueryOptionSettings(typeof(object), defaultQuerySettings);
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Count.Should().Be(5);
        }
        public void apply_to_should_add_filter_parameter_description(string name)
        {
            // arrange
            var dollarPrefix       = name[0] == '$';
            var description        = NewApiDescription();
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions = Filter
            };
            var settings   = new TestODataQueryOptionSettings(dollarPrefix);
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Single().Should().BeEquivalentTo(
                new
            {
                Name                = name,
                Documentation       = "Test",
                Source              = FromUri,
                ParameterDescriptor = new
                {
                    ParameterName = name,
                    ParameterType = typeof(string),
                    Prefix        = "$",
                    IsOptional    = true,
                    DefaultValue  = default(object),
                }
            },
                options => options.ExcludingMissingMembers());
            settings.MockDescriptionProvider.Verify(p => p.Describe(Filter, It.IsAny <ODataQueryOptionDescriptionContext>()), Once());
        }
예제 #4
0
        public void apply_to_should_ignore_nonquery_and_nonaction_descriptions(string httpMethod)
        {
            // arrange
            var description        = NewApiDescription(httpMethod);
            var validationSettings = new ODataValidationSettings();
            var settings           = new TestODataQueryOptionSettings(typeof(object));
            var convention         = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Should().BeEmpty();
        }
        public void apply_to_should_use_default_query_settings()
        {
            // arrange
            var description        = NewApiDescription();
            var configuration      = description.ActionDescriptor.Configuration;
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions = AllowedQueryOptions.None
            };
            var settings   = new TestODataQueryOptionSettings();
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            configuration.Count().Expand().Filter().OrderBy().Select();

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Count.Should().Be(5);
        }
예제 #6
0
        public void apply_to_should_use_model_bound_query_attributes()
        {
            // arrange
            var builder = new ODataConventionModelBuilder().EnableLowerCamelCase();

            builder.EntitySet <Order>("Orders");

            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions        = AllowedQueryOptions.None,
                AllowedArithmeticOperators = AllowedArithmeticOperators.None,
                AllowedLogicalOperators    = AllowedLogicalOperators.None,
                AllowedFunctions           = AllowedFunctions.None,
            };
            var settings    = new TestODataQueryOptionSettings(typeof(Order));
            var convention  = new ODataValidationSettingsConvention(validationSettings, settings);
            var model       = builder.GetEdmModel();
            var description = NewApiDescription(typeof(OrdersController), typeof(IEnumerable <Order>), model);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    Name                = "$select",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$select",
                        ParameterType = typeof(string),
                    },
                },
                new
                {
                    Name                = "$filter",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$filter",
                        ParameterType = typeof(string),
                    },
                },
                new
                {
                    Name                = "$orderby",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$orderby",
                        ParameterType = typeof(string),
                    },
                },
                new
                {
                    Name                = "$count",
                    Source              = Query,
                    Type                = typeof(bool),
                    DefaultValue        = (object)false,
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$count",
                        ParameterType = typeof(bool),
                    },
                },
            },
                options => options.ExcludingMissingMembers());
        }
예제 #7
0
        public void apply_to_should_use_enable_query_attribute(ApiDescription description)
        {
            // arrange
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions        = AllowedQueryOptions.None,
                AllowedArithmeticOperators = AllowedArithmeticOperators.None,
                AllowedLogicalOperators    = AllowedLogicalOperators.None,
                AllowedFunctions           = AllowedFunctions.None,
            };
            var settings   = new TestODataQueryOptionSettings(typeof(IEnumerable <object>));
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    Name                = "$select",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$select",
                        ParameterType = typeof(string),
                    },
                },
                new
                {
                    Name                = "$expand",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$expand",
                        ParameterType = typeof(string),
                    },
                },
                new
                {
                    Name                = "$filter",
                    Source              = Query,
                    Type                = typeof(string),
                    DefaultValue        = default(object),
                    IsRequired          = false,
                    ModelMetadata       = new { Description = "Test" },
                    ParameterDescriptor = new
                    {
                        Name          = "$filter",
                        ParameterType = typeof(string),
                    },
                },
            },
                options => options.ExcludingMissingMembers());
        }
        public void apply_to_should_use_enable_query_attribute(ApiDescription description)
        {
            // arrange
            var validationSettings = new ODataValidationSettings()
            {
                AllowedQueryOptions        = AllowedQueryOptions.None,
                AllowedArithmeticOperators = AllowedArithmeticOperators.None,
                AllowedLogicalOperators    = AllowedLogicalOperators.None,
                AllowedFunctions           = AllowedFunctions.None,
            };
            var settings   = new TestODataQueryOptionSettings();
            var convention = new ODataValidationSettingsConvention(validationSettings, settings);

            // act
            convention.ApplyTo(description);

            // assert
            description.ParameterDescriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    Name                = "$select",
                    Documentation       = "Test",
                    Source              = FromUri,
                    ParameterDescriptor = new
                    {
                        ParameterName = "$select",
                        ParameterType = typeof(string),
                        Prefix        = "$",
                        IsOptional    = true,
                        DefaultValue  = default(object),
                    }
                },
                new
                {
                    Name                = "$expand",
                    Documentation       = "Test",
                    Source              = FromUri,
                    ParameterDescriptor = new
                    {
                        ParameterName = "$expand",
                        ParameterType = typeof(string),
                        Prefix        = "$",
                        IsOptional    = true,
                        DefaultValue  = default(object),
                    }
                },
                new
                {
                    Name                = "$filter",
                    Documentation       = "Test",
                    Source              = FromUri,
                    ParameterDescriptor = new
                    {
                        ParameterName = "$filter",
                        ParameterType = typeof(string),
                        Prefix        = "$",
                        IsOptional    = true,
                        DefaultValue  = default(object),
                    }
                },
            },
                options => options.ExcludingMissingMembers());
        }