예제 #1
0
        /* Syntax checks */

        private void SyntaxChecks()
        {
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            // Create for EventHandler type — no generic parameters
            proxy.TestEvent += FilteredEventHandler.Create(TestEventHandler, new TestEventFilter());

            // Create for EventHandler<TEventArgs> type — single generic parameter for EventArgs type
            proxy.SampleEvent += FilteredEventHandler.Create <SampleEventArgs>(SampleEventHandler, new SampleEventFilter());

            // Create for custom event type — single generic parameter for delegate type
            proxy.CustomEvent += FilteredEventHandler.Create <CustomEventType>(CustomEventHandler, new CustomEventFilter());

            // AddFilter for EventHandler type — no generic parameters
            var testEventHandler = new EventHandler(TestEventHandler);

            testEventHandler = testEventHandler.AddFilter(new TestEventFilter());

            // AddFilter for EventHandler<TEventArgs> type — no generic parameters
            var sampleEventHandler = new EventHandler <SampleEventArgs>(SampleEventHandler);

            sampleEventHandler = sampleEventHandler.AddFilter(new SampleEventFilter());

            // AddFilter for EventHandler<TEventArgs> using Linq expression — no generic parameters
            sampleEventHandler = sampleEventHandler.AddFilter((sender, args) => args.Value != 1);
        }
예제 #2
0
        public void FilteredEventHandlerUsingCombinedFilter_TransformsEventsRemotely()
        {
            // prepare event handler
            var handledValue = default(SampleEventArgs);
            var handler      = new EventHandler <SampleEventArgs>((sender, args) => handledValue = args);

            // attach server-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.SampleEvent += handler
                                 .AddFilter(new SampleEventFilter(3, 5, 7), false)
                                 .AddFilter(new SampleEventFilter(9, 6, 3), false)
                                 .AddFilter(new SampleEventFilter(1, 2, 3), false)
                                 .AddFilter(new SampleEventFilter(5, 4, 3), false); // 3 will pass all filters

            // raise events, check results
            proxy.RaiseSampleEvent(321);             // filtered out
            Assert.IsNull(handledValue);

            proxy.RaiseSampleEvent(3);
            Assert.IsNotNull(handledValue);
            Assert.AreEqual(3, handledValue.Value);
            Assert.IsTrue(handledValue.IsTransformed);

            handledValue.Value = 111;
            proxy.RaiseSampleEvent(456);             // filtered out
            Assert.AreEqual(111, handledValue.Value);
        }
예제 #3
0
        public void FilteredEventHandlerUsingCombinedFilter_TransformsEventsLocally()
        {
            // prepare event handler
            var handledValue = default(SampleEventArgs);
            var handler      = new EventHandler <SampleEventArgs>((sender, args) => handledValue = args);

            // attach client-side event filter
            var sample = new SampleServer();

            sample.SampleEvent += handler
                                  .AddFilter(new SampleEventFilter(321, 123, 111))
                                  .AddFilter(new SampleEventFilter(333, 123, 222)); // 123 will pass both filters

            // raise events, check results
            sample.RaiseSampleEvent(321);             // filtered out
            Assert.IsNull(handledValue);

            sample.RaiseSampleEvent(123);
            Assert.IsNotNull(handledValue);
            Assert.AreEqual(123, handledValue.Value);
            Assert.IsTrue(handledValue.IsTransformed);

            handledValue.Value = 111;
            sample.RaiseSampleEvent(456);             // filtered out
            Assert.AreEqual(111, handledValue.Value);
        }
예제 #4
0
        public void SubscriptionUnsubscriptionWithEventFilters_RegressionTest2()
        {
            var handled              = false;
            var testEventHandler     = new EventHandler((s, e) => handled = true);
            var filteredEventHandler = testEventHandler.AddFilter(new TestEventFilter());

            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.TestEvent += filteredEventHandler;
            handled          = false;

            proxy.RaiseTestEvent();
            Assert.IsTrue(handled);

            proxy.TestEvent -= filteredEventHandler;             // unsubscription with filter
            handled          = false;

            proxy.RaiseTestEvent();
            Assert.IsFalse(handled);

            proxy.TestEvent += filteredEventHandler;
            handled          = false;

            proxy.RaiseTestEvent();
            Assert.IsTrue(handled);

            proxy.TestEvent -= testEventHandler;             // unsubscription without filter
            handled          = false;

            proxy.RaiseTestEvent();
            Assert.IsFalse(handled);
        }
