예제 #1
0
        public void TestComplexProp()
        {
            var a = new TestModel.A();

            var innerA = new TestModel.A {
                Str = "qqq", ManyStrs = new List <string> {
                    "qwer", "cvbn"
                }
            };

            a.Str      = "xxx";
            a.ManyStrs = new List <string> {
                "asdf", "Zxcv"
            };
            a.SingleA = innerA;

            var qe = new QueryEntity
            {
                ObjectDefinitionFullName = "WasA",
                PropertyList             = new List <string> {
                    "Str", "ManyStrs"
                },
                ChildList = new List <QueryEntity>
                {
                    new QueryEntity
                    {
                        ObjectDefinitionFullName
                                     = "WasA",
                        PropertyList =
                            new List <string
                                      >
                        {
                            "Str",
                            "ManyStrs"
                        },
                        Name = "SingleA"
                    }
                }
            };

            var de = DataReflector.ToDataEntity(a, qe);

            Assert.AreEqual(2, de.Properties.Count);
            Assert.AreEqual("asdf", ((List <string>)de.Properties["ManyStrs"]).First());
            Assert.AreEqual(1, de.Children.Count);
            Assert.AreEqual("WasA", de.Children["SingleA"].First().ObjectDefinitionFullName);

            Assert.AreEqual("qqq", de.Children["SingleA"].First().Properties["Str"]);
        }
예제 #2
0
        public void TestComplexPropsThatAreNull()
        {
            var a = new TestModel.A();

            var innerA = new TestModel.A {
                Str = "qqq", ManyStrs = new List <string> {
                    "qwer", "cvbn"
                }
            };

            a.Str      = "xxx";
            a.ManyStrs = new List <string> {
                "asdf", "Zxcv"
            };
            a.SingleA = null;

            var qe = new QueryEntity
            {
                ObjectDefinitionFullName = "WasA",
                PropertyList             = new List <string> {
                    "Str", "ManyStrs"
                },
                ChildList = new List <QueryEntity>
                {
                    new QueryEntity
                    {
                        ObjectDefinitionFullName
                                     = "WasA",
                        PropertyList =
                            new List <string
                                      >
                        {
                            "Str",
                            "ManyStrs"
                        },
                        Name = "SingleA"
                    }
                }
            };

            var de = DataReflector.ToDataEntity(a, qe);

            Assert.AreEqual(2, de.Properties.Count);
            Assert.AreEqual("asdf", ((List <string>)de.Properties["ManyStrs"]).First());
            Assert.AreEqual(1, de.Children.Count);
            Assert.AreEqual(1, de.Children.First().Value.Count, "A Single Complex Property should always be encoded as a list of 1.");
            Assert.IsNull(de.Children["SingleA"].First());
        }
예제 #3
0
        public void TestSimpleProps()
        {
            var a = new TestModel.A();

            a.Str = "asdf";

            var de = DataReflector.ToDataEntity(
                a,
                new QueryEntity()
            {
                ObjectDefinitionFullName = "WasA", PropertyList = new List <string> {
                    "Str"
                }
            });

            Assert.AreEqual(1, de.Properties.Count);
            Assert.AreEqual("asdf", de.Properties["Str"]);
            Assert.AreNotEqual("_asdf", de.Properties["Str"]);
        }
예제 #4
0
        public void TestSimplePropsWithSimpleList()
        {
            var a = new TestModel.A();

            a.Str      = "asdf";
            a.ManyStrs = new List <string> {
                "asdf", "Zxcv"
            };

            var de = DataReflector.ToDataEntity(
                a,
                new QueryEntity()
            {
                ObjectDefinitionFullName = "WasA",
                PropertyList             = new List <string> {
                    "Str", "ManyStrs"
                }
            });

            Assert.AreEqual(2, de.Properties.Count);
            Assert.AreEqual("asdf", ((List <string>)de.Properties["ManyStrs"]).First());
        }
예제 #5
0
        public void TestComplexPropLists()
        {
            var a = new TestModel.A();

            var innerA = new TestModel.A {
                Str = "qqq", ManyStrs = new List <string> {
                    "qwer", "cvbn"
                }
            };

            a.Str      = "xxx";
            a.ManyStrs = new List <string> {
                "asdf", "Zxcv"
            };
            a.SingleA = innerA;
            a.ManyAs  = new List <TestModel.A> {
                innerA, innerA
            };

            var qe = new QueryEntity
            {
                ObjectDefinitionFullName = "WasA",
                PropertyList             = new List <string> {
                    "Str", "ManyStrs"
                },
                ChildList = new List <QueryEntity>
                {
                    new QueryEntity
                    {
                        ObjectDefinitionFullName
                                     = "WasA",
                        PropertyList =
                            new List <string
                                      >
                        {
                            "Str",
                            "ManyStrs"
                        },
                        Name = "SingleA"
                    },
                    new QueryEntity
                    {
                        ObjectDefinitionFullName
                                     = "WasA",
                        PropertyList =
                            new List <string
                                      >
                        {
                            "Str",
                            "ManyStrs"
                        },
                        Name = "ManyAs"
                    }
                }
            };

            var de = DataReflector.ToDataEntity(a, qe);

            Assert.AreEqual(2, de.Properties.Count);
            Assert.AreEqual("asdf", ((List <string>)de.Properties["ManyStrs"]).First());
            Assert.AreEqual(2, de.Children.Count);
            Assert.AreEqual("WasA", de.Children["SingleA"].First().ObjectDefinitionFullName);

            Assert.AreEqual("qqq", de.Children["SingleA"].First().Properties["Str"]);
            Assert.AreEqual(2, de.Children["ManyAs"].Count);

            var childrenNested = de.Children["ManyAs"];

            Assert.IsTrue(
                childrenNested.SelectMany(x => x.Properties.Where(kv => kv.Key == "Str"))
                .All(kv => kv.Value.ToString() == "qqq"));
        }