public void bson_serialize_message_test()
        {
            var          prop1 = "prop1";
            var          prop2 = "prop2";
            var          msg   = new WoftamEvent(prop1, prop2);
            MemoryStream ms    = new MemoryStream();
            var          bs    = new BsonDataWriter(ms);

            bs.WriteStartObject();
            bs.WritePropertyName(msg.GetType().FullName);
            bs.WriteValue(JsonConvert.SerializeObject(msg));
            bs.WriteEnd();
             
            ms.Seek(0, SeekOrigin.Begin);

            Message msg2;
            var     reader = new BsonDataReader(ms);

            // read object
            reader.Read();
            // read type name
            reader.Read();
            var messageType = MessageHierarchy.GetTypeByFullName((string)reader.Value);

            reader.Read(); //property value
            msg2 = (Message)JsonConvert.DeserializeObject((string)reader.Value, messageType);
            Assert.IsType <WoftamEvent>(msg2);
            Assert.Equal(prop1, ((WoftamEvent)msg2).Property1);
        }
        public void bson_serialize_object_test()
        {
            var          propName  = "Value";
            var          propValue = "Dummy";
            MemoryStream ms        = new MemoryStream();
            var          bs        = new BsonDataWriter(ms);

            bs.WriteStartObject();
            bs.WritePropertyName(propName);
            bs.WriteValue(propValue);
            bs.WriteEnd();
             
            ms.Seek(0, SeekOrigin.Begin);

             
            var reader = new BsonDataReader(ms);

            // object
            reader.Read();
            // property name
            reader.Read();
            Assert.Equal(propName, (string)reader.Value);
            reader.Read();
            Assert.Equal(propValue, (string)reader.Value);
        }
示例#3
0
        public void WriteValues()
        {
            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            writer.WriteStartArray();
            writer.WriteValue(long.MaxValue);
            writer.WriteValue((ulong)long.MaxValue);
            writer.WriteValue(int.MaxValue);
            writer.WriteValue((uint)int.MaxValue);
            writer.WriteValue(byte.MaxValue);
            writer.WriteValue(sbyte.MaxValue);
            writer.WriteValue('a');
            writer.WriteValue(decimal.MaxValue);
            writer.WriteValue(double.MaxValue);
            writer.WriteValue(float.MaxValue);
            writer.WriteValue(true);
            writer.WriteValue(new byte[] { 0, 1, 2, 3, 4 });
            writer.WriteValue(new DateTimeOffset(2000, 12, 29, 12, 30, 0, TimeSpan.Zero));
            writer.WriteValue(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc));
            writer.WriteEnd();

            string bson = BytesToHex(ms.ToArray());

            Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-00-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson);
        }
示例#4
0
        public void WriteEndOnProperty()
        {
            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            writer.WriteStartObject();
            writer.WritePropertyName("Blah");
            writer.WriteEnd();

            Assert.AreEqual("0B-00-00-00-0A-42-6C-61-68-00-00", (BitConverter.ToString(ms.ToArray())));
        }
示例#5
0
        public void WriteDouble()
        {
            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            writer.WriteStartArray();
            writer.WriteValue(99.99d);
            writer.WriteEnd();

            string bson = BytesToHex(ms.ToArray());

            Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson);
        }
示例#6
0
        public void WriteGuid()
        {
            Guid g = new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705");

            MemoryStream   ms     = new MemoryStream();
            BsonDataWriter writer = new BsonDataWriter(ms);

            writer.WriteStartArray();
            writer.WriteValue(g);
            writer.WriteEnd();

            string bson = BytesToHex(ms.ToArray());

            Assert.AreEqual("1D-00-00-00-05-30-00-10-00-00-00-04-D7-EE-21-D8-5C-4B-C9-43-8A-C2-69-28-E5-79-B7-05-00", bson);
        }