Ejemplo n.º 1
0
        public void Single_Property_With_Null_Final_Value_Should_Return_Correct_Chain()
        {
            var source = new
            {
                Foo = 1,
                Bar = (object)null,
            };

            var expected = new[]
            {
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.Valid,
                    Object       = source,
                    PropertyName = "Bar",
                },
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.FinalValue,
                    Object       = null,
                    PropertyName = null,
                },
            };

            PropertyPathParser target = new PropertyPathParser();

            PropertyPathToken[] result = target.Parse(source, "Bar").ToArray();

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 2
0
        public void Parse_ValidPath_IsParsedCorrect(string path)
        {
            var parser     = new PropertyPathParser();
            var parsedPath = parser.Parse(path);

            Assert.AreEqual(path, parsedPath.ToString());
        }
Ejemplo n.º 3
0
        public void When_PropertyPath_Is_A_Reference_Object_Without_Chain()
        {
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null,"Category")).WithExactArguments().WillReturn(associationMemberInfo);
            var propertyPathParser = new PropertyPathParser(null);
            CriteriaOperator criteriaOperator = propertyPathParser.Parse("Category","SomeProperty=50");

            Assert.AreEqual(new BinaryOperator("Category.SomeProperty",50).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 4
0
        public void Parse_InValidPath_ThrowsFormatException(string path)
        {
            var parser = new PropertyPathParser();

            Assert.Throws <FormatException>(() =>
            {
                parser.Parse(path);
            });
        }
Ejemplo n.º 5
0
        public void ControlChar2()
        {
            string text = "(";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.ControlChar, "(")
                           );
        }
Ejemplo n.º 6
0
        public void AttachedPropertyTest()
        {
            string text = "(ownerType.propertyName)";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "ownerType.propertyName")
                           );
        }
Ejemplo n.º 7
0
        public void MultipleIndexerTest()
        {
            string text = "[index1,index2]";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.Indexer, "index1,index2")
                           );
        }
Ejemplo n.º 8
0
        public void When_PropertyPath_Is_A_Reference_Object_Without_Chain()
        {
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Category")).WithExactArguments().WillReturn(associationMemberInfo);
            var propertyPathParser            = new PropertyPathParser(null, Session.DefaultSession);
            CriteriaOperator criteriaOperator = propertyPathParser.Parse("Category", "SomeProperty=50");

            Assert.AreEqual(new BinaryOperator("Category.SomeProperty", 50).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 9
0
        public void When_PropertyPath_Is_A_Collection_Without_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null,"Orders")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null);

            CriteriaOperator criteriaOperator= parser.Parse("Orders", "Amount=50");

            Assert.AreEqual("[Orders][[Amount] = 50]", criteriaOperator.ToString());
        }
Ejemplo n.º 10
0
        public void SourceTraversalTest()
        {
            string text = "propertyName/propertyNameX";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.SourceTraversal, "propertyName/propertyNameX")
                           );
        }
Ejemplo n.º 11
0
        public void SimpleIndexerTest()
        {
            string text = "[key]";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.Indexer, "key")
                           );
        }
Ejemplo n.º 12
0
        public void SimplePropertyTest()
        {
            string text = "Test";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "Test")
                           );
        }
Ejemplo n.º 13
0
        public void When_Parameter_Is_A_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Customers")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Customers", "Order.OrderLine.Ammount=50");

            Assert.AreEqual(new ContainsOperator("Customers", new BinaryOperator("Order.OrderLine.Ammount", 50)).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 14
0
        public void When_PropertyPath_Is_A_Collection_Without_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Orders")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Orders", "Amount=50");

            Assert.AreEqual("[Orders][[Amount] = 50]", criteriaOperator.ToString());
        }
Ejemplo n.º 15
0
        public void ComplexTest2()
        {
            string text = "(TextBlock.Background).(SolidColorBrush.Color)";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "TextBlock.Background"),
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "SolidColorBrush.Color")
                           );
        }
Ejemplo n.º 16
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Reference_Object_In_Chain()
        {   
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null,"Order")).WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null, "Order.OrderLine")).WillReturn(associationMemberInfo);
            var parser = new PropertyPathParser(null);

            CriteriaOperator criteriaOperator = parser.Parse("Order.OrderLine", "Amount=50");

            Assert.AreEqual(new BinaryOperator("Order.OrderLine.Amount", 50).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 17
0
        public void ControlChar3()
        {
            string text = "test[";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "test"),
                           new PropertyPathSegment(SegmentKind.ControlChar, "[")
                           );
        }
Ejemplo n.º 18
0
        public void ControlChar4()
        {
            string text = "(testType.";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "(testType"),
                           new PropertyPathSegment(SegmentKind.ControlChar, ".")
                           );
        }
