示例#1
0
        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);
        }
示例#2
0
        public void Value_should_equal_Expression()
        {
            PropertyTreeReader pt = LoadContent("beta-upsilon.xml");

            pt.Read();
            pt.Read();

            // Assert.IsAssignableFrom<Expression>(pt.Value);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        public void node_types()
        {
            PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetContentPath("beta.xml"));

            Assert.Equal(ReadState.Initial, reader.ReadState);
            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.PropertyTree, reader.NodeType);
            Assert.Equal("beta", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.Property, reader.NodeType);
            Assert.Equal("c", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.Property, reader.NodeType);
            Assert.Equal("d", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.PropertyTree, reader.NodeType);
            Assert.Equal("a", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.Property, reader.NodeType);
            Assert.Equal("a", reader.Name);

            // Additional reads
            TestUtils.Times(() => reader.Read(), 5);

            Assert.Equal(PropertyNodeType.EndPropertyTree, reader.NodeType);
            Assert.Equal("a", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.PropertyTree, reader.NodeType);
            Assert.Equal("b", reader.Name);

            Assert.True(reader.Read());
            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.EndPropertyTree, reader.NodeType);
            Assert.Equal("b", reader.Name);

            Assert.True(reader.Read());
            Assert.Equal(PropertyNodeType.EndPropertyTree, reader.NodeType);
            Assert.Equal("beta", reader.Name);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        public void ReadPropertyTree_should_retain_prefix_map_in_nodes()
        {
            PropertyTreeReader reader = PropertyTreeReader.CreateXml(GetXmlReader("alpha.xml"));

            Assert.True(reader.Read());
            Assert.True(reader.Read());
            Assert.True(reader.Read());

            // The tree created here should also support ns resolving
            PropertyTree tree     = PropertyTreeReader.CreateXml(GetXmlReader("alpha.xml")).ReadPropertyTree();
            var          nav      = tree.CreateNavigator();
            var          resolver = (IXmlNamespaceResolver)nav;

            nav.MoveToFirstChild();
            Assert.Equal("a", nav.Name);
            Assert.Equal("https://ns.carbonfrost.com/commons/core",
                         resolver.LookupNamespace("shared"));
            Assert.Null(resolver.LookupNamespace(string.Empty));
        }
示例#18
0
        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"));
        }
示例#19
0
        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);
        }
示例#20
0
        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"));
        }
示例#21
0
        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);
        }
示例#22
0
        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"));
        }
示例#23
0
        public void bind_optional_parameters()
        {
            PropertyTreeReader pt = LoadContent("upsilon.xml");

            Assert.True(pt.Read());

            Upsilon p = pt.Bind <Upsilon>();

            Assert.Equal(45, p.A);
            Assert.Equal("yipp", p.B);
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#26
0
        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);
        }
示例#27
0
        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);
        }
示例#28
0
        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);
        }
示例#29
0
        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"]);
        }
示例#30
0
        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);
        }