Exemplo n.º 1
0
        public void RejectNoArgumentsInQueryStringWhenExpected()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int_1", typeof(int), new FromQueryAttribute()),
                CreateArgument("argument_int_2", typeof(int), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("");

            var accepted = constraint.Accept(context);

            Assert.False(accepted);
        }
Exemplo n.º 2
0
        public void AcceptTwoArgumentsInDifferentOrder()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int_1", typeof(int), new FromQueryAttribute()),
                CreateArgument("argument_int_2", typeof(int), new FromQueryAttribute()),
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?argument_int_2=6&argument_int_1=4");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 3
0
        public void AcceptOverloadedActionWithoutQueryString()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("body_int", typeof(int), new FromBodyAttribute()),
                CreateArgument("body_string", typeof(string), new FromBodyAttribute()),
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 4
0
        public void AcceptNoArgumentsInQueryStringWhenNoneExpected()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>();

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 5
0
        public void RejectFromQueryArgumentWithWrongName()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int", typeof(int), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?wrong_name=3");

            var accepted = constraint.Accept(context);

            Assert.False(accepted);
        }
Exemplo n.º 6
0
        public void RejectMultiValueStringWithoutCollection()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_string", typeof(string), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?argument_string=abc&argument_string=def&argument_string=xyz");

            var accepted = constraint.Accept(context);

            Assert.False(accepted);
        }
Exemplo n.º 7
0
        public void AcceptMultiValueIntInCollection()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int", typeof(IEnumerable <int>), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?argument_int=1&argument_int=2&argument_int=3");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 8
0
        public void AcceptIntValueWhenStringExpected()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_string", typeof(string), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?argument_string=3");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 9
0
        public void RejectQueryStringArgumentWithoutBinderMetadata()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int", typeof(int), null)
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?argument_int=3");

            var accepted = constraint.Accept(context);

            Assert.False(accepted);
        }
Exemplo n.º 10
0
        public void AcceptArgumentWithDifferentCasingInQueryString()
        {
            var action = new ActionDescriptor();

            action.Parameters = new List <ParameterDescriptor>()
            {
                CreateArgument("argument_int", typeof(int), new FromQueryAttribute())
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();

            context.Candidates = new List <ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new[] { constraint })
            };
            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext     = CreateRouteContext("?ARGUMENT_INT=3");

            var accepted = constraint.Accept(context);

            Assert.True(accepted);
        }
Exemplo n.º 11
0
        public void Accept_AcceptsActionWithSatisfiedParameters()
        {
            // Arrange
            var action = new ActionDescriptor();
            action.Parameters = new List<ParameterDescriptor>()
            {
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "id",
                    ParameterType = typeof(int),
                },
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "quantity",
                    ParameterType = typeof(int),
                },
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();
            context.Candidates = new List<ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new [] { constraint }),
            };

            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext = CreateRouteContext("?quantity=5", new { id = 17 });

            // Act & Assert
            Assert.True(constraint.Accept(context));
        }
Exemplo n.º 12
0
        public void Accept_RejectsWorseMatch_OptionalParameter()
        {
            // Arrange
            var action1 = new ActionDescriptor();
            action1.Parameters = new List<ParameterDescriptor>()
            {
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "id",
                    ParameterType = typeof(int),
                },
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "quantity",
                    ParameterType = typeof(int),
                },
            };

            var optionalParameters = new HashSet<string>();
            optionalParameters.Add("quantity");
            action1.Properties.Add("OptionalParameters", optionalParameters);

            var action2 = new ActionDescriptor();
            action2.Parameters = new List<ParameterDescriptor>()
            {
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "id",
                    ParameterType = typeof(int),
                },
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "quantity",
                    ParameterType = typeof(int),
                },
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();
            context.Candidates = new List<ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action1, new [] { constraint }),
                new ActionSelectorCandidate(action2, new [] { constraint }),
            };

            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext = CreateRouteContext("?quantity=5", new { id = 17 });

            // Act & Assert
            Assert.False(constraint.Accept(context));
        }
Exemplo n.º 13
0
        public void Accept_RejectsActionMatchWithMissingParameter()
        {
            // Arrange
            var action = new ActionDescriptor();
            action.Parameters = new List<ParameterDescriptor>()
            {
                new ParameterDescriptor()
                {
                    BindingInfo = new BindingInfo()
                    {
                      BindingSource = (new FromUriAttribute()).BindingSource,
                    },
                    Name = "id",
                    ParameterType = typeof(int),
                },
            };

            var constraint = new OverloadActionConstraint();

            var context = new ActionConstraintContext();
            context.Candidates = new List<ActionSelectorCandidate>()
            {
                new ActionSelectorCandidate(action, new [] { constraint }),
            };

            context.CurrentCandidate = context.Candidates[0];
            context.RouteContext = CreateRouteContext();

            // Act & Assert
            Assert.False(constraint.Accept(context));
        }