public void TestEventHandlerThrows() { Exception error = null; using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel)) using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel)) { ch1.StartListening("ch1"); ch1.OnError += delegate(object o, ErrorEventArgs e) { error = e.GetException(); }; ch1["Throw"].OnEvent += delegate(object o, IpcSignalEventArgs e) { throw new Exception("Throw"); }; ch1.RaiseLocal("Throw"); Assert.IsNotNull(error); Assert.AreEqual(typeof(Exception), error.GetType()); Assert.AreEqual("Throw", error.Message); error = null; sender.Broadcast(100, "Throw"); ch1.StopListening(1000); Assert.IsNotNull(error); Assert.AreEqual(typeof(Exception), error.GetType()); Assert.AreEqual("Throw", error.Message); } }
public void TestUnsubscribeFromEvent() { using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel)) { int count = 0; EventHandler <IpcSignalEventArgs> handler = delegate(object o, IpcSignalEventArgs e) { count++; }; ch1["name"].OnEvent += handler; ch1.RaiseLocal("name"); Assert.AreEqual(1, count); ch1["name"].OnEvent -= handler; ch1.RaiseLocal("name"); Assert.AreEqual(1, count); } }
public void TestChannelRaiseLocalInCallTrue() { bool wasInCall = false; using (IpcEventChannel channel = new IpcEventChannel(_registrar, _channel)) { channel["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e) { wasInCall = true; }; channel.RaiseLocal("Test", new string[0]); } Assert.IsTrue(wasInCall); }
public void TestIpcEventArgs() { Exception error = null; using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel)) using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel)) { ch1.StartListening("ch1"); bool recieved = false; ch1.OnError += delegate(object o, ErrorEventArgs e) { error = e.GetException(); }; ch1["TestArgs"].OnEvent += delegate(object o, IpcSignalEventArgs e) { recieved = true; Assert.AreEqual(ch1, o); Assert.AreEqual(ch1, e.EventChannel); Assert.AreEqual("TestArgs", e.EventName); Assert.AreEqual("1,2,3", String.Join(",", e.Arguments)); e.Arguments[0] = "a"; Assert.AreEqual("1,2,3", String.Join(",", e.Arguments)); }; recieved = false; ch1.RaiseLocal("TestArgs", "1", "2", "3"); Assert.IsTrue(recieved); if (error != null) { throw new AssertionException("Event Raised Error", error); } recieved = false; sender.Broadcast(100, "TestArgs", "1", "2", "3"); ch1.StopListening(1000); Assert.IsTrue(recieved); if (error != null) { throw new AssertionException("Event Raised Error", error); } } }
public void TestRaiseLocalUnknown() { using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel)) ch1.RaiseLocal("UnknownName"); }