public void TestEncodedObjectRequestReply() { using (IEncodedConnection c = new ConnectionFactory().CreateEncodedConnection()) { Object mu = new Object(); SerializationTestObj origObj = new SerializationTestObj(); EventHandler <EncodedMessageEventArgs> eh = (sender, args) => { SerializationTestObj so = (SerializationTestObj)args.ReceivedObject; Assert.IsTrue(so.Equals(origObj)); String str = "Received"; c.Publish(args.Reply, str); c.Flush(); lock (mu) { Monitor.Pulse(mu); } }; using (IAsyncSubscription s = c.SubscribeAsync("foo", eh)) { Assert.IsTrue("Received".Equals(c.Request("foo", origObj, 1000))); Assert.IsTrue("Received".Equals(c.Request("foo", origObj))); } } }
public void TestDefaultObjectSerialization() { using (new NATSServer()) { using (IEncodedConnection c = DefaultEncodedConnection) { Object mu = new Object(); SerializationTestObj origObj = new SerializationTestObj(); EventHandler <EncodedMessageEventArgs> eh = (sender, args) => { // Ensure we blow up in the cast SerializationTestObj so = (SerializationTestObj)args.ReceivedObject; Assert.True(so.Equals(origObj)); lock (mu) { Monitor.Pulse(mu); } }; using (IAsyncSubscription s = c.SubscribeAsync("foo", eh)) { lock (mu) { c.Publish("foo", new SerializationTestObj()); c.Flush(); Monitor.Wait(mu, 1000); } } } } }
public void TestEncodedSerizationOverrides() { using (IEncodedConnection c = new ConnectionFactory().CreateEncodedConnection()) { c.OnDeserialize = deserializeFromXML; c.OnSerialize = serializeToXML; Object mu = new Object(); SerializationTestObj origObj = new SerializationTestObj(); origObj.a = 99; EventHandler <EncodedMessageEventArgs> eh = (sender, args) => { SerializationTestObj so = (SerializationTestObj)args.ReceivedObject; Assert.IsTrue(so.Equals(origObj)); lock (mu) { Monitor.Pulse(mu); } }; using (IAsyncSubscription s = c.SubscribeAsync("foo", eh)) { lock (mu) { c.Publish("foo", origObj); c.Flush(); Monitor.Wait(mu, 1000); } } } }