public void AddAfterStarting() { var p = new MockConnectionProvider (protocol); Assert.IsFalse (p.IsRunning); var server = new MockServer (provider, MessageTypes.Reliable); server.Start(); server.AddConnectionProvider (p); Assert.IsTrue (p.IsRunning); }
public void ConnectionMade() { var server = new MockServer (provider, MessageTypes.Reliable); server.Start(); var test = new AsyncTest(); server.ConnectionMade += test.PassHandler; var client = provider.GetClientConnection (protocol); client.ConnectAsync (new IPEndPoint (IPAddress.Any, 0), MessageTypes.Reliable); test.Assert (5000); }
public void MessageHandlingGlobalOrder() { IServerConnection connection = null; var test = new AsyncTest(e => { var me = (MessageEventArgs)e; Assert.AreSame (connection, me.Connection); Assert.IsInstanceOf (typeof(MockMessage), me.Message); Assert.AreEqual ("hi", ((MockMessage)me.Message).Content); }); var server = new MockServer (MessageTypes.Reliable); server.AddConnectionProvider (provider, ExecutionMode.GlobalOrder); server.Start(); Action<MessageEventArgs> handler = e => test.PassHandler (test, e); ((IContext)server).RegisterMessageHandler (MockProtocol.Instance, 1, handler); provider.ConnectionMade += (sender, e) => connection = e.Connection; var c = provider.GetClientConnection (protocol); c.ConnectAsync (new IPEndPoint (IPAddress.Any, 0), MessageTypes.Reliable); c.Send (new MockMessage { Content = "hi" }); test.Assert (10000); }
public void GenericMessageHandling() { IServerConnection connection = null; var test = new AsyncTest (e => { var me = (MessageEventArgs<MockMessage>)e; Assert.AreSame (connection, me.Connection); Assert.AreEqual ("hi", me.Message.Content); }); var server = new MockServer (provider, MessageTypes.Reliable); server.Start(); Action<MessageEventArgs<MockMessage>> handler = e => test.PassHandler (test, e); server.RegisterMessageHandler (handler); provider.ConnectionMade += (sender, e) => connection = e.Connection; var c = provider.GetClientConnection (protocol); c.ConnectAsync (new IPEndPoint (IPAddress.Any, 0), MessageTypes.Reliable); c.Send (new MockMessage { Content = "hi" }); test.Assert (10000); }