public void depth_and_position() { PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetContentPath("beta.xml")); Assert.Equal(ReadState.Initial, reader.ReadState); Assert.True(reader.Read()); Assert.Equal(0, reader.Depth); Assert.Equal(0, reader.Position); Assert.True(reader.Read()); Assert.Equal(1, reader.Depth); Assert.Equal(0, reader.Position); Assert.True(reader.Read()); Assert.Equal(1, reader.Depth); // d Assert.Equal(1, reader.Position); Assert.True(reader.Read()); Assert.Equal(1, reader.Depth); // a Assert.Equal(2, reader.Position); Assert.True(reader.Read()); Assert.Equal(2, reader.Depth); Assert.Equal(0, reader.Position); // a.a // 9 additional reads TestUtils.Times(() => reader.Read(), 9); Assert.False(reader.Read()); Assert.Equal(ReadState.EndOfFile, reader.ReadState); }
public void bind_template_primitive_types() { PropertyTreeReader pt = LoadContent("alpha.xml"); Assert.True(pt.Read()); var template = pt.Bind <Template <Alpha> >(); var a = new Alpha(); template.Apply(a); Assert.True(a.A); Assert.False(a.AA.HasValue); Assert.Equal(0, a.B); Assert.True(a.BB.HasValue); Assert.Equal(0, a.BB.Value); Assert.Equal('g', a.D); Assert.Equal(DateTime.Parse("3/30/2011 1:50 AM"), a.E); Assert.Equal(10.5000m, a.F); Assert.Equal(10.5, a.G); Assert.Equal(256, a.H); Assert.Equal(1024, a.I); Assert.Equal(102410241024, a.J); Assert.Equal(-120, a.K); Assert.Equal(float.NaN, a.L); Assert.Equal("Carbonfrost F5 Project", a.M); Assert.Equal(65535, a.N); Assert.True(6553620 == a.O); Assert.True(6553620655362 == a.P); Assert.Equal(new Uri("http://carbonfrost.com"), a.Q); Assert.Equal(TimeSpan.Parse("4.12:0:30.5"), a.R); Assert.Equal(new Guid("{BF972F0A-CB10-441B-9D25-3D6DEB9065D1}"), a.S); Assert.Equal(DateTimeOffset.Parse("4/1/2011 12:11:01 AM -04:00"), a.T); Assert.Equal(typeof(Glob), a.U); }
public void Read_should_handle_elided_property_trees() { PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetXmlReader("omicron-theta-2.xml")); // 6 Reads to get to the elision Assert.True(reader.Read()); // omicronTheta Assert.True(reader.Read()); // alpha Assert.True(reader.Read()); // id Assert.True(reader.Read()); // d Assert.True(reader.Read()); // e Assert.True(reader.Read()); // alpha Assert.True(reader.Read()); // beta Assert.True(reader.Read()); Assert.Equal("a", reader.Name); Assert.Null(reader.Value); Assert.Equal(PropertyNodeType.PropertyTree, reader.NodeType); Assert.True(reader.Read()); Assert.Equal("source", reader.Name); Assert.Equal("#alpha", reader.Value); Assert.Equal(PropertyNodeType.Property, reader.NodeType); Assert.True(reader.Read()); Assert.Equal("a", reader.Name); Assert.Equal(PropertyNodeType.EndPropertyTree, reader.NodeType); }
public void bind_builder_types() { // Demonstrates that the builder indirection can be used PropertyTreeReader pt = LoadContent("epsilon-builder.xml"); Assert.True(pt.Read()); Epsilon e = pt.Bind <Epsilon>(); Assert.True(e is EpsilonAlpha); Assert.Equal(256, e.A); Assert.Equal(TimeSpan.Parse("2.5:05:05.200"), e.B); Assert.Equal(2256.231250002, e.C); Assert.Equal(293680235, e.D); Assert.IsInstanceOf <EpsilonExtended>(e.E); EpsilonExtended f = (EpsilonExtended)e.E; Assert.Equal(1256, f.A); Assert.Equal(TimeSpan.Parse("12.5:05:05.200"), f.B); Assert.Equal(12256.231250002, f.C); Assert.Equal(1293680235, f.D); Assert.Equal(DateTime.Parse("2011-05-12 8:45AM"), f.F); }
public void bind_ordered_list() { // Binding of an ordered list IList<T> implementation PropertyTreeReader pt = LoadContent("delta.xml"); Assert.True(pt.Read()); Delta originalD = new Delta(); Delta d = pt.Bind(originalD); Assert.True(object.ReferenceEquals(d, originalD)); Assert.Equal(3, d.A.Count); Assert.True(d.A[0].A); Assert.Equal(0, d.A[0].B); Assert.Equal('g', d.A[0].D); Assert.Equal(DateTime.Parse("3/30/2011 1:50 AM"), d.A[0].E); Assert.Equal(10.5000m, d.A[1].F); Assert.Equal(10.5, d.A[1].G); Assert.Equal(256, d.A[1].H); Assert.Equal(1024, d.A[1].I); Assert.Equal("Carbonfrost F5 Project", d.A[2].M); Assert.Equal(new Uri("http://carbonfrost.com"), d.A[2].Q); Assert.Equal(TimeSpan.Parse("4.12:0:30.5"), d.A[2].R); Assert.Equal(new Guid("{ED826F6C-47B5-4C40-B5B1-E847CB193E03}"), d.A[2].S); Assert.Equal(10.5000m, d.B[0].A.F); Assert.Equal(10.5, d.B[0].A.G); // <add> is inherited, but still binds Assert.Equal("Carbonfrost F5 Project", d.C[0].M); }
public void bind_nondefault_constructors_complex() { // Demonstrates that an object with a nondefault constructor // can be populated with a complex object like Eta PropertyTreeReader pt = LoadContent("iota.xml"); Assert.True(pt.Read()); Iota i = pt.Bind <Iota>(); Assert.Equal(8256, i.A); Assert.Equal(TimeSpan.Parse("82.5:05:05.200"), i.B); Assert.Equal(82256.231250002, i.C); Assert.Equal(8293680235, i.D); Assert.Equal("Typedescriptor", i.F); Assert.Equal(new Uri("http://carbonfrost.com"), i.G); Eta e = i.E; Assert.Equal(256, e.A); Assert.Equal(TimeSpan.Parse("2.5:05:05.200"), e.B); Assert.Equal(2256.231250002, e.C); Assert.Equal(293680235, e.D); }
public void read_property_tree_implicitly_moves_initial_xml() { PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetXmlReader("beta.xml")); Assert.Equal(ReadState.Initial, reader.ReadState); PropertyTree tree = reader.ReadPropertyTree(); Assert.Equal("beta", tree.Name); }
public void read_property_tree_from_root_xml() { PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetXmlReader("beta.xml")); Assert.True(reader.Read()); PropertyTree tree = reader.ReadPropertyTree(); AssertBetaFile(tree); }
public void Value_should_equal_Expression() { PropertyTreeReader pt = LoadContent("beta-upsilon.xml"); pt.Read(); pt.Read(); // Assert.IsAssignableFrom<Expression>(pt.Value); }
public void bind_should_bind_nested_class() { PropertyTreeReader pt = LoadContent("iota-2.xml"); Assert.True(pt.Read()); Iota i = pt.Bind <Iota>(); Assert.Equal("ng", i.H.A); }
public void bind_should_apply_uri_context_to_accessible_properties() { PropertyTreeReader pt = LoadContent("beta-6.xml"); Assert.True(pt.Read()); var a = pt.Bind <Beta>(); Assert.True(Convert.ToString(a.J.BaseUri).EndsWith("beta-6.xml")); }
public void bind_add_method_factory_extension_no_parameters() { PropertyTreeReader pt = LoadContent("omicron-2.xml"); Assert.True(pt.Read()); Omicron o = pt.Bind <Omicron>(); Assert.Equal(new CultureInfo("fr-FR"), o.G.A); }
public void bind_concrete_class_indirections() { PropertyTreeReader pt = LoadContent("mu.xml"); Assert.True(pt.Read()); var b = (MuAlpha)pt.Bind <Mu>(); Assert.Equal(420, b.B); }
public void bind_latebound_provider_criteria() { PropertyTreeReader pt = LoadContent("iota-chi-2.xml"); Assert.True(pt.Read()); IotaChi b = pt.Bind(new IotaChi()); Assert.Equal("properties", App.GetProviderName(typeof(StreamingSource), b.A).LocalName); }
public void Bind_should_bind_undefined_expressions_by_ignoring() { PropertyTreeReader pt = LoadContent("beta-upsilon.xml"); Assert.True(pt.Read()); Beta b = pt.Bind(new Beta()); Assert.Null(b.D); }
public void bind_should_apply_uri_context_to_object() { PropertyTreeReader pt = LoadContent("alpha-chi.xml"); Assert.True(pt.Read()); var a = pt.Bind <AlphaChi>(); Assert.True(Convert.ToString(a.BaseUri).EndsWith("alpha-chi.xml")); }
public void BaseUri_should_equal_absolute_uri_of_local_file_streams() { PropertyTreeReader pt = PropertyTreeReader.CreateXml(File.OpenRead(GetContentPath("beta-upsilon.xml"))); pt.Read(); var baseUri = GetContentUri("beta-upsilon.xml"); Assert.Equal(baseUri, pt.BaseUri); }
public void Bind_should_pickup_items_added_to_name_scope_and_bind_expression() { PropertyTreeReader pt = LoadContent("omicron-theta-3.xml"); Assert.True(pt.Read()); OmicronTheta b = pt.Bind <OmicronTheta>(); Assert.Equal("Some string", b.Beta.D); }
public void bind_should_prefer_source_on_class() { PropertyTreeReader pt = LoadContent("beta-3.xml"); Assert.True(pt.Read()); Beta b = pt.Bind(new Beta()); Assert.Equal("not a streaming source", b.Source); }
public void BaseUri_should_equal_absolute_uri_of_local_files() { PropertyTreeReader pt = LoadContent("beta-upsilon.xml"); pt.Read(); var baseUri = GetContentUri("beta-upsilon.xml"); Assert.Equal(baseUri, pt.BaseUri); }
public void throw_before_moved() { PropertyTreeReader pt = LoadContent("beta.xml"); // TODO pt.ReadState Assert.Throws(typeof(PropertyTreeException), () => { PropertyNodeType p = pt.NodeType; }); }
public void bind_should_resolve_NameValueCollection() { PropertyTreeReader pt = LoadContent("echo.xml"); Assert.True(pt.Read()); var a = pt.Bind <Echo>().V; Assert.Equal(1, a.Keys.Count); Assert.Equal("b", a["a"]); }
public void bind_should_invoke_ancestor_attached_property_context() { PropertyTreeReader pt = LoadContent("control-extension-property.xml"); Assert.True(pt.Read()); var p = pt.Bind <Canvas>(); Assert.Equal(40, p.Controls[0]._Top); Assert.Equal(80, p.Controls[1]._Top); }
public void bind_should_invoke_extension_method() { PropertyTreeReader pt = LoadContent("control-extension-property-2.xml"); Assert.True(pt.Read()); var p = pt.Bind <Canvas>(); Assert.Equal(132, p.Controls[0]._Left); Assert.Equal(66, p.Controls[1]._Left); }
public void bind_should_resolve_relative_source_url() { PropertyTreeReader pt = LoadContent("beta-7.xml"); Assert.True(pt.Read()); var a = pt.Bind <Beta>().H; Assert.Equal('g', a.D); Assert.Equal(DateTime.Parse("3/30/2011 1:50 AM"), a.E); }
public void bind_missing_properties_throws_exception() { PropertyTreeReader pt = LoadContent("beta-4.xml"); Assert.True(pt.Read()); var ex = Record.Exception(() => pt.Bind <Beta>()); Assert.IsInstanceOf <PropertyTreeException>(ex); Assert.Contains("line 2, pos 5", ex.Message); }
public void bind_should_resolve_source_ellison() { PropertyTreeReader pt = LoadContent("omicron-theta-2.xml"); Assert.True(pt.Read()); var a = pt.Bind <OmicronTheta>().Alpha; Assert.Equal('g', a.D); Assert.Equal(DateTime.Parse("3/30/2011 1:50 AM"), a.E); }
public void bind_should_store_id_in_name_scope() { PropertyTreeReader pt = LoadContent("omicron-theta.xml"); Assert.True(pt.Read()); var ot = pt.Bind <OmicronThetaWithScope>(); Assert.NotNull(ot.FindName("alpha")); Assert.Same(ot.Alpha, ot.FindName("alpha")); }
protected PropertyTreeReader LoadContent(string fileName) { if (fileName.EndsWith(".xml", StringComparison.Ordinal)) { return(PropertyTreeReader.CreateXml(GetContentPath(fileName))); } else { throw new NotImplementedException(); } }
public void bind_should_apply_file_location_to_object() { PropertyTreeReader pt = LoadContent("beta-6.xml"); Assert.True(pt.Read()); var a = pt.Bind <Beta>(); Assert.True(a.I.SetFileLocationCalled); Assert.Equal(9, a.I.LineNumber); Assert.Equal(6, a.I.LinePosition); }