public void MessageFromSubscriberIsSentToCorrectHost() { byte[] b = new byte[1024]; NetworkController nc = new NetworkController(); FakeServer server = new FakeServer(); nc.Servers.Add(server); Networking.NetworkController = nc; Networking.Start(); FakeSender sender = new FakeSender(); SenderBase.FactoryMethod = e => sender; Message msg = new Message(); msg.Data = b; msg.Sender = EllaConfiguration.Instance.NodeId + 1; msg.Type = MessageType.Discover; IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456); server.DiscoveryMessageEvent(msg, ep); TestSubscriber s = new TestSubscriber(); s.Subscribe(); server.SubscribeResponseMessageEvent(sender._id); Thread.Sleep(1000); s.SendMessage(); Thread.Sleep(1000); Assert.AreEqual(1, sender._messages[MessageType.ApplicationMessage]); }
public void NetworkControllerUnsubscribeFrom() { byte[] b = new byte[1024]; NetworkController nc = new NetworkController(); FakeServer fs = new FakeServer(); FakeSender sender = new FakeSender(); nc.Servers.Add(fs); Networking.NetworkController = nc; Networking.Start(); SenderBase.FactoryMethod = e => sender; //this discoveryMessage is required to add the Instance to the RemoteHosts, //which is used in the NetworkController to send messages, subscribe, unsubscribe.. //must call these MessageProcessor methods by hand, because the FakeSender just fakes the Send() implementation Message msg = new Message(); msg.Data = b; msg.Sender = EllaConfiguration.Instance.NodeId + 1; msg.Type = MessageType.Discover; IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456); fs.DiscoveryMessageEvent(msg, ep); TestSubscriber s = new TestSubscriber(); s.Subscribe(); Thread.Sleep(1000); //after subscription is done: new MessageEvent of Type SubscribeResponse is faked in FakeServer fs.SubscribeResponseMessageEvent(sender._id); s.UnsubscribeFromRemote(); Thread.Sleep(1000); Assert.AreEqual(1, sender._messages[MessageType.Unsubscribe]); }