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); }
public void Parse_ValidPath_IsParsedCorrect(string path) { var parser = new PropertyPathParser(); var parsedPath = parser.Parse(path); Assert.AreEqual(path, parsedPath.ToString()); }
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()); }
public void Parse_InValidPath_ThrowsFormatException(string path) { var parser = new PropertyPathParser(); Assert.Throws <FormatException>(() => { parser.Parse(path); }); }
public void ControlChar2() { string text = "("; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.ControlChar, "(") ); }
public void AttachedPropertyTest() { string text = "(ownerType.propertyName)"; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.AttachedProperty, "ownerType.propertyName") ); }
public void MultipleIndexerTest() { string text = "[index1,index2]"; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.Indexer, "index1,index2") ); }
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()); }
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()); }
public void SourceTraversalTest() { string text = "propertyName/propertyNameX"; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.SourceTraversal, "propertyName/propertyNameX") ); }
public void SimpleIndexerTest() { string text = "[key]"; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.Indexer, "key") ); }
public void SimplePropertyTest() { string text = "Test"; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.PropertyOrType, "Test") ); }
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()); }
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()); }
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") ); }
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()); }
public void ControlChar3() { string text = "test["; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.PropertyOrType, "test"), new PropertyPathSegment(SegmentKind.ControlChar, "[") ); }
public void ControlChar4() { string text = "(testType."; PropertyPathSegment[] result = PropertyPathParser.Parse(text).ToArray(); CompareResults(result, new PropertyPathSegment(SegmentKind.AttachedProperty, "(testType"), new PropertyPathSegment(SegmentKind.ControlChar, ".") ); }
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") ); }
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") ); }
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()); }
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") ); }
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, ".") ); }
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()); }
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); }
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); }
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); }
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()); }
public void No_Property_And_No_Source_Should_Throw_Exception() { PropertyPathParser target = new PropertyPathParser(); PropertyPathToken[] result = target.Parse(null, "").ToArray(); }