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);
        }
Esempio n. 2
0
        public void can_serialize_from_message()
        {
            var serializer = new SimpleJsonSerializer();
            var json       = serializer.SerializeMessage(_testEvent);
            var encoder    = new TcpMessageEncoder();
            var data       = encoder.ToBytes(json, _testEvent.GetType());
            var decoded    = encoder.FromBytes(data);
            var msg        = serializer.DeserializeMessage(decoded.Item1, decoded.Item2);

            Assert.IsType <WoftamEvent>(msg);
            var msg2 = msg as WoftamEvent;

            Assert.NotNull(msg2);
            // ReSharper disable once PossibleNullReferenceException
            Assert.Equal(_testEvent.Property1, msg2.Property1);
            Assert.Equal(_testEvent.Property2, msg2.Property2);
        }