예제 #5
0
        public void SubscriptionUnsubscriptionWithEventFilters_RegressionTest1()
        {
            var handled              = false;
            var sampleEventHandler   = new EventHandler <SampleEventArgs>((s, e) => handled = true);
            var filteredEventHandler = sampleEventHandler.AddFilter(new SampleEventFilter(1, 2, 3));

            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.SampleEvent += filteredEventHandler;
            handled            = false;

            proxy.RaiseSampleEvent(1);
            Assert.IsTrue(handled);

            proxy.SampleEvent -= sampleEventHandler;             // unsubscription without filter
            handled            = false;

            proxy.RaiseSampleEvent(2);
            Assert.IsFalse(handled);

            proxy.SampleEvent += filteredEventHandler;
            handled            = false;

            proxy.RaiseSampleEvent(3);
            Assert.IsTrue(handled);

            proxy.SampleEvent -= filteredEventHandler;             // unsubscription with filter
            handled            = false;

            proxy.RaiseSampleEvent(2);
            Assert.IsFalse(handled);
        }
예제 #6
0
        public void FilteredEventHandlerOfTypeEventHandler_FiltersEventsRemotely()
        {
            // prepare event handler
            var handled = false;
            var handler = new EventHandler((sender, args) => handled = true);

            // attach server-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.TestEvent += handler.AddFilter(new TestEventFilter(), false);

            // raise events, check results
            proxy.RaiseTestEvent(EventArgs.Empty);             // filtered out
            Assert.IsFalse(handled);

            proxy.RaiseTestEvent(null);
            Assert.IsTrue(handled);

            handled = false;
            proxy.RaiseTestEvent(new EventArgs());             // filtered out
            Assert.IsFalse(handled);
        }
예제 #7
0
        public void FilteredEventHandlerUsingFlexibleFilter_FiltersEventsRemotely()
        {
            // prepare event handler
            var handledValue = 0;
            var handler      = new EventHandler <SampleEventArgs>((sender, args) => handledValue = args.Value);

            // attach client-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.SampleEvent += handler.AddFilter((sender, args) => args.Value == 123, false);

            // raise events, check results
            proxy.RaiseSampleEvent(321);             // filtered out
            Assert.AreEqual(0, handledValue);

            proxy.RaiseSampleEvent(123);
            Assert.AreEqual(123, handledValue);

            handledValue = 111;
            proxy.RaiseSampleEvent(456);             // filtered out
            Assert.AreEqual(111, handledValue);
        }
예제 #8
0
        public void FilteredEventHandlerUsingFluentSyntax_FiltersEventsRemotely()
        {
            // prepare event handler
            var handledValue = 0;
            var handler      = new EventHandler <SampleEventArgs>((sender, args) => handledValue = args.Value);

            // attach server-side event filter
            var proxy = ZyanConnection.CreateProxy <ISampleServer>();

            proxy.SampleEvent += handler.AddFilter(new SampleEventFilter(123), false);

            // raise events
            proxy.RaiseSampleEvent(111);             // filtered out
            Assert.AreEqual(0, handledValue);

            proxy.RaiseSampleEvent(123);
            Assert.AreEqual(123, handledValue);

            handledValue = 222;
            proxy.RaiseSampleEvent(456);             // filtered out
            Assert.AreEqual(222, handledValue);
        }
예제 #9
0
        public void FilteredEventHandlerOfTypeEventHandler_FiltersEventsLocally()
        {
            // prepare event handler
            var handled = false;
            var handler = new EventHandler((sender, args) => handled = true);

            // attach client-side event filter
            var sample = new SampleServer();

            sample.TestEvent += handler.AddFilter(new TestEventFilter());

            // raise events, check results
            sample.RaiseTestEvent(EventArgs.Empty);             // filtered out
            Assert.IsFalse(handled);

            sample.RaiseTestEvent(null);
            Assert.IsTrue(handled);

            handled = false;
            sample.RaiseTestEvent(new EventArgs());             // filtered out
            Assert.IsFalse(handled);
        }
예제 #10
0
        public void FilteredEventHandlerUsingFlexibleFilter_FiltersEventsLocally()
        {
            // prepare event handler
            var handledValue = 0;
            var handler      = new EventHandler <SampleEventArgs>((sender, args) => handledValue = args.Value);

            // attach client-side event filter
            var sample = new SampleServer();

            sample.SampleEvent += handler.AddFilter((f, args) => args.Value == 123);

            // raise events, check results
            sample.RaiseSampleEvent(321);             // filtered out
            Assert.AreEqual(0, handledValue);

            sample.RaiseSampleEvent(123);
            Assert.AreEqual(123, handledValue);

            handledValue = 111;
            sample.RaiseSampleEvent(456);             // filtered out
            Assert.AreEqual(111, handledValue);
        }