Ejemplo n.º 19
0
        public void TwoPartsTest()
        {
            string text = "propertyName.propertyName2";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "propertyName"),
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "propertyName2")
                           );
        }
Ejemplo n.º 20
0
        public void MixedTest1()
        {
            string text = "(testType.prop).(someType.as";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "testType.prop"),
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "(someType.as")
                           );
        }
Ejemplo n.º 21
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Reference_Object_In_Chain()
        {
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order")).WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order.OrderLine")).WillReturn(associationMemberInfo);
            var parser = new PropertyPathParser(null, Session.DefaultSession);

            CriteriaOperator criteriaOperator = parser.Parse("Order.OrderLine", "Amount=50");

            Assert.AreEqual(new BinaryOperator("Order.OrderLine.Amount", 50).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 22
0
        public void ComplexTest()
        {
            string text = "ColorGrid[20,30].SolidColorBrushResult";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "ColorGrid"),
                           new PropertyPathSegment(SegmentKind.Indexer, "20,30"),
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "SolidColorBrushResult")
                           );
        }
Ejemplo n.º 23
0
        public void ControlChar1()
        {
            string text = "propertyName.propertyName2[index].";

            PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray();

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "propertyName"),
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "propertyName2"),
                           new PropertyPathSegment(SegmentKind.Indexer, "index"),
                           new PropertyPathSegment(SegmentKind.ControlChar, ".")
                           );
        }
Ejemplo n.º 24
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Collection_In_Chain()
        {
            XPMemberInfo collectionMemberInfo  = GetCollectionMemberInfo();
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();

            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order")).WithExactArguments().WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => XpandReflectionHelper.GetXpMemberInfo(null, "Order.OrderLines")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null);

            CriteriaOperator criteriaOperator = parser.Parse("Order.OrderLines", "Ammount=50");

            Assert.AreEqual(new ContainsOperator("Order.OrderLines", new BinaryOperator("Ammount", 50)).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 25
0
        public void Multiple_Properties_With_Broken_Link_Should_Return_Correct_Chain()
        {
            var source = new
            {
                Foo = new
                {
                    Bar = new
                    {
                        Qux = 9,
                    }
                },
            };

            var expected = new[]
            {
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.Valid,
                    Object       = source,
                    PropertyName = "Foo",
                },
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.Valid,
                    Object       = source.Foo,
                    PropertyName = "Bar",
                },
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.Broken,
                    Object       = source.Foo.Bar,
                    PropertyName = "Baz",
                },
            };

            PropertyPathParser target = new PropertyPathParser();

            PropertyPathToken[] result = target.Parse(source, "Foo.Bar.Baz").ToArray();

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 26
0
        public void No_Property_Should_Return_Source_As_FinalValue()
        {
            var source = new
            {
                Foo = 1,
                Bar = 2,
            };

            var expected = new[]
            {
                new PropertyPathToken
                {
                    Type   = PropertyPathTokenType.FinalValue,
                    Object = source,
                }
            };

            PropertyPathParser target = new PropertyPathParser();

            PropertyPathToken[] result = target.Parse(source, "").ToArray();

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 27
0
        public void Single_Property_Broken_Sould_Return_Correct_Chain()
        {
            var source = new
            {
                Foo = 1,
                Bar = (object)null,
            };

            var expected = new[]
            {
                new PropertyPathToken
                {
                    Type         = PropertyPathTokenType.Broken,
                    Object       = source,
                    PropertyName = "Baz",
                },
            };

            PropertyPathParser target = new PropertyPathParser();

            PropertyPathToken[] result = target.Parse(source, "Baz").ToArray();

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 28
0
        public void When_PropertyPath_Is_A_Reference_Object_With_A_Collection_And_A_Collection_In_Chain()
        {
            XPMemberInfo collectionMemberInfo = GetCollectionMemberInfo();
            XPMemberInfo associationMemberInfo = GetAssociationMemberInfo();
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null, "Customer")).WithExactArguments().WillReturn(associationMemberInfo);
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null, "Customer.Orders")).WithExactArguments().WillReturn(collectionMemberInfo);
            Isolate.WhenCalled(() => ReflectorHelper.GetXpMemberInfo(null, "Customer.Orders.OrderLines")).WithExactArguments().WillReturn(collectionMemberInfo);
            var parser = new PropertyPathParser(null);

            CriteriaOperator criteriaOperator= parser.Parse("Customer.Orders.OrderLines", "Ammount=50");

            Assert.AreEqual(new ContainsOperator("Customer.Orders",new ContainsOperator("OrderLines",new BinaryOperator("Ammount",50))).ToString(), criteriaOperator.ToString());
        }
Ejemplo n.º 29
0
        public void No_Property_And_No_Source_Should_Throw_Exception()
        {
            PropertyPathParser target = new PropertyPathParser();

            PropertyPathToken[] result = target.Parse(null, "").ToArray();
        }