示例#1
0
 public void announce_should_return_after_all_recipients_have_been_notified_but_before_they_finish()
 {
     var test_subject = new MailRoom();
     test_subject.subscribe<SillyMessage>(message_handler_that_never_finishes);
     test_subject.announce(new SillyMessage("hi"));
     _log.Should()
         .ContainInOrder(new object[] {"Notified: hi"});
 }
示例#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"});
 }
示例#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"});
 }
示例#4
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"});
 }
示例#5
0
 public void mail_sent_to_a_mail_room_should_also_be_announced_to_all_more_central_mail_rooms()
 {
     var home_office = new MailRoom();
     var log = store_silly_values();
     var mail_target = home_office.create_satellite_office();
     home_office.subscribe<SillyMessage>(log.accept);
     mail_target.announce_and_wait(new SillyMessage("hi"), TimeSpan.FromMilliseconds(50));
     log.received.Should()
         .ContainInOrder(new object[] {"hi"});
 }
示例#6
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"});
 }
示例#7
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"});
 }