コード例 #1
0
        public void BuildFilter_AliasInFunction_WithoutValue()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=Fully.Qualified.Namespace.HasDog(inOffice%3D%40p1%2Cname%3D%40p2)");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Filter.Expression.ShouldBeSingleValueFunctionCallQueryNode(HardCodedTestModel.GetHasDogOverloadForPeopleWithThreeParameters().As <IEdmFunction>()).And.Parameters.Last().As <NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p2", null);
            aliasNodes["@p1"].Should().BeNull();
            aliasNodes["@p2"].Should().BeNull();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #2
0
        public void BuildFilter_AliasInFunction_enum_undefined()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=null%20ne%20Fully.Qualified.Namespace.GetPetCount(colorPattern%3D%40p1)&@p1=Fully.Qualified.Namespace.ColorPattern'238563'");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            NamedFunctionParameterNode p = odataUri.Filter.Expression.As <BinaryOperatorNode>().Right.As <SingleEntityFunctionCallNode>().Parameters.First().As <NamedFunctionParameterNode>();

            p.Value.As <ParameterAliasNode>().Alias.ShouldBeEquivalentTo("@p1");
            p.Value.As <ParameterAliasNode>().TypeReference.IsEnum().Should().Be(true);
            p.Value.As <ParameterAliasNode>().TypeReference.Definition.FullTypeName().ShouldBeEquivalentTo("Fully.Qualified.Namespace.ColorPattern");

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            aliasNodes["@p1"].As <ConstantNode>().Value.As <ODataEnumValue>().TypeName.Should().Be("Fully.Qualified.Namespace.ColorPattern");
            aliasNodes["@p1"].As <ConstantNode>().Value.As <ODataEnumValue>().Value.Should().Be("238563");
            aliasNodes["@p1"].TypeReference.IsEnum().Should().Be(true);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(fullUri, actualUri);
        }
コード例 #3
0
        public void BuildFilter_AliasInFunction_PropertyAsValue_TypeMismatch()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=Fully.Qualified.Namespace.HasDog(inOffice%3D%40p1%2Cname%3D%40p1)&@p2=Name&@p1=%40p2");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Filter.Expression.ShouldBeSingleValueFunctionCallQueryNode(HardCodedTestModel.GetHasDogOverloadForPeopleWithThreeParameters().As <IEdmFunction>()).And.Parameters.Last().As <NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetString(true));
            aliasNodes["@p1"].ShouldBeParameterAliasNode("@p2", EdmCoreModel.Instance.GetString(true));
            aliasNodes["@p2"].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPeopleSet().EntityType().FindProperty("Name"));

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(fullUri, actualUri);
        }
コード例 #4
0
        public void BuildOrderby_AliasInFunction()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$orderby=Fully.Qualified.Namespace.HasDog(inOffice%3D%40p1)&@p1=true");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;
            var expectedFunc = HardCodedTestModel.GetAllHasDogFunctionOverloadsForPeople().Single(s => s.Parameters.Count() == 2);

            odataUri.OrderBy.Expression.ShouldBeSingleValueFunctionCallQueryNode(expectedFunc).And.Parameters.Last().As <NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetBoolean(false));
            aliasNodes["@p1"].ShouldBeConstantQueryNode(true);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #5
0
        public void BuildFilter_AliasInFunction_BuiltIn()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=contains(%40p1%2CName)&@p1=Name");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Filter.Expression.As <SingleValueFunctionCallNode>().Parameters.First().ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetString(true));
            aliasNodes["@p1"].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPeopleSet().EntityType().FindProperty("Name"));

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #6
0
        public void BuildExpandOrderby_AliasInFunction()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$expand=MyPet2Set($orderby=concat(Color, @p1 )asc )&@p1='abc'");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;
            SingleValueFunctionCallNode           node       = (odataUri.SelectAndExpand.SelectedItems.First() as ExpandedNavigationSelectItem).OrderByOption.Expression as SingleValueFunctionCallNode;

            node.Parameters.Last().ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetString(true));
            aliasNodes["@p1"].ShouldBeConstantQueryNode("abc");

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(odataUriParser.UrlConventions, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal("http://gobbledygook/People?$expand=" + Uri.EscapeDataString("MyPet2Set($orderby=concat(Color,@p1))") + "&@p1=" + Uri.EscapeDataString("'abc'"), actualUri.OriginalString);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal("http://gobbledygook/People?$expand=" + Uri.EscapeDataString("MyPet2Set($orderby=concat(Color,@p1))") + "&@p1=" + Uri.EscapeDataString("'abc'"), actualUri.OriginalString);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal("http://gobbledygook/People?$expand=" + Uri.EscapeDataString("MyPet2Set($orderby=concat(Color,@p1))") + "&@p1=" + Uri.EscapeDataString("'abc'"), actualUri.OriginalString);
        }
