Exemplo n.º 1
0
        public void T_04_Array()
        {
            using (var client = new MongoClient("My Test"))
            {
                var db = client.DefaultLocalServer["db1"];

                db["t1"].Drop();

                var t1 = db["t1"];

                var row = new ArrayRow
                {
                    _id = 1,
                    Map = new JSONDataMap {
                        { "Name", "Xerson" }, { "Age", 123 }
                    },
                    List = new List <object> {
                        1, true, "YEZ!", -123.01
                    },
                    ObjectArray = new object[] { 123, -12, 789d, null, new object[] { 54.67d, "alpIna" } },
                    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", -40.0789 }
                        }, new JSONDataMap {
                            { "nothing", null }
                        }
                    }
                };

                var rc  = new NFX.Serialization.BSON.RowConverter();
                var doc = rc.RowToBSONDocument(row, "A");
                Assert.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

                var got = db["t1"].FindOne(Query.ID_EQ_Int32(1));
                Assert.IsNotNull(got);

                var row1 = new ArrayRow();
                rc.BSONDocumentToRow(got, row1, "A");

                Assert.AreEqual(row, row1);
            }
        }
Exemplo n.º 2
0
        public void T_04_Array()
        {
            using(var client= new MongoClient("My Test"))
              {
            var db = client.DefaultLocalServer["db1"];

            db["t1"].Drop();

            var t1 = db["t1"];

            var row = new ArrayRow
            {
              _id = 1,
              Map = new JSONDataMap{{"Name","Xerson"},{"Age",123}},
              List = new List<object>{ 1,true, "YEZ!", -123.01},
              ObjectArray = new object[]{123, -12, 789d, null, new object[] { 54.67d, "alpIna"}},
              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", -40.0789}},  new JSONDataMap{{"nothing",null}} }
            };

            var rc = new NFX.Serialization.BSON.RowConverter();
            var doc = rc.RowToBSONDocument(row, "A");
            Assert.AreEqual(1, t1.Insert(doc).TotalDocumentsAffected);

            var got = db["t1"].FindOne(Query.ID_EQ_Int32(1));
            Assert.IsNotNull( got );

            var row1 = new ArrayRow();
            rc.BSONDocumentToRow(got, row1, "A");

            Assert.AreEqual(row, row1);
              }
        }