Example #1
0
        public void TestSimpleBinaryRead()
        {
            string hex = "0600000002020000000102";
            byte[] data = DecodeHex (hex);
            MemoryStream stream = new MemoryStream (data);

            BsonReader reader = new BsonReader(stream);
            BsonBinary binaryOut = new BsonBinary ();
            int read = binaryOut.Read(reader);
            Assert.AreEqual(hex.Length/2,read);
            Assert.AreEqual((byte)2,binaryOut.Subtype);
            Assert.AreEqual(2,binaryOut.Val.Length);
            Assert.AreEqual(hex.Length/2, binaryOut.Size);
        }
Example #2
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);
        }
Example #3
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);
        }