コード例 #7
0
        public void BuildOrderby_AliasInBinaryOp()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$orderby=ID%20mul%20%40p1%20asc&@p1=3 div 2");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.OrderBy.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Multiply).And.Right.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetInt32(false));
            aliasNodes["@p1"].ShouldBeBinaryOperatorNode(BinaryOperatorKind.Divide).And.Right.ShouldBeConstantQueryNode(2);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(odataUriParser.UrlConventions, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(new Uri("http://gobbledygook/People?$orderby=ID%20mul%20%40p1&@p1=3 div 2"), actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(new Uri("http://gobbledygook/People?$orderby=ID%20mul%20%40p1&@p1=3 div 2"), actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(new Uri("http://gobbledygook/People?$orderby=ID%20mul%20%40p1&@p1=3 div 2"), actualUri);
        }
コード例 #8
0
        public void BuildPath_AliasInFunctionImport_enum()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/GetPetCount(colorPattern=@p1)?@p1=Fully.Qualified.Namespace.ColorPattern'BlueYellowStriped'");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();
            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            OperationSegmentParameter p = odataUri.Path.LastSegment.ShouldBeOperationImportSegment(HardCodedTestModel.GetFunctionImportForGetPetCount()).And.Parameters.First();

            p.Name.Should().Be("colorPattern");
            p.Value.As <ParameterAliasNode>().Alias.Should().Be("@p1");
            p.Value.As <ParameterAliasNode>().TypeReference.IsEnum().Should().Be(true);
            p.Value.As <ParameterAliasNode>().TypeReference.Definition.FullTypeName().ShouldBeEquivalentTo("Fully.Qualified.Namespace.ColorPattern");
            aliasNodes["@p1"].As <ConstantNode>().Value.As <ODataEnumValue>().TypeName.Should().Be("Fully.Qualified.Namespace.ColorPattern");
            aliasNodes["@p1"].As <ConstantNode>().Value.As <ODataEnumValue>().Value.Should().Be("22");
            aliasNodes["@p1"].TypeReference.IsEnum().Should().Be(true);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #9
0
        public void BuildPath_AliasInPath_AliasInFunction()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/GetPet4(id=@p1)?$filter=ID%20eq%20%40p1&@p1=1.01M");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Path.LastSegment.ShouldBeOperationImportSegment(HardCodedTestModel.GetFunctionImportForGetPet4()).And.Parameters.First().ShouldHaveParameterAliasNode("id", "@p1", EdmCoreModel.Instance.GetDecimal(false));
            odataUri.Filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And.Right.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetDecimal(false));
            aliasNodes["@p1"].ShouldBeConstantQueryNode(1.01M);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #10
0
        public void BuildPath_AliasInFunctionImport_NullAsValue()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/GetPet4(id=@p1)?@p1=null");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Path.LastSegment.ShouldBeOperationImportSegment(HardCodedTestModel.GetFunctionImportForGetPet4()).And.Parameters.First().ShouldHaveParameterAliasNode("id", "@p1", null);
            aliasNodes["@p1"].ShouldBeConstantQueryNode((object)null);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #11
0
        public void BuildPath_AliasInBoundFunction()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People(123)/Fully.Qualified.Namespace.HasHat(onCat=@p1)?@p1=true");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Path.LastSegment.ShouldBeOperationSegment(HardCodedTestModel.TestModel.FindOperations("Fully.Qualified.Namespace.HasHat").Single(s => (s as IEdmFunction).Parameters.Count() == 2)).As <IEdmFunction>();
            aliasNodes["@p1"].ShouldBeConstantQueryNode(true);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.NotEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);

            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.Equal(fullUri, actualUri);
        }
