コード例 #1
0
ファイル: EventBrokerTests.cs プロジェクト: dhasenan/Yaeb
 public void PublishAnEventWithNoArgumentsToOneSubscriber()
 {
     var pub = new Publisher ();
     var sub = new Subscriber ();
     _target.Register (sub);
     _target.Register (pub);
     Assert.That (sub.callCount, Is.EqualTo (0));
     pub.TriggerEvent ();
     Assert.That (sub.callCount, Is.EqualTo (1));
 }
コード例 #2
0
ファイル: Class1.cs プロジェクト: fr33h8r/TestEvents
        public void check_evrthng()
        {
            var publisher = new Publisher();
            var subscriber1 = new Subscriber {Name = "boo1"};
            var subscriber2 = new Subscriber {Name = "boo2"};
            subscriber1.Subscribe(publisher);
            subscriber2.Subscribe(publisher);

            publisher.Send("foo");
            publisher.Send("f00000oo");
        }
コード例 #3
0
ファイル: EventBrokerTests.cs プロジェクト: dhasenan/Yaeb
 public void LowLevelSubscription()
 {
     var pub = new Publisher ();
     var sub1 = new Subscriber ();
     _target.AddSubscriber ("event1", sub1, sub1.GetType ().GetMethod ("EventHappened", BindingFlags.Public | BindingFlags.Instance));
     _target.Register (pub);
     Assert.That (sub1.callCount, Is.EqualTo (0));
     pub.TriggerEvent ();
     Assert.That (sub1.callCount, Is.EqualTo (1));
     Assert.That (sub1.callCount2, Is.EqualTo (0));
     Assert.That (sub1.callCount3, Is.EqualTo (0));
 }
コード例 #4
0
        static void Main(string[] args)
        {
			Publisher p = new Publisher();
			Subscriber s = new Subscriber();

			p.SimpleEvent += s.MethodA;
			p.SimpleEvent += s.MethodB;
			p.RaiseTheEvent();

			p.SimpleEvent -= s.MethodB;
			p.RaiseTheEvent();
		}
コード例 #5
0
        static void Main(string[] args)
        {
            Console.Write("Input seconds between publishing: ");
            int t = int.Parse(Console.ReadLine());
            Publisher publisher = new Publisher();
            Subscriber subscriber = new Subscriber("subscriber", publisher);

            while (true)
            {
                publisher.Greet();
                Thread.Sleep(t * 1000);
            }
        }
コード例 #6
0
ファイル: EventBrokerTests.cs プロジェクト: dhasenan/Yaeb
 public void LowLevelPublish()
 {
     var pub = new Publisher ();
     var sub1 = new Subscriber ();
     var sub2 = new Subscriber ();
     _target.Register (sub1);
     _target.Register (sub2);
     _target.AddPublisher(new string[]{"event2"}, pub, pub.GetType().GetEvent("Eventy", BindingFlags.Public | BindingFlags.Instance));
     Assert.That (sub1.callCount2, Is.EqualTo (0));
     Assert.That (sub2.callCount2, Is.EqualTo (0));
     pub.TriggerEvent ();
     Assert.That (sub1.callCount2, Is.EqualTo (1));
     Assert.That (sub2.callCount2, Is.EqualTo (1));
 }
コード例 #7
0
 static void Main(string[] args)
 {
     Broadcast b = new Broadcast();
     Subscriber s = new Subscriber();
     b.Event += s.SubscribedEvent;
     //b.Event += s.SubscribedEvent1;
     AddEventArgs ae = new AddEventArgs(10, 15);
     b.EventArgs += s.SubscribedEventArgs;
     b.EventArgsObj1 += s.SubscribedEventArgsObjJust;
     //b.Event2 += s.SubscribedFrameworkMethod;
    // b.Event2 += new EventHandler<EventArgs>(s.SubscribedFrameworkMethod);
     b.FireEvent(ae);
     //ExtendedBroadcast eb = new ExtendedBroadcast();
     //ExtendedSubscriber es = new ExtendedSubscriber();
     //eb.BroadcastEvent += new EventHandler<AddEventArgs>(es.AddMethod);
     //eb.OnFireEvent(new AddEventArgs(4, 5));
 }
コード例 #8
0
ファイル: Class1.cs プロジェクト: fr33h8r/TestEvents
        public void should_subscribe_to_publisher_and_save_message()
        {
            var publisher = Substitute.For<IPublisher>();
            var subscriber = new Subscriber();

            subscriber.Subscribe(publisher);

            const string someMessage = "some message";
            publisher.MessageSent += Raise.EventWith(new MsgEventArgs {Message = someMessage});

            subscriber.ReceivedMessage.Should().Be(someMessage);
        }