Beispiel #1
0
        public void T_07_ArraysListsAndMaps()
        {
            var row = new RowC
              {
            Map = new JSONDataMap{{"Name","Xerson"},{"Age",123}},
            List = new List<object>{ 1,true, "YEZ!", -123.01m},
            ObjectArray = new object[]{123, -12, 789d, new GDID(0, 1223), null},
            MapArray = new JSONDataMap[]{ new JSONDataMap{{"a",1},{"b",true}},  new JSONDataMap{{"kosmos",234.12},{"b",null}} },
            MapList = new List<JSONDataMap>{ new JSONDataMap{{"abc",0},{"buba", new GDID(2, 1223)}},  new JSONDataMap{{"nothing",null}} }
              };

              var rc = new RowConverter();

              var doc = rc.RowToBSONDocument(row, "A");
              Console.WriteLine( doc.ToString() );

              var row2 = new RowC();
              rc.BSONDocumentToRow(doc, row2, "A");

              Assert.AreEqual(2, row2.Map.Count);
              Assert.AreEqual("Xerson", row2.Map["Name"]);
              Assert.AreEqual(123, row2.Map["Age"]);

              Assert.AreEqual(4, row2.List.Count);
              Assert.AreEqual(1, row2.List[0]);
              Assert.AreEqual(true, row2.List[1]);
              Assert.AreEqual("YEZ!", row2.List[2]);
              Assert.AreEqual(-123010m, row2.List[3]); //notice that "decimalness" is lost, because reading back into list<object>

              Assert.AreEqual(5, row2.ObjectArray.Length);
              Assert.AreEqual(123, row2.ObjectArray[0]);
              Assert.AreEqual(-12, row2.ObjectArray[1]);
              Assert.AreEqual(789, row2.ObjectArray[2]);
              Assert.IsTrue((new byte[]{0,0,0,0,0,0,0,0,0,0,0x04,0xc7}).SequenceEqual( (byte[])(row2.ObjectArray[3]) ));//notice that GDID is lost, it got turned into int because reading back in object[], so no type conversion happens
              Assert.AreEqual(null, row2.ObjectArray[4]);

              Assert.AreEqual(2, row2.MapArray.Length);
              Assert.AreEqual(1, row2.MapArray[0]["a"]);
              Assert.AreEqual(true, row2.MapArray[0]["b"]);
              Assert.AreEqual(234.12, row2.MapArray[1]["kosmos"]);
              Assert.AreEqual(null, row2.MapArray[1]["b"]);

              Assert.AreEqual(2, row2.MapList.Count);
              Assert.AreEqual(2, row2.MapList[0].Count);
              Assert.AreEqual(0, row2.MapList[0]["abc"]);
              Assert.IsTrue((new byte[]{0,0,0,2,0,0,0,0,0,0,0x04,0xc7}).SequenceEqual( (byte[])(row2.MapList[0]["buba"]) ) );//"GDIDness" is lost
              Assert.AreEqual(1, row2.MapList[1].Count);
              Assert.AreEqual(null, row2.MapList[1]["nothing"]);
        }
Beispiel #2
0
        public void T_07_ArraysListsAndMaps()
        {
            var row = new RowC
            {
                Map = new JSONDataMap {
                    { "Name", "Xerson" }, { "Age", 123 }
                },
                List = new List <object> {
                    1, true, "YEZ!", -123.01m
                },
                ObjectArray = new object[] { 123, -12, 789d, new GDID(0, 1223), null },
                MapArray    = new JSONDataMap[] { new JSONDataMap {
                                                      { "a", 1 }, { "b", true }
                                                  }, new JSONDataMap {
                                                      { "kosmos", 234.12 }, { "b", null }
                                                  } },
                MapList = new List <JSONDataMap> {
                    new JSONDataMap {
                        { "abc", 0 }, { "buba", new GDID(2, 1223) }
                    }, new JSONDataMap {
                        { "nothing", null }
                    }
                }
            };

            var rc = new RowConverter();

            var doc = rc.RowToBSONDocument(row, "A");

            Console.WriteLine(doc.ToString());

            var row2 = new RowC();

            rc.BSONDocumentToRow(doc, row2, "A");

            Assert.AreEqual(2, row2.Map.Count);
            Assert.AreEqual("Xerson", row2.Map["Name"]);
            Assert.AreEqual(123, row2.Map["Age"]);

            Assert.AreEqual(4, row2.List.Count);
            Assert.AreEqual(1, row2.List[0]);
            Assert.AreEqual(true, row2.List[1]);
            Assert.AreEqual("YEZ!", row2.List[2]);
            Assert.AreEqual(-123010m, row2.List[3]); //notice that "decimalness" is lost, because reading back into list<object>

            Assert.AreEqual(5, row2.ObjectArray.Length);
            Assert.AreEqual(123, row2.ObjectArray[0]);
            Assert.AreEqual(-12, row2.ObjectArray[1]);
            Assert.AreEqual(789, row2.ObjectArray[2]);
            Assert.IsTrue((new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0xc7 }).SequenceEqual((byte[])(row2.ObjectArray[3])));//notice that GDID is lost, it got turned into int because reading back in object[], so no type conversion happens
            Assert.AreEqual(null, row2.ObjectArray[4]);

            Assert.AreEqual(2, row2.MapArray.Length);
            Assert.AreEqual(1, row2.MapArray[0]["a"]);
            Assert.AreEqual(true, row2.MapArray[0]["b"]);
            Assert.AreEqual(234.12, row2.MapArray[1]["kosmos"]);
            Assert.AreEqual(null, row2.MapArray[1]["b"]);

            Assert.AreEqual(2, row2.MapList.Count);
            Assert.AreEqual(2, row2.MapList[0].Count);
            Assert.AreEqual(0, row2.MapList[0]["abc"]);
            Assert.IsTrue((new byte[] { 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0x04, 0xc7 }).SequenceEqual((byte[])(row2.MapList[0]["buba"])));//"GDIDness" is lost
            Assert.AreEqual(1, row2.MapList[1].Count);
            Assert.AreEqual(null, row2.MapList[1]["nothing"]);
        }