Пример #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);
        }
Пример #2
0
        public void Parse_ValidPath_IsParsedCorrect(string path)
        {
            var parser     = new PropertyPathParser();
            var parsedPath = parser.Parse(path);

            Assert.AreEqual(path, parsedPath.ToString());
        }
Пример #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());
        }
Пример #4
0
        public void Parse_InValidPath_ThrowsFormatException(string path)
        {
            var parser = new PropertyPathParser();

            Assert.Throws <FormatException>(() =>
            {
                parser.Parse(path);
            });
        }
Пример #5
0
        public void ControlChar2()
        {
            string text = "(";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.ControlChar, "(")
                           );
        }
Пример #6
0
        public void AttachedPropertyTest()
        {
            string text = "(ownerType.propertyName)";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.AttachedProperty, "ownerType.propertyName")
                           );
        }
Пример #7
0
        public void MultipleIndexerTest()
        {
            string text = "[index1,index2]";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.Indexer, "index1,index2")
                           );
        }
Пример #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());
        }
Пример #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());
        }
Пример #10
0
        public void SourceTraversalTest()
        {
            string text = "propertyName/propertyNameX";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.SourceTraversal, "propertyName/propertyNameX")
                           );
        }
Пример #11
0
        public void SimpleIndexerTest()
        {
            string text = "[key]";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.Indexer, "key")
                           );
        }
Пример #12
0
        public void SimplePropertyTest()
        {
            string text = "Test";

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

            CompareResults(result,
                           new PropertyPathSegment(SegmentKind.PropertyOrType, "Test")
                           );
        }
Пример #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());
        }
Пример #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());
        }
Пример #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")
                           );
        }
Пример #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());
        }
Пример #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, "[")
                           );
        }
Пример #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, ".")
                           );
        }
Пример #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")
                           );
        }
Пример #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")
                           );
        }
Пример #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());
        }
Пример #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")
                           );
        }
Пример #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, ".")
                           );
        }
Пример #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());
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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());
        }
Пример #29
0
        public void No_Property_And_No_Source_Should_Throw_Exception()
        {
            PropertyPathParser target = new PropertyPathParser();

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