public void NullUrlValidation() { var protocol = new NullClientProtocolSetup(); Assert.IsTrue(protocol.IsUrlValid("null://NullChannel:1234/server")); Assert.IsFalse(protocol.IsUrlValid(null)); Assert.IsFalse(protocol.IsUrlValid(string.Empty)); Assert.IsFalse(protocol.IsUrlValid("null://")); Assert.IsFalse(protocol.IsUrlValid("null://NullChannel:/server")); }
public void EventsOnSingleCallComponentsWorkGlobally() { var nullProtocol = new NullClientProtocolSetup(); // start two new sessions using (var conn2 = new ZyanConnection(ZyanConnection.ServerUrl, nullProtocol)) using (var conn3 = new ZyanConnection(ZyanConnection.ServerUrl, nullProtocol)) { var proxy1 = ZyanConnection.CreateProxy <ISampleServer>("SingleCall"); var proxy2 = conn2.CreateProxy <ISampleServer>("SingleCall"); var proxy3 = conn3.CreateProxy <ISampleServer>("SingleCall"); var proxy1handled = false; var handler1 = new EventHandler((sender, args) => proxy1handled = true); proxy1.TestEvent += handler1; var proxy2handled = false; var handler2 = new EventHandler((sender, args) => proxy2handled = true); proxy2.TestEvent += handler2; var proxy3handled = false; var handler3 = new EventHandler((sender, args) => { proxy3handled = true; throw new Exception(); }); proxy3.TestEvent += handler3; proxy1.RaiseTestEvent(); Assert.IsTrue(proxy1handled); Assert.IsTrue(proxy2handled); Assert.IsTrue(proxy3handled); proxy1handled = false; proxy2handled = false; proxy3handled = false; proxy2.RaiseTestEvent(); Assert.IsTrue(proxy1handled); Assert.IsTrue(proxy2handled); Assert.IsFalse(proxy3handled); proxy1handled = false; proxy2handled = false; proxy3.RaiseTestEvent(); Assert.IsTrue(proxy1handled); Assert.IsTrue(proxy2handled); Assert.IsFalse(proxy3handled); } }
public void SessionVariablesAreStoredWithinTheCurrentSession() { var server = new NullServerProtocolSetup(123); var client = new NullClientProtocolSetup(); using (var host = new ZyanComponentHost("SessionSample", server)) { host.RegisterComponent <ISessionSample, SessionSample>(); using (var conn = new ZyanConnection(client.FormatUrl(123, "SessionSample"), client)) { var proxy = conn.CreateProxy <ISessionSample>(); proxy.Set("Hello", "World"); Assert.AreEqual("World", proxy.Get("Hello")); var temp = proxy.Get("Undefined"); Assert.IsNull(temp); proxy.Set("Undefined", "Defined"); Assert.AreEqual("Defined", proxy.Get("Undefined")); } } }
public void EventsWithArgumentsDerivedFromSessionBoundEvents_CanListenToOtherSessions() { var nullProtocol = new NullClientProtocolSetup(); // start two new sessions using (var conn2 = new ZyanConnection(ZyanConnection.ServerUrl, nullProtocol)) using (var conn3 = new ZyanConnection(ZyanConnection.ServerUrl, nullProtocol)) { var proxy1 = ZyanConnection.CreateProxy <ISampleServer>(); var proxy2 = conn2.CreateProxy <ISampleServer>(); var proxy3 = conn3.CreateProxy <ISampleServer>(); var sessions13 = new[] { ZyanConnection.SessionID, conn3.SessionID }; // session2 is not included var handled1 = 0; var handled2 = 0; var handled3 = 0; proxy1.CustomSessionBoundEvent += (s, args) => handled1 = args.Value; proxy2.CustomSessionBoundEvent += FilteredEventHandler.Create <CustomEventArgs>((s, args) => handled2 = args.Value, new SessionEventFilter(sessions13)); proxy3.CustomSessionBoundEvent += (s, args) => handled3 = args.Value; proxy1.RaiseCustomSessionBoundEvent(123); Assert.AreEqual(123, handled1); Assert.AreEqual(123, handled2); // proxy2 receives event from session1 Assert.AreEqual(0, handled3); proxy2.RaiseCustomSessionBoundEvent(321); Assert.AreEqual(123, handled1); Assert.AreEqual(123, handled2); // proxy2 doesn't receive events from session2 Assert.AreEqual(0, handled3); proxy3.RaiseCustomSessionBoundEvent(111); Assert.AreEqual(123, handled1); Assert.AreEqual(111, handled2); // proxy2 receives event from session3 Assert.AreEqual(111, handled3); } }
public static int RunTest() { var protocol = new NullClientProtocolSetup(); _connection = new ZyanConnection("null://NullChannel:1234/NullEventTest", protocol); _proxySingleton = _connection.CreateProxy <IEventComponentSingleton>(); _proxySingleCall = _connection.CreateProxy <IEventComponentSingleCall>(); _proxyCallbackSingleton = _connection.CreateProxy <ICallbackComponentSingleton>(); _proxyCallbackSingleCall = _connection.CreateProxy <ICallbackComponentSingleCall>(); _proxyRequestResponseSingleCall = _connection.CreateProxy <IRequestResponseCallbackSingleCall>(); int successCount = 0; _proxyCallbackSingleton.Out_Callback = CallBackSingleton; _proxyCallbackSingleCall.Out_Callback = CallBackSingleCall; _proxyCallbackSingleton.DoSomething(); if (_callbackCountSingleton == 1) { successCount++; Console.WriteLine("[NULL Channel] Singleton Callback Test passed."); } _proxyCallbackSingleCall.DoSomething(); if (_callbackCountSingleCall == 1) { successCount++; Console.WriteLine("[NULL Channel] SingleCall Callback Test passed."); } RegisterEvents(); if (_registrationsSingleton == _proxySingleton.Registrations) { successCount++; } if (_registrationsSingleCall == _proxySingleCall.Registrations) { successCount++; } _proxySingleton.TriggerEvent(); if (_firedCountSingleton == 1) { successCount++; Console.WriteLine("[NULL Channel] Singleton Event Test passed."); } _proxySingleCall.TriggerEvent(); if (_firedCountSingleCall == 1) { successCount++; Console.WriteLine("[NULL Channel] SingleCall Event Test passed."); } UnregisterEvents(); if (_registrationsSingleton == _proxySingleton.Registrations) { successCount++; } if (_registrationsSingleCall == _proxySingleCall.Registrations) { successCount++; } RequestResponseResult requestResponseResult = new RequestResponseResult("NULL Channel"); _proxyRequestResponseSingleCall.DoRequestResponse("Success", requestResponseResult.ReceiveResponseSingleCall); Thread.Sleep(1000); if (requestResponseResult.Count == 1) { successCount++; } _connection.Dispose(); if (successCount == 9) { return(0); } else { return(1); } }