Example #1
0
 public async Task When_receives_a_message_sends_it_to_the_mom()
 {
     try
     { 
         var momRepositoryFake = new MomRepositoryFake();
         var forwarderFactory = new MessageForwarderFactory(
             momRepositoryFake,
             ServiceEvents.Instance.Value,
             new QuotaFactory(HostConfiguration.Instance.Value)
         );
         var messageForwardingService = new MessageForwardingService(new JsonSerializer(), ServiceEvents.Instance.Value, forwarderFactory);
         using (HostService host = new HostService(messageForwardingService, new IncommingMessageRepository()))
         {
             host.Start();
             await MessageRequestHelper.DoRequest(_validMessage, HostConfiguration.Instance.Value.WebListenerPort);
             Thread.Sleep(1000);
             Assert.True(momRepositoryFake.ReceivedSendMessages.ContainsKey(_validMessage.Topic));
             Assert.Equal(momRepositoryFake.ReceivedSendMessages[_validMessage.Topic].Count, 1);
             Assert.Equal(momRepositoryFake.ReceivedSendMessages[_validMessage.Topic].First(), _serializer.Serialize<BaseEvent>(_validMessage));
         }
     }
     finally
     {
         File.Delete("PendingMessages");
     }
 }
 public void If_a_messageForwarder_for_a_given_topic_does_not_exist_creates_it()
 {
     NotNullable<IMomRepository> momRepository = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>()); 
     NotNullable<IServiceEvents> mediator = new ServiceEvents();
     NotNullable<IQuotaFactory> quotaFactory = new QuotaFactory(new HostConfiguration());
     var sut = new MessageForwarderFactory(momRepository, mediator, quotaFactory);
     Assert.NotNull(sut.CreateForwarder(StringExtension.RandomString()));
 }
 public void If_a_messageForwarder_for_a_given_topic_already_exist_returns_that_instance()
 {
     NotNullable<IMomRepository> momRepository = new NotNullable<IMomRepository>(Substitute.For<IMomRepository>());
     NotNullable<IServiceEvents> mediator = new ServiceEvents();
     NotNullable<IQuotaFactory> quotaFactory = new QuotaFactory(new HostConfiguration());
     var sut = new MessageForwarderFactory(momRepository, mediator, quotaFactory);
     var topic = StringExtension.RandomString();
     var forwarder = sut.CreateForwarder(topic);
     Assert.Same(sut.CreateForwarder(topic), forwarder);
 }
Example #4
0
        public HostService()
        {
            var kafkaProducerFactory = new KafkaProducerFactory(KafkaConfiguration.FromLocalFile("KafkaConfiguration.json"));
            var forwarderFactory = new MessageForwarderFactory(
                new MomRepository(kafkaProducerFactory),
                ServiceEvents.Instance.Value,
                new QuotaFactory(HostConfiguration.Instance.Value)
            );

            _messagesRepository = new IncommingMessageRepository();
            _messageForwardingService = new MessageForwardingService(new JsonSerializer(), ServiceEvents.Instance.Value, forwarderFactory);
            new MessageCleanerService(ServiceEvents.Instance.Value, _messagesRepository);
            _webApiHost = new WebAPISelfHost(HostConfiguration.Instance.Value.WebListenerPort);
        }