Beispiel #1
0
        /// <summary>
        /// Initialize a new instance of <see cref="TopQueryOption"/> based on the raw $top value and
        /// an EdmModel from <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="rawValue">The raw value for $top query. It can be null or empty.</param>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information</param>
        public TopQueryOption(string rawValue, ODataQueryContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (String.IsNullOrEmpty(rawValue))
            {
                throw Error.ArgumentNullOrEmpty("rawValue");
            }

            Context   = context;
            RawValue  = rawValue;
            Validator = new TopQueryValidator();
        }
Beispiel #2
0
        public void GetTopQueryValidator_Returns_Validator()
        {
            // Arrange & Act & Assert
            Assert.NotNull(TopQueryValidator.GetTopQueryValidator(null));

            // Arrange & Act & Assert
            ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, typeof(int));

            Assert.NotNull(TopQueryValidator.GetTopQueryValidator(context));

            // Arrange & Act & Assert
            IServiceProvider services = new ServiceCollection()
                                        .AddSingleton <TopQueryValidator>().BuildServiceProvider();

            context.RequestContainer = services;
            Assert.NotNull(TopQueryValidator.GetTopQueryValidator(context));
        }
Beispiel #3
0
        /// <summary>
        /// Initialize a new instance of <see cref="TopQueryOption"/> based on the raw $top value and
        /// an EdmModel from <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="rawValue">The raw value for $top query. It can be null or empty.</param>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information</param>
        /// <param name="queryOptionParser">The <see cref="ODataQueryOptionParser"/> which is used to parse the query option.</param>
        public TopQueryOption(string rawValue, ODataQueryContext context, ODataQueryOptionParser queryOptionParser)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (String.IsNullOrEmpty(rawValue))
            {
                throw Error.ArgumentNullOrEmpty("rawValue");
            }

            if (queryOptionParser == null)
            {
                throw Error.ArgumentNull("queryOptionParser");
            }

            Context            = context;
            RawValue           = rawValue;
            Validator          = TopQueryValidator.GetTopQueryValidator(context);
            _queryOptionParser = queryOptionParser;
        }
Beispiel #4
0
        // This constructor is intended for unit testing only.
        internal TopQueryOption(string rawValue, ODataQueryContext context)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (String.IsNullOrEmpty(rawValue))
            {
                throw Error.ArgumentNullOrEmpty("rawValue");
            }

            Context            = context;
            RawValue           = rawValue;
            Validator          = TopQueryValidator.GetTopQueryValidator(context);
            _queryOptionParser = new ODataQueryOptionParser(
                context.Model,
                context.ElementType,
                context.NavigationSource,
                new Dictionary <string, string> {
                { "$top", rawValue }
            });
        }
 public TopQueryValidatorTest()
 {
     _validator = new TopQueryValidator();
     _context   = ValidationTestHelper.CreateCustomerContext();
 }