示例#1
0
 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"));
 }
示例#2
0
        public void EventsOnSingletonComponentsWorkGlobally()
        {
            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>("Singleton");
                var proxy2 = conn2.CreateProxy<ISampleServer>("Singleton");
                var proxy3 = conn3.CreateProxy<ISampleServer>("Singleton");

                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);
            }
        }
示例#3
0
        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;
        }