Example #1
0
        public void TestAccessorForRecursive()
        {
            var m = new MutableSample();
            {
                var d = m.AsDictionary();

                d["Id"]   = 1;
                d["Time"] = DateTime.Now;
                d["X"]    = 10.0;
                d["Y"]    = 20.0;
            }

            var r1 = new RecursiveSample
            {
                X = new ImmutableSample(2, DateTime.Now.AddDays(1), 11, 21),
                Y = m,
            };
            var r2 = new RecursiveSample
            {
                X = new ImmutableSample(3, DateTime.Now.AddDays(2), 12, 22),
            };

            var d1 = r1.AsDictionary();
            var d2 = r2.AsDictionary();

            d2["Y"] = d1["Y"];

            Assert.NotNull(r2.Y);
            Assert.Equal(r1.Y, r2.Y);

            Assert.Equal(1, r1.Y.Id);
            Assert.Equal(10.0, r1.Y.X);
            Assert.Equal(20.0, r1.Y.Y);

            var dx1 = d1["X"] as IDictionary <string, object>;

            Assert.NotNull(dx1);
            Assert.Equal(r1.X.Id, dx1["Id"]);
            Assert.Equal(r1.X.Time, dx1["Time"]);
            Assert.Equal(r1.X.X, dx1["X"]);
            Assert.Equal(r1.X.Y, dx1["Y"]);

            var dx2 = d2["X"] as IDictionary <string, object>;

            Assert.NotNull(dx2);
            Assert.Equal(r2.X.Id, dx2["Id"]);
            Assert.Equal(r2.X.Time, dx2["Time"]);
            Assert.Equal(r2.X.X, dx2["X"]);
            Assert.Equal(r2.X.Y, dx2["Y"]);
        }
Example #2
0
        public void TestAccessorForRecursive()
        {
            var m = new MutableSample();
            {
                var d = m.AsDictionary();

                d["Id"] = 1;
                d["Time"] = DateTime.Now;
                d["X"] = 10.0;
                d["Y"] = 20.0;
            }

            var r1 = new RecursiveSample
            {
                X = new ImmutableSample(2, DateTime.Now.AddDays(1), 11, 21),
                Y = m,
            };
            var r2 = new RecursiveSample
            {
                X = new ImmutableSample(3, DateTime.Now.AddDays(2), 12, 22),
            };

            var d1 = r1.AsDictionary();
            var d2 = r2.AsDictionary();

            d2["Y"] = d1["Y"];

            Assert.NotNull(r2.Y);
            Assert.Equal(r1.Y, r2.Y);

            Assert.Equal(1, r1.Y.Id);
            Assert.Equal(10.0, r1.Y.X);
            Assert.Equal(20.0, r1.Y.Y);

            var dx1 = d1["X"] as IDictionary<string, object>;
            Assert.NotNull(dx1);
            Assert.Equal(r1.X.Id, dx1["Id"]);
            Assert.Equal(r1.X.Time, dx1["Time"]);
            Assert.Equal(r1.X.X, dx1["X"]);
            Assert.Equal(r1.X.Y, dx1["Y"]);

            var dx2 = d2["X"] as IDictionary<string, object>;
            Assert.NotNull(dx2);
            Assert.Equal(r2.X.Id, dx2["Id"]);
            Assert.Equal(r2.X.Time, dx2["Time"]);
            Assert.Equal(r2.X.X, dx2["X"]);
            Assert.Equal(r2.X.Y, dx2["Y"]);
        }