コード例 #1
0
        public void TestElements()
        {
            BsonDocument bdoc = new BsonDocument();
            MemoryStream buf = new MemoryStream();
            BsonWriter writer = new BsonWriter(buf);

            Oid oid = new Oid("4a753ad8fac16ea58b290351");

            bdoc.Append("_id", new BsonElement("_id",new BsonOid(oid)))
                .Append("a", new BsonElement("a",new BsonNumber(1)))
                .Append("b", new BsonElement("b",new BsonString("test")));
            bdoc.Write(writer);

            writer.Flush();

            Byte[] output = buf.ToArray();
            String hexdump = BitConverter.ToString(output);
            hexdump = hexdump.Replace("-","");
                             //0         1         2         3         4         5         6         7         8         9
                             //0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
            string expected = "2D000000075F6964004A753AD8FAC16EA58B290351016100000000000000F03F02620005000000746573740000";
            Assert.AreEqual(expected,hexdump, "Dump not correct");
        }
コード例 #2
0
        public void TestNumberElements()
        {
            BsonDocument bdoc = new BsonDocument();
            MemoryStream buf = new MemoryStream();
            BsonWriter writer = new BsonWriter(buf);

            Oid oid = new Oid("4a75384cfac16ea58b290350");

            bdoc.Append("_id", new BsonElement("_id",new BsonOid(oid)))
                .Append("a", new BsonElement("a",new BsonNumber(1)))
                .Append("b", new BsonElement("b",new BsonNumber(2)));
            bdoc.Write(writer);

            writer.Flush();

            Byte[] output = buf.ToArray();
            String hexdump = BitConverter.ToString(output);
            hexdump = hexdump.Replace("-","");

            Assert.AreEqual("2C000000075F6964004A75384CFAC16EA58B290350016100000000000000F03F016200000000000000004000",hexdump, "Dump not correct");
        }