Ejemplo n.º 1
0
 public void announced_messages_should_be_delivered_to_all_who_have_expressed_interest_in_that_message_type()
 {
     var test_subject = new MailRoom();
     var log = store_silly_values();
     test_subject.subscribe<SillyMessage>(log.accept);
     test_subject.announce_and_wait(new SillyMessage("1"), TimeSpan.FromMilliseconds(50));
     test_subject.announce_and_wait(new SillyMessage("2"), TimeSpan.FromMilliseconds(50));
     log.received.Should()
         .ContainInOrder(new object[] {"1", "2"});
 }
Ejemplo n.º 2
0
 public void announce_and_wait_should_time_out_but_not_cancel_tasks_if_tasks_never_finish()
 {
     var test_subject = new MailRoom();
     test_subject.subscribe<SillyMessage>(message_handler_that_never_finishes);
     test_subject.announce_and_wait(new SillyMessage("hi"), TimeSpan.FromMilliseconds(10))
         .Should()
         .BeFalse();
     _log.Should()
         .ContainInOrder(new object[] {"Notified: hi"});
 }
Ejemplo n.º 3
0
 public void announce_and_wait_should_only_return_after_all_recipients_have_completed()
 {
     var test_subject = new MailRoom();
     test_subject.subscribe<SillyMessage>(message_handler_that_finishes);
     test_subject.announce_and_wait(new SillyMessage("hi"), TimeSpan.FromMilliseconds(50))
         .Should()
         .BeTrue();
     _log.Should()
         .ContainInOrder(new object[] {"Notified: hi", "Finished: hi"});
 }
Ejemplo n.º 4
0
 public void universal_subscribers_should_receive_all_messages()
 {
     var test_subject = new MailRoom();
     var log = store_all_values();
     test_subject.subscribe_to_all(log.accept);
     test_subject.announce(new SillyMessage("silly"));
     test_subject.announce_and_wait(new SeriousMessage("serious"), TimeSpan.Zero);
     log.received.Should()
         .ContainInOrder(new object[] {"silly", "serious"});
 }
Ejemplo n.º 5
0
 public void subscribing_for_a_message_while_processing_that_message_should_result_in_new_subscriber_not_receiving_message()
 {
     var test_subject = new MailRoom();
     test_subject.subscribe<SillyMessage>(new RecursiveSubscriber(3, test_subject, _log).subscribe_recursively_until_counter_expires);
     test_subject.subscribe<SillyMessage>(new RecursiveSubscriber(3, test_subject, _log).subscribe_recursively_until_counter_expires);
     test_subject.announce_and_wait(new SillyMessage("hi"), TimeSpan.FromMilliseconds(100))
         .Should()
         .BeTrue();
     _log.Should()
         .ContainInOrder(new object[] {"Counted 3: hi", "Counted 3: hi"});
 }
Ejemplo n.º 6
0
 public void subscribers_should_only_get_messages_they_asked_for()
 {
     var test_subject = new MailRoom();
     var log = store_silly_values();
     test_subject.subscribe<SillyMessage>(log.accept);
     test_subject.announce_and_wait(new SillyMessage("silly"), TimeSpan.FromMilliseconds(50));
     test_subject.announce_and_wait(new SeriousMessage("serious"), TimeSpan.FromMilliseconds(50));
     log.received.Should()
         .ContainInOrder(new object[] {"silly"});
 }