public void CanRegisterEventToPropertyRoute() { Package pkg = new Package(); OutComponent outComponent = new OutComponent(); InComponent inComponent = new InComponent(); EventToPropertyRoute route = EventToPropertyRoute.Create <TestEventArgs>(outComponent, "TestEventOut", inComponent, x => inComponent.TestEventArgsInProperty); pkg.RegisterEventRoute(route); Assert.IsTrue(pkg.RegisteredEventRoutes.Any()); pkg.UnregisterEventRoute(route); }
public void CanRegisterEventArgsRoute() { OutComponent outComponent = new OutComponent(); InComponent inComponent = new InComponent(); TestEventArgs e = new TestEventArgs("RouteOut", 100); EventToPropertyRoute route = EventToPropertyRoute.Create(outComponent, "TestEventOut", inComponent, x => inComponent.TestEventArgsInProperty); route.RegisterRoute(); if (!route.IsRegistered) { Assert.Fail("Route not registered."); } outComponent.RaiseTestEventOut(e); route.UnregisterRoute(); Assert.AreEqual(inComponent.TestEventArgsInProperty.EventInteger, e.EventInteger); }
public void CanRegisterEventArgsRouteWithReferenceConverter() { OutComponent outComponent = new OutComponent(); InComponent inComponent = new InComponent(); TestEventArgs e = new TestEventArgs("RouteOut", 100); TestEventArgsToStringRouteConverter converter = new TestEventArgsToStringRouteConverter(); EventToPropertyRoute route = EventToPropertyRoute.Create(outComponent, "TestEventOut", inComponent, x => inComponent.StringInProperty, converter); route.RegisterRoute(); if (!route.IsRegistered) { Assert.Fail("Route not registered."); } outComponent.RaiseTestEventOut(e); route.UnregisterRoute(); Assert.IsTrue(string.Compare(e.EventString, inComponent.StringInProperty, false) == 0); }
static void Main(string[] args) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); PublisherComponent publisher = new PublisherComponent(); MethodSubscriberComponent methodSubscriber = new MethodSubscriberComponent(); PropertySubscriberComponent propertySubscriber = new PropertySubscriberComponent(); EventToMethodRoute eventToMethodRoute = EventToMethodRoute.Create <EventArgs>(publisher, "IntervalEvent", methodSubscriber, (x) => methodSubscriber.ReceiveInterval(x)); EventToPropertyRoute eventToPropertyRoute = EventToPropertyRoute.Create(publisher, "IntervalEvent", propertySubscriber, x => propertySubscriber.ReceiveInterval); Package package = new Package("PubSub"); package.RegisterEventRoute(eventToMethodRoute); package.RegisterEventRoute(eventToPropertyRoute); Console.WriteLine("Preparing to publish... Please wait or press any key to exit."); Console.ReadKey(); package.UnregisterAll(); publisher.Dispose(); }