Ejemplo n.º 1
0
        public void TestSimpleBinaryStorage()
        {
            Binary b = new Binary();
            byte[] data = new byte[2];
            data[0] = (byte)1;
            data[1] = (byte)2;
            b.Subtype = Binary.TypeCode.General;

            BsonBinary binaryIn = new BsonBinary (new Binary (data));
            MemoryStream stream = new MemoryStream ();
            BsonWriter bsonWriter = new BsonWriter (stream);
            binaryIn.Write (bsonWriter);

            string hex = BitConverter.ToString (stream.ToArray());
            hex = hex.Replace ("-", "");
            Assert.AreEqual("0600000002020000000102",hex);
        }
Ejemplo n.º 2
0
        public void TestBinary()
        {
            byte[] data = File.ReadAllBytes(@"test-data\tests.binary.txt");
            BsonBinary binaryIn = new BsonBinary(new Binary(data));
            MemoryStream stream = new MemoryStream();
            BsonWriter bsonWriter = new BsonWriter(stream);
            binaryIn.Write(bsonWriter);

            stream.Position = 0;
            BsonReader reader = new BsonReader(stream);
            BsonBinary binaryOut = new BsonBinary();
            int size = reader.ReadInt32();
            binaryOut.Subtype = reader.ReadByte();
            binaryOut.Val = reader.ReadBytes(size);
            Assert.AreEqual(binaryIn.Val, binaryOut.Val);
            Assert.AreEqual(binaryIn.Subtype, binaryOut.Subtype);
            Assert.AreEqual(data.Length, binaryOut.Size);
        }