示例#1
0
        public void TestIterate1()
        {
            var doc = new BsonDocument();

            doc["a"]  = "av";
            doc["bb"] = 24;
            //doc["ccc"] = BsonDocument.ValueOf(new{na1 = 1, nb = "2"});
            //doc["d"] = new ObjectId("51b9f3af98195c4600000000");

            //17-00-00-00                       +4
            //02-61-00-03-00-00-00-61-76-00		+10
            //10-62-62-00-18-00-00-00			+8
            //00								+1
            Assert.AreEqual("17-00-00-00-02-61-00-03-00-00-00-61-76-00-10-62-62-00-18-00-00-00-00",
                            doc.ToDebugDataString());
            BsonIterator it = new BsonIterator(doc);

            Assert.AreEqual(doc.ToByteArray().Length, it.DocumentLength);
            var c = "";

            while (it.Next() != BsonType.EOO)
            {
                c += it.CurrentKey;
            }
            Assert.AreEqual("abb", c);
            it.Dispose();

            it = new BsonIterator(doc);
            var cnt = 0;

            while (it.Next() != BsonType.EOO)
            {
                BsonValue bv = it.FetchCurrentValue();
                Assert.IsNotNull(bv);
                if (cnt == 0)
                {
                    Assert.IsTrue(bv.BsonType == BsonType.STRING);
                    Assert.IsTrue(bv.Key == "a");
                    Assert.AreEqual("av", bv.Value);
                }
                if (cnt == 1)
                {
                    Assert.IsTrue(bv.BsonType == BsonType.INT);
                    Assert.IsTrue(bv.Key == "bb");
                    Assert.AreEqual(24, bv.Value);
                }
                cnt++;
            }
        }
示例#2
0
        public void TestIterate1()
        {
            var doc = new BsonDocument();
            doc["a"] = "av";
            doc["bb"] = 24;
            //doc["ccc"] = BsonDocument.ValueOf(new{na1 = 1, nb = "2"});
            //doc["d"] = new ObjectId("51b9f3af98195c4600000000");

            //17-00-00-00 						+4
            //02-61-00-03-00-00-00-61-76-00		+10
            //10-62-62-00-18-00-00-00			+8
            //00								+1
            Assert.AreEqual("17-00-00-00-02-61-00-03-00-00-00-61-76-00-10-62-62-00-18-00-00-00-00",
                            doc.ToDebugDataString());
            BsonIterator it = new BsonIterator(doc);
            Assert.AreEqual(doc.ToByteArray().Length, it.DocumentLength);
            var c = "";
            while (it.Next() != BsonType.EOO)
            {
                c += it.CurrentKey;
            }
            Assert.AreEqual("abb", c);
            it.Dispose();

            it = new BsonIterator(doc);
            var cnt = 0;
            while (it.Next() != BsonType.EOO)
            {
                BsonValue bv = it.FetchCurrentValue();
                Assert.IsNotNull(bv);
                if (cnt == 0)
                {
                    Assert.IsTrue(bv.BsonType == BsonType.STRING);
                    Assert.IsTrue(bv.Key == "a");
                    Assert.AreEqual("av", bv.Value);
                }
                if (cnt == 1)
                {
                    Assert.IsTrue(bv.BsonType == BsonType.INT);
                    Assert.IsTrue(bv.Key == "bb");
                    Assert.AreEqual(24, bv.Value);
                }
                cnt++;
            }
        }