コード例 #12
0
        public void ODataUriBuilderWithKeyAsSegment()
        {
            Uri            fullUri        = new Uri("http://www.example.com/People/1?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID&$expand=MyDog&$top=1&$skip=2&$count=false");
            ODataUriParser oDataUriParser = new ODataUriParser(this.GetModel(), serviceRoot, fullUri);

            oDataUriParser.UrlConventions = ODataUrlConventions.KeyAsSegment;
            SetODataUriParserSettingsTo(this.settings, oDataUriParser.Settings);
            ODataUri odataUri = oDataUriParser.ParseUri();

            //verify path
            EntitySetSegment entitySet  = (EntitySetSegment)odataUri.Path.FirstSegment;
            KeySegment       keySegment = (KeySegment)odataUri.Path.LastSegment;
            IEnumerable <KeyValuePair <string, object> > keyValuePairs = keySegment.Keys;

            Assert.AreEqual(odataUri.Path.Count, 2);
            Assert.AreEqual(entitySet.EntitySet.Name, "People");
            foreach (var keyValuePair in keyValuePairs)
            {
                Assert.AreEqual(keyValuePair.Key, "ID");
                Assert.AreEqual(keyValuePair.Value, 1);
            }

            //verify $filter
            BinaryOperatorNode            binaryOperator      = (BinaryOperatorNode)odataUri.Filter.Expression;
            SingleValuePropertyAccessNode singleValueProperty = (SingleValuePropertyAccessNode)binaryOperator.Left;
            SingleNavigationNode          singleNavigation    = (SingleNavigationNode)singleValueProperty.Source;
            ConstantNode constantNode = (ConstantNode)binaryOperator.Right;

            Assert.AreEqual(binaryOperator.OperatorKind, BinaryOperatorKind.Equal);
            Assert.AreEqual(singleValueProperty.Property.Name, "Color");
            Assert.AreEqual(singleNavigation.NavigationProperty.Name, "MyDog");
            Assert.AreEqual(constantNode.LiteralText, "'Brown'");

            //verify $select and $expand
            IEnumerable <SelectItem> selectItems = odataUri.SelectAndExpand.SelectedItems;

            foreach (ExpandedNavigationSelectItem selectItem in selectItems)
            {
                NavigationPropertySegment navigationProperty = (NavigationPropertySegment)selectItem.PathToNavigationProperty.FirstSegment;
                Assert.AreEqual(navigationProperty.NavigationProperty.Name, "MyDog");
                break;
            }

            //verify $top
            Assert.AreEqual(odataUri.Top, 1);

            //verify $skip
            Assert.AreEqual(odataUri.Skip, 2);

            //verify $count
            Assert.AreEqual(odataUri.QueryCount, false);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);
            Uri             actualUri = uriBuilderWithKeyAsSegment.BuildUri();

            Assert.AreEqual(new Uri("http://www.example.com/People/1?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog&$expand=MyDog&$top=1&$skip=2&$count=false"), actualUri);
        }
コード例 #13
0
        public static Uri UriBuilder(Uri queryUri, ODataUrlConventions urlConventions, ODataUriParserSettings settings)
        {
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, queryUri);

            odataUriParser.UrlConventions = urlConventions;
            ODataUri odataUri = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(urlConventions, odataUri);

            return(odataUriBuilder.BuildUri());
        }
コード例 #14
0
ファイル: PathBuilderTests.cs プロジェクト: sivethe/odata.net
        public void TrailingDollarSegmentIsIgnored()
        {
            Uri            queryUri       = new Uri("People/$", UriKind.Relative);
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("https://www.blah.org/OData/"), queryUri);
            ODataUri       odataUri       = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(new Uri("https://www.blah.org/OData/People"), actualUri);
        }
コード例 #15
0
ファイル: PathBuilderTests.cs プロジェクト: sivethe/odata.net
        public void BuildPathWithRelativeFullUri()
        {
            Uri            queryUri       = new Uri("Dogs", UriKind.Relative);
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://gobbldygook/service.svc"), queryUri);
            ODataUri       odataUri       = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(new Uri("http://gobbldygook/service.svc/Dogs"), actualUri);
        }
コード例 #16
0
ファイル: PathBuilderTests.cs プロジェクト: sivethe/odata.net
        public void UriOverloadSmokeTest()
        {
            Uri            queryUri       = new Uri("Dogs", UriKind.Relative);
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("https://www.tomatosoup.com:1234/OData/V3/"), queryUri);
            ODataUri       odataUri       = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.Equal(new Uri("https://www.tomatosoup.com:1234/OData/V3/Dogs"), actualUri);
        }
