Exemplo n.º 1
0
        public void Should_get_and_set_generic_object_converted_to_document()
        {
            var dummy1 = new Dummy();

            dummy1.Foo = "test string value";
            dummy1.Bar = 12345;

            var dummy2 = new NestedDummy();

            dummy2.Foo        = "test value string";
            dummy2.Bar        = 54321;
            dummy2.Baz        = dummy1;
            dummy2.StringList = new List <string> {
                "one", "two", "three"
            };
            dummy2.ObjectList = new List <Dummy>
            {
                new Dummy()
                {
                    Foo = "one", Bar = 1
                },
                new Dummy()
                {
                    Foo = "two", Bar = 2
                },
                new Dummy()
                {
                    Foo = "three", Bar = 3
                }
            };

            var doc1 = Document.ToDocument(dummy1);
            var doc2 = Document.ToDocument(dummy2);

            var document = new Document()
                           .Object("foo", Document.ToDocument(dummy1))
                           .Object("bar.baz", Document.ToDocument(dummy2));

            Assert.AreEqual(doc1, document.Object("foo"));
            Assert.AreEqual(doc2, document.Object("bar.baz"));

            var stringList = document.List <string>("bar.baz.StringList");
            var objectList = document.List <Document>("bar.baz.ObjectList");

            Assert.AreEqual(dummy2.StringList, stringList);
            Assert.AreEqual(Document.ToList(dummy2.ObjectList), objectList);
        }
Exemplo n.º 2
0
        public void Should_get_and_set_generic_object_values()
        {
            var dummy1 = new Dummy();

            dummy1.Foo = "test string value";
            dummy1.Bar = 12345;

            var dummy2 = new NestedDummy();

            dummy2.Foo        = "test value string";
            dummy2.Bar        = 54321;
            dummy2.Baz        = dummy1;
            dummy2.StringList = new List <string> {
                "one", "two", "three"
            };
            dummy2.ObjectList = new List <Dummy>
            {
                new Dummy()
                {
                    Foo = "one", Bar = 1
                },
                new Dummy()
                {
                    Foo = "two", Bar = 2
                },
                new Dummy()
                {
                    Foo = "three", Bar = 3
                }
            };

            var document = new Document()
                           .Object("foo", dummy1)
                           .Object("bar.baz", dummy2);

            Assert.AreEqual(dummy1, document.Object <Dummy>("foo"));
            Assert.AreEqual(dummy2, document.Object <NestedDummy>("bar.baz"));
        }