public void If_wont_send_incommingMessages_until_we_call_StartForwarding()
 {
     var repo = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>());
     var sut = new MessageForwarder(StringExtension.RandomString(), repo, new ServiceEvents(), new TransparentQuota());
     (3).Times(new Action(() => sut.AddMessage(StringExtension.RandomString())));
     Thread.Sleep(100);
     repo.Value.DidNotReceive().SendMessages(Arg.Any<NotNullOrWhiteSpaceString>(), Arg.Any<NotNullable<IEnumerable<NotNullOrWhiteSpaceString>>>());
 }
 public void It_sends_added_Messages_on_a_background_thread()
 {
     var repo = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>());
     var sut = new MessageForwarder(StringExtension.RandomString(), repo, new ServiceEvents(), new TransparentQuota());
     (3).Times(new Action(() => sut.AddMessage(StringExtension.RandomString())));
     sut.StartForwarding();
     Thread.Sleep(200);
     repo.Value.Received().SendMessages(Arg.Any<NotNullOrWhiteSpaceString>(), Arg.Any<NotNullable<IEnumerable<NotNullOrWhiteSpaceString>>>());
 }
 public IMessageForwarder CreateForwarder(NotNullOrWhiteSpaceString topic)
 {
     var fordwarder = _forwarders
                         .Where(f => f.Topic.Equals(topic, StringComparison.OrdinalIgnoreCase))
                         .FirstOrDefault();
     if(fordwarder == null)
     {
         fordwarder = new MessageForwarder(
             topic,
             new NotNullable<IMomRepository>(_momRepository),
             new NotNullable<IServiceEvents>(_mediator),
             _quotaFactory.CreateQuota(topic) 
         );
         _forwarders.Add(fordwarder);
     }
     return fordwarder;
 }
        public void When_a_message_is_sent_it_sends_a_sentMessage_to_the_mediator()
        {
            List<string> messages = new List<string>(StringExtension.RandomStrings(4));
            List<string> receivedMessages = new List<string>();

            var repo = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>());
            var mediator = new ServiceEvents();
            mediator.SentIncommingMessageSequence.Subscribe(s=> receivedMessages.Add(s));
            var topic = StringExtension.RandomString();
            var sut = new MessageForwarder(topic, repo, mediator, new TransparentQuota());

            sut.StartForwarding();
            messages.ForEach(m => sut.AddMessage(m));
            Thread.Sleep(200);
            Assert.Equal(messages.Count, receivedMessages.Count);
            messages.ForEach(m => Assert.True(receivedMessages.Contains(m)));
        }
 public void GetTopic_returns_the_messageForwarder_topic()
 {
     var repo = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>());
     var mediator = new ServiceEvents();
     var topic = StringExtension.RandomString();
     var forwarder = new MessageForwarder(topic, repo, mediator, new TransparentQuota());
     Assert.Equal(forwarder.Topic, topic);
 }