コード例 #17
0
ファイル: UriBuilderTests.cs プロジェクト: sivethe/odata.net
        public void RelativeUriBuildWithEmptyQueryOptions()
        {
            Uri            queryUri       = new Uri("People", UriKind.Relative);
            ODataUriParser odataUriParser = new ODataUriParser(this.GetModel(), queryUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(queryUri, actualUri);
        }
コード例 #18
0
ファイル: UriBuilderTests.cs プロジェクト: sivethe/odata.net
        public void AbsoluteUriBuildWithEmptyQueryOptions()
        {
            Uri            queryUri       = new Uri("http://www.example.com/People");
            ODataUriParser odataUriParser = new ODataUriParser(this.GetModel(), serviceRoot, queryUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(queryUri, actualUri);
        }
コード例 #19
0
        public void BuildUrlWithNewODataUri()
        {
            ODataUri uri = new ODataUri();

            uri.ServiceRoot = new Uri("http://gobbledygook/");
            uri.Skip        = 4;
            uri.Top         = 5;
            uri.Path        = new ODataPath(new EntitySetSegment(HardCodedTestModel.GetPeopleSet()));
            Assert.AreEqual(uri.ParameterAliasNodes.Count, 0);

            ODataUriBuilder builder = new ODataUriBuilder(ODataUrlConventions.Default, uri);
            Uri             res     = builder.BuildUri();

            Assert.AreEqual(new Uri("http://gobbledygook/People?$top=5&$skip=4"), res);
        }
コード例 #20
0
        public void BuildPathWithFunctionImport()
        {
            ODataUri odataUri = new ODataUri();

            odataUri.ServiceRoot = new Uri("http://gobbledygook/");
            IEdmOperationImport functionImport         = HardCodedTestModel.TestModel.EntityContainer.FindOperationImports("GetPet1").Single();
            IEdmEntitySetReferenceExpression reference = functionImport.EntitySet as IEdmEntitySetReferenceExpression;

            OperationSegmentParameter[] parameters = new OperationSegmentParameter[] { new OperationSegmentParameter("id", new ConstantNode(1, "1")) };
            odataUri.Path = new ODataPath(new OperationImportSegment(
                                              new IEdmOperationImport[] { functionImport },
                                              reference.ReferencedEntitySet,
                                              parameters));
            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actual          = odataUriBuilder.BuildUri();

            Assert.Equal(new Uri("http://gobbledygook/GetPet1(id=1)"), actual);
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: vksamal1990/ODataSamples
        private static void BuildNavigationWithAny()
        {
            // Request URI
            var requestUri              = new Uri("Students?$filter=StudentId gt 100", UriKind.Relative);
            var requestODataUri         = new ODataUriParser(SchoolModel.Model, requestUri).ParseUri();
            var requestFilterExpression = requestODataUri.Filter.Expression;

            // URI that contains additional condition
            var conditionUri        = new Uri("Students?$filter=Courses/any(c:c/Teacher/Education/Degrees/any(d:d/Category eq 'English Literature'))", UriKind.Relative);
            var conditionODataUri   = new ODataUriParser(SchoolModel.Model, conditionUri).ParseUri();
            var conditionExpression = conditionODataUri.Filter.Expression;

            // New $filter expression
            var newFilterExpression = new BinaryOperatorNode(BinaryOperatorKind.And, requestFilterExpression, conditionExpression);

            requestODataUri.Filter = new FilterClause(newFilterExpression, requestODataUri.Filter.RangeVariable);
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, requestODataUri);

            Console.WriteLine(builder.BuildUri());

            // http://host/Students?$filter=StudentId%20gt%20100%20and%20Courses%2Fany%28c%3Ac%2FTeacher%2FEducation%2FDegrees%2Fany%28d%3Ad%2FCategory%20eq%20%27English%20Literature%27%29%29
            // http://host/Students?$filter=StudentId gt 100 and Courses/any(c:c/Teacher/Education/Degrees/any(d:d/Category eq 'English Literature'))
        }
コード例 #22
0
        private static void BuildOrderBy()
        {
            var productTypeRef   = new EdmEntityTypeReference(V4Model.Product, false);
            var supplierProperty = (IEdmNavigationProperty)V4Model.Product.FindProperty("Supplier");
            var nameProperty     = V4Model.Supplier.FindProperty("Name");

            var topIt           = new EntityRangeVariable("$it", productTypeRef, V4Model.ProductsSet);
            var topItRef        = new EntityRangeVariableReferenceNode("$it", topIt);
            var supplierNavNode = new SingleNavigationNode(supplierProperty, topItRef);
            var nameNode        = new SingleValuePropertyAccessNode(supplierNavNode, nameProperty);

            var orderby  = new OrderByClause(null, nameNode, OrderByDirection.Ascending, topIt);
            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(V4Model.ProductsSet)),
                ServiceRoot = V4Root,
                OrderBy     = orderby
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/OData/OData.svc/Products?$orderby=Supplier%2FName
        }
コード例 #23
0
        public void BuildFilter_AliasInFunction()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=Fully.Qualified.Namespace.AllHaveDog(inOffice%3D%40p1)&@p1=true");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Filter.Expression.ShouldBeSingleValueFunctionCallQueryNode(HardCodedTestModel.GetFunctionForAllHaveDogWithTwoParameters()).And.Parameters.Last().As <NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetBoolean(false));
            aliasNodes["@p1"].ShouldBeConstantQueryNode(true);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(fullUri, actualUri);
        }
コード例 #24
0
        public void BuildFilter_AliasInBinaryOp_ValueAsExpression()
        {
            Uri            fullUri        = new Uri("http://gobbledygook/People?$filter=ID%20eq%20%40p1&@p1=1 add 2");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);

            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary <string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And.Right.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetInt32(false));
            aliasNodes["@p1"].ShouldBeBinaryOperatorNode(BinaryOperatorKind.Add).And.Right.ShouldBeConstantQueryNode(2);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(fullUri, actualUri);
        }
コード例 #25
0
        private static void BuildFilterWithBinaryOperator()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var friendsProp   = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var firstNameProp = TripPinModel.Person.FindProperty("FirstName");
            var lastNameProp  = TripPinModel.Person.FindProperty("LastName");

            var topIt          = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef       = new EntityRangeVariableReferenceNode("$it", topIt);
            var friendsNavNode = new CollectionNavigationNode(friendsProp, topItRef);
            var e0             = new EntityRangeVariable("e0", personTypeRef, friendsNavNode);
            var e0Ref          = new EntityRangeVariableReferenceNode("e0", e0);
            var fun1           = new SingleValueFunctionCallNode(
                "startswith",
                new QueryNode[]
            {
                new SingleValuePropertyAccessNode(e0Ref, firstNameProp),
                new ConstantNode("var1", "'var1'")
            },
                EdmCoreModel.Instance.GetBoolean(false));

            var friendsNavNode2 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1    = new EntityRangeVariable("e1", personTypeRef, friendsNavNode2);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);
            var fun2  = new SingleValueFunctionCallNode(
                "contains",
                new QueryNode[]
            {
                new SingleValuePropertyAccessNode(e1Ref, lastNameProp),
                new ConstantNode("var2", "'var2'")
            },
                EdmCoreModel.Instance.GetBoolean(false));

            // Actually $it also needed, but would not be used in UriBuilder, so omit it here.
            var any2 = new AnyNode(new Collection <RangeVariable> {
                e1
            }, e1)
            {
                Body   = fun2,
                Source = friendsNavNode2
            };

            var any1 = new AnyNode(new Collection <RangeVariable> {
                e0
            }, e0)
            {
                Body   = new BinaryOperatorNode(BinaryOperatorKind.And, fun1, any2),
                Source = friendsNavNode
            };

            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter      = new FilterClause(any1, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());

            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(
            // e0:startswith(e0%2FFirstName%2C'var1') and e0%2FFriends%2Fany(e1:contains(e1%2FLastName%2C'var2')))
        }
コード例 #26
0
ファイル: UriBuilderTests.cs プロジェクト: sivethe/odata.net
        public void ODataUriBuilderWithEntitySet()
        {
            Uri            fullUri        = new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID&$expand=MyDog%2CMyCat/$ref&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA");
            ODataUriParser odataUriParser = new ODataUriParser(this.GetModel(), serviceRoot, fullUri);

            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            ODataUri odataUri = odataUriParser.ParseUri();

            //verify path
            EntitySetSegment entitySet = (EntitySetSegment)odataUri.Path.FirstSegment;

            Assert.AreEqual(entitySet.EntitySet.Name, "People");
            Assert.AreEqual(odataUri.Path.Count, 1);

            //verify $filter
            BinaryOperatorNode            binaryOperator      = (BinaryOperatorNode)odataUri.Filter.Expression;
            SingleValuePropertyAccessNode singleValueProperty = (SingleValuePropertyAccessNode)binaryOperator.Left;
            SingleNavigationNode          singleNavigation    = (SingleNavigationNode)singleValueProperty.Source;
            ConstantNode constantNode = (ConstantNode)binaryOperator.Right;

            Assert.AreEqual(binaryOperator.OperatorKind, BinaryOperatorKind.Equal);
            Assert.AreEqual(singleValueProperty.Property.Name, "Color");
            Assert.AreEqual(singleNavigation.NavigationProperty.Name, "MyDog");
            Assert.AreEqual(constantNode.LiteralText, "'Brown'");

            //verify $select and $expand
            IEnumerable <SelectItem> selectItems = odataUri.SelectAndExpand.SelectedItems;
            IEnumerable <ExpandedNavigationSelectItem> expandedNavigationSelectItem = selectItems.Where(I => I.GetType() == typeof(ExpandedNavigationSelectItem)).OfType <ExpandedNavigationSelectItem>();
            IEnumerable <ExpandedReferenceSelectItem>  expandedReferenceSelectItem  = selectItems.Where(I => I.GetType() == typeof(ExpandedReferenceSelectItem)).OfType <ExpandedReferenceSelectItem>();
            IEnumerable <PathSelectItem> pathSelectItem = selectItems.Where(I => I.GetType() == typeof(PathSelectItem)).OfType <PathSelectItem>();

            Assert.AreEqual(expandedNavigationSelectItem.Count(), 1);
            Assert.AreEqual(expandedReferenceSelectItem.Count(), 1);
            Assert.AreEqual(pathSelectItem.Count(), 3);
            NavigationPropertySegment navigationProperty = (NavigationPropertySegment)expandedNavigationSelectItem.First().PathToNavigationProperty.FirstSegment;

            Assert.AreEqual(navigationProperty.NavigationProperty.Name, "MyDog");
            navigationProperty = (NavigationPropertySegment)expandedReferenceSelectItem.First().PathToNavigationProperty.FirstSegment;
            Assert.AreEqual(navigationProperty.NavigationProperty.Name, "MyCat");

            //verify $orderby
            SingleValuePropertyAccessNode orderby = (SingleValuePropertyAccessNode)odataUri.OrderBy.Expression;

            Assert.AreEqual(orderby.Property.Name, "ID");

            //verify $top
            Assert.AreEqual(odataUri.Top, 1);

            //verify $skip
            Assert.AreEqual(odataUri.Skip, 2);

            //verify $count
            Assert.AreEqual(odataUri.QueryCount, true);

            //verify $search
            SearchTermNode searchTermNode = (SearchTermNode)odataUri.Search.Expression;

            Assert.AreEqual(searchTermNode.Text, "FA");

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri             actualUri       = odataUriBuilder.BuildUri();

            Assert.AreEqual(new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog%2CMyCat&$expand=MyDog%2CMyCat%2F%24ref&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA"), actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);

            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog%2CMyCat&$expand=MyDog%2CMyCat%2F%24ref&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA"), actualUri);
        }
コード例 #27
0
        private static void BuildFilterWithNestedAny()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var tripTypeRef   = new EdmEntityTypeReference(TripPinModel.Trip, false);

            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var tripsProp   = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Trips");
            var budgetProp  = TripPinModel.Trip.FindProperty("Budget");

            var topIt    = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);

            var friendsNavNode0 = new CollectionNavigationNode(friendsProp, topItRef);
            var e0    = new EntityRangeVariable("e0", personTypeRef, friendsNavNode0);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);

            var friendsNavNode1 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1    = new EntityRangeVariable("e1", personTypeRef, friendsNavNode1);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);

            var tripNavNode = new CollectionNavigationNode(tripsProp, e1Ref);
            var e2          = new EntityRangeVariable("e2", tripTypeRef, friendsNavNode1);
            var e2Ref       = new EntityRangeVariableReferenceNode("e2", e2);

            var bugetNode = new SingleValuePropertyAccessNode(e2Ref, budgetProp);

            var gt = new BinaryOperatorNode(
                BinaryOperatorKind.GreaterThan,
                bugetNode,
                new ConstantNode(1200, "1200"));

            var any2 = new AnyNode(new Collection <RangeVariable> {
                e2
            }, e2)
            {
                Body = gt, Source = tripNavNode
            };
            var any1 = new AnyNode(new Collection <RangeVariable> {
                e1
            }, e1)
            {
                Body = any2, Source = friendsNavNode1
            };
            var any0 = new AnyNode(new Collection <RangeVariable> {
                e0
            }, e0)
            {
                Body = any1, Source = friendsNavNode0
            };


            var odataUri = new ODataUri
            {
                Path        = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter      = new FilterClause(any0, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);

            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(e0:e0%2FFriends%2Fany(e1:e1%2FTrips%2Fany(e2:e2%2FBudget gt 1200)))
        }