public void ParsingPathWithStringConstantsTest() { var emptyResolver = new XamlTypeResolverMock(null); AssertPropertyPathes("S + \"1\" + \"0\"", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + \"local:MyClass.Property\" + \"0\"", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + \"'local:MyClass.Property'\" + \"0\"", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + \"'local:MyClass.Property\" + \"0\"", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + \"\" + \"0\"", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); //"5:5", "local:MyProp.Nested", "'sdfsdf'", "'", "", '' more more.. }
public void BadUseOfTernarOperator() { var analyzer = new PropertyPathAnalyzer(); var resolver = new XamlTypeResolverMock(null); var badPathes = new [] { "(Color>local:Colors.Enum?Color:Color", "(Color>local:Colors.Enum?Color: Color", "(Color>local:Colors.Enum?Color :Color", "(Color>local:Colors.Enum?local:Color.prop: Color", "(Color>local:Colors.Enum?local:Color.prop :Color", }; foreach (var path in badPathes) { try { analyzer.GetPathes(path, null); } catch (Exception e) { continue; } Assert.Fail("Exception must be thrown! Path = {0}", path); } }
public void InternatializationPathTokensTest() { var emptyResolver = new XamlTypeResolverMock(null); AssertPropertyPathes("1 > 0 ? local:propiedad.icône : local:Класс.中國.český", emptyResolver, true, new StaticPropertyPathToken(8, 28, "local", "propiedad", new[] { "icône" }), new StaticPropertyPathToken(32, 51, "local", "Класс", new[] { "中國", "český" }) ); }
public void ColorsTest() { var colorsResolver = new XamlTypeResolverMock(new Dictionary <string, Type> { { "colors:Colors", typeof(Colors) } }); AssertPropertyPathes("Enabled?colors:Colors.White : colors:Colors.Black", colorsResolver, false, new PropertyPathToken(0, 0, new [] { "Enabled" }), new StaticPropertyPathToken(0, 0, "colors", "Colors", new [] { "White" }), new StaticPropertyPathToken(0, 0, "colors", "Colors", new[] { "Black" })); }
public void EnumPropertyPathTokensTest() { var resolver = new XamlTypeResolverMock(new Dictionary <string, Type>() { { "local:Enum1", typeof(ExampleEnum1) }, { "local:Enum2", typeof(ExampleEnum2) }, }); AssertPropertyPathes("(1 > 0) ? local:MyClass.MyProp : local:MyClass.Prop", resolver, true, new StaticPropertyPathToken(10, 29, "local", "MyClass", new[] { "MyProp" }), new StaticPropertyPathToken(33, 50, "local", "MyClass", new[] { "Prop" }) ); }
public void ComplexTernarOperatorTest() { var resolver = new XamlTypeResolverMock(new Dictionary <string, Type>() { { "local:Enum1", typeof(ExampleEnum1) }, { "local:Enum2", typeof(ExampleEnum2) }, }); AssertPropertyPathes("(1 > 0) ? local:MyClass.MyProp : local:MyClass.Prop", resolver, true, new StaticPropertyPathToken(10, 29, "local", "MyClass", new[] { "MyProp" }), new StaticPropertyPathToken(33, 50, "local", "MyClass", new[] { "Prop" }) ); AssertPropertyPathes("1 > 0 ? MyProp : local:MyClass.Prop", resolver, true, new PropertyPathToken(8, 13, new[] { "MyProp" }), new StaticPropertyPathToken(17, 34, "local", "MyClass", new[] { "Prop" }) ); AssertPropertyPathes("1 > 0 ? Local : Prop", resolver, true, new PropertyPathToken(8, 12, new[] { "Local" }), new PropertyPathToken(16, 19, new[] { "Prop" }) ); AssertPropertyPathes("1 > 0 ? Local:Prop.P1 : P2", resolver, true, new StaticPropertyPathToken(8, 20, "Local", "Prop", new[] { "P1" }), new PropertyPathToken(24, 25, new [] { "P2" }) ); AssertPropertyPathes("1 > 0 ? (5+Local:Prop.P1): P2", resolver, true, new StaticPropertyPathToken(11, 23, "Local", "Prop", new[] { "P1" }), new PropertyPathToken(27, 28, new[] { "P2" }) ); AssertPropertyPathes("1 > 0 ? (\"5\"+Local:Prop.P1): P2", resolver, true, new StaticPropertyPathToken(13, 25, "Local", "Prop", new[] { "P1" }), new PropertyPathToken(29, 30, new[] { "P2" }) ); AssertPropertyPathes("1 > 0 ? (Local1:Class2.P4+Local:Prop.P1) : P2", resolver, true, new StaticPropertyPathToken(9, 24, "Local1", "Class2", new[] { "P4" }), new StaticPropertyPathToken(26, 38, "Local", "Prop", new[] { "P1" }), new PropertyPathToken(43, 44, new[] { "P2" }) ); AssertPropertyPathes("1 > 0 ? local:Enum1.Prop1 : local:Enum2.Prop2", resolver, true, new EnumToken(8, 24, "local", typeof(ExampleEnum1), "Prop1"), new EnumToken(28, 44, "local", typeof(ExampleEnum2), "Prop2") ); }
public void ParsingPathWithCharConstantsTest() { var emptyResolver = new XamlTypeResolverMock(null); AssertPropertyPathes("S + '1' + '0'", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + ''", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); AssertPropertyPathes("S + '\"'", emptyResolver, true, new PropertyPathToken(0, 0, new[] { "S" }) ); }