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);
 }
 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_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>>>());
 }
Beispiel #4
0
 public void SendMessages(NotNullOrWhiteSpaceString topic, NotNullable<IEnumerable<NotNullOrWhiteSpaceString>> messages)
 {
     if (messages.Value.Count() == 1) SendMessage(topic, messages.Value.First());
     else
     {
         _producerFactory.CreateProducer(topic).Produce<string>(messages.Value.Select(m => m.Value).ToList(), topic);
     }
 }
        public IMessageForwardingService ProcessPendingMessages(NotNullable<IEnumerable<NotNullOrWhiteSpaceString>> pendingMessages)
        {
            pendingMessages
                .Value
                .ToList()
                .ForEach(m => AddMessage(m));

            return this;
        }
 public void When_a_message_is_sent_it_removes_the_message_from_the_repository()
 {
     var repository = new NotNullable<IIncommingMessageRepository>( Substitute.For<IIncommingMessageRepository>());
     var serviceEvents = new ServiceEvents();
     var sut = new MessageCleanerService(serviceEvents, repository);
     var message = new NotNullOrWhiteSpaceString(StringExtension.RandomString());
     serviceEvents.SentIncommingMessage(message);
     repository.Value.Received(1).Delete(message);
 }
 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 MessageForwarderFactory(
     NotNullable<IMomRepository> momRepository, 
     NotNullable<IServiceEvents> mediator, 
     NotNullable<IQuotaFactory> quotaFactory)
 { 
     _momRepository = momRepository.Value;
     _mediator = mediator.Value;
     _quotaFactory = quotaFactory.Value;
 }
 public void It_wont_process_any_incomming_message_until_we_call_StartListening()
 {
     var serializer = new NotNullable<IStringSerializer>(new JsonSerializer());
     var forwarderFactory = new MessageForwarderFactoryFake();
     var serviceEvents = new ServiceEvents();
     var sut = new MessageForwardingService(serializer, serviceEvents, forwarderFactory);
     serviceEvents.SavedIncommingMessage(GenerateMessages(1, "ATopic").Value.ElementAt(0));
     Assert.False(forwarderFactory.Forwarders.ContainsKey("ATopic"));
 }
 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);
 }
 public MessageForwardingService(
     NotNullable<IStringSerializer> messageSerializer, 
     NotNullable<IServiceEvents> hostMediator,
     NotNullable<IMessageForwarderFactory> messageForwarderFactory)
 {
     _messageSerializer = messageSerializer.Value;
     _messageForwarderFactory = messageForwarderFactory.Value;
     _forwarders = new List<IMessageForwarder>();
     _hostMediator = hostMediator.Value;
 }
 public MessageForwarder(
     NotNullOrWhiteSpaceString topic, 
     NotNullable<IMomRepository> momRepository,
     NotNullable<IServiceEvents> mediator,
     NotNullable<IQuota> quota)
 {
     _topic = topic;
     _momRepository = momRepository.Value;
     _mediator = mediator.Value;
     _quota = quota.Value;
 }
 public void when_called_StartListening_it_will_process_every_incommingEvent()
 {
     var serializer = new NotNullable<IStringSerializer>(new JsonSerializer());
     var forwarderFactory = new MessageForwarderFactoryFake();
     var serviceEvents = new ServiceEvents();
     var sut = new MessageForwardingService(serializer, serviceEvents, forwarderFactory);
     sut.StartListening();
     serviceEvents.SavedIncommingMessage(GenerateMessages(1, "ATopic").Value.ElementAt(0));
     Assert.NotNull(forwarderFactory.Forwarders["ATopic"]);
     forwarderFactory.Forwarders["ATopic"].Received(1).AddMessage(Arg.Any<string>());
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventID">The EventId of the message which was being processed</param>
 /// <param name="messageType">The MessageType of the message which was being processed</param>
 /// <param name="messageHandler">The Handler which tried to process the message</param>
 /// <param name="message">The exception message</param>
 /// <param name="exception">The catched exception</param>
 public ProcesedMessageException(
     Guid eventID, 
     NotNullOrWhiteSpaceString messageType, 
     NotNullOrWhiteSpaceString messageHandler,
     NotNullOrWhiteSpaceString message,
     NotNullable<Exception> exception)
     :base(message, exception)
 {
     EventID = eventID;
     MessageType = messageType;
     MessageHandler = messageHandler;
 }
Beispiel #15
0
        public HostLogger( 
            NotNullable<IServiceEvents> serviceEvents, 
            NotNullable<SynchronizationManagerEventTracing> eventTracing, 
            NotNullable<IHostConfiguration> configuration)
        {
            _eventTracing = eventTracing;
            serviceEvents.Value.IncommingEventSequence.Subscribe(LogIncomeMessage);
            serviceEvents.Value.ReceivedMessageEventSequence.Subscribe(LogReceivedMessage);
            serviceEvents.Value.ProcesedMessageEventSequence.Subscribe(LogProcessedMessage);
            serviceEvents.Value.ProcesedMessageExceptionSequence.Subscribe(LogProcessedMessageException);

        }
        public void It_can_process_pending_messages()
        {
            var serializer = new NotNullable<IStringSerializer>(new JsonSerializer());
            var forwarderFactory = new MessageForwarderFactoryFake();
            var serviceEvents = new ServiceEvents();
            var sut = new MessageForwardingService(serializer, serviceEvents, forwarderFactory);

            var messages = GenerateMessages(8, "oneTopic");
            sut.ProcessPendingMessages(messages);

            Assert.NotNull(forwarderFactory.Forwarders["oneTopic"]);
            forwarderFactory.Forwarders["oneTopic"].Received(messages.Value.Count()).AddMessage(Arg.Any<string>());
        }
 public void When_a_message_is_removed_emits_serviceEvent_DeletedIncommingMessage()
 {
     var repository = new NotNullable<IIncommingMessageRepository>(Substitute.For<IIncommingMessageRepository>());
     var serviceEvents = new ServiceEvents();
     var sut = new MessageCleanerService(serviceEvents, repository);
     var message = new NotNullOrWhiteSpaceString(StringExtension.RandomString());
     bool eventEmitted = false;
     serviceEvents.DeletedIncommingMessageSequence.Subscribe(new Action<NotNullOrWhiteSpaceString>(s =>
     {
         Assert.Equal(message.Value, s.Value);
         eventEmitted = true;
     }));
     serviceEvents.SentIncommingMessage(message);
     Assert.True(eventEmitted);
 }
        public void StopSendingMessages_stops_every_awakened_forwarder()
        {
            var serializer = new NotNullable<IStringSerializer>(new JsonSerializer());
            var forwarderFactory = new MessageForwarderFactoryFake();

            var serviceEvents = new ServiceEvents();
            var sut = new MessageForwardingService(serializer, serviceEvents, forwarderFactory);

            var messages = GenerateMessages(8);
            sut.ProcessPendingMessages(messages);
            sut.StopSendingMessages();

            Assert.True(forwarderFactory.Forwarders.Any());
            forwarderFactory.Forwarders.ToList().ForEach(item => item.Value.Received().StopForwarding());
        }
Beispiel #19
0
        public HostLogger(NotNullable<IStringSerializer> serializer, NotNullable<IServiceEvents> serviceEvents)
        {
            serviceEvents.Value.SavedIncommingMessageSequence.Subscribe(new Action<NotNullOrWhiteSpaceString>(s =>
            {
                string messageId = serializer.Value.Deserialize<BaseEvent>(s).EventID.ToString();
                MomProxyEventTracing.Log.Value.Message_saved_in_local_storage(
                    HostConfiguration.Instance.Value.ApplicationName, 
                    HostConfiguration.Instance.Value.MachineName,
                    messageId);
            }));
            serviceEvents.Value.SentIncommingMessageSequence.Subscribe(new Action<NotNullOrWhiteSpaceString>(s =>
            {
                string messageId = serializer.Value.Deserialize<BaseEvent>(s).EventID.ToString();
                MomProxyEventTracing.Log.Value.Message_send_to_MOM(
                    HostConfiguration.Instance.Value.ApplicationName,
                    HostConfiguration.Instance.Value.MachineName,
                    messageId);
            }));
            serviceEvents.Value.DeletedIncommingMessageSequence.Subscribe(new Action<NotNullOrWhiteSpaceString>(s =>
            {
                string messageId = serializer.Value.Deserialize<BaseEvent>(s).EventID.ToString();
                MomProxyEventTracing.Log.Value.Message_deleted_from_local_storage(
                    HostConfiguration.Instance.Value.ApplicationName,
                    HostConfiguration.Instance.Value.MachineName,
                    messageId);
            }));

            serviceEvents.Value.ReceivedMessageSequence.Subscribe(new Action<NotNullable<BaseEvent>>(@event =>
            {
                MomProxyEventTracing.Log.Value.Message_received(
                        HostConfiguration.Instance.Value.ApplicationName,
                        HostConfiguration.Instance.Value.MachineName,
                        @event.Value.Topic,
                        @event.Value.EventID.ToString(),
                        HostConfiguration.Instance.Value.ApplicationName
                        );
            }));
            serviceEvents.Value.ReceivedInvalidMessageSequence.Subscribe(new Action<NotNullable<BaseEvent>>((message) =>
            {
                MomProxyEventTracing.Log.Value.Invalid_Message_received(
                        HostConfiguration.Instance.Value.ApplicationName,
                        HostConfiguration.Instance.Value.MachineName,
                        message.Value.Topic ?? string.Empty,
                        message.Value.EventID.ToString(),
                        Enum.GetName(typeof(EInvalidMessageReason), message.Value.InvalidReason.Value)
                        );
            }));
        }
        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 bool Equals(TestModel other)
        {
            var sizes = true;

            if (Sizes != null && other.Sizes != null)
            {
                if (Sizes.Count == other.Sizes.Count)
                {
                    if (Sizes.Where((t, i) => !t.Equals(other.Sizes[i])).Any())
                    {
                        sizes = false;
                    }
                }
            }

            return(Id == other.Id && Name == other.Name && Age == other.Age && NotNullable.GetValueOrDefault() == other.NotNullable.GetValueOrDefault() && Nullable == other.Nullable && Weight == other.Weight && BoolValue == other.BoolValue && Gender == other.Gender && NullableGender == other.NullableGender &&
                   Created == other.Created && ((Country == null && other.Country == null) || Country.Equals(other.Country)) && sizes);
        }
Beispiel #22
0
 public ServiceResult<User> Login(NotNullable<UserCredentials> credentials)
 {
     ServiceResult<User>  result = null;
     var validation = _credentialValidator.Validate(credentials);
     if(validation.IsValid)
     {
         var user = _userRepository.LoadUser(credentials.Value.UserMail);
         if(user.Password.Equals(_hashGenerator.GenerateHash(credentials.Value.Password)))
         {
             result = new ServiceResult<User>(user);
         }
         else result = new ServiceResult<User>(new IServiceError[] { new UserOrPasswordDoesNotMatch() });
     }
     else
     {
         result = new ServiceResult<User>(validation.Errors.Select(v => v.CustomState as IServiceError));
     }
     return result;
 }
        public void It_routes_each_message_by_topic()
        {
            var serializer = new NotNullable<IStringSerializer>(new JsonSerializer());
            var forwarderFactory = new MessageForwarderFactoryFake();
            var serviceEvents = new ServiceEvents();
            var sut = new MessageForwardingService(serializer, serviceEvents, forwarderFactory);

            var messages = GenerateMessages(8);
            sut.ProcessPendingMessages(messages);
            var groupedTopics = messages.Value
                                            .GroupBy(m => serializer.Value.Deserialize<BaseEvent>(m).Topic)
                                            .Select(g => new {
                                                Name = g.Key,
                                                Count = g.Count()
                                            });
            Assert.NotEmpty(groupedTopics);
            groupedTopics.ToList().ForEach(topicCount =>
            {
                Assert.NotNull(forwarderFactory.Forwarders[topicCount.Name]);
                forwarderFactory.Forwarders[topicCount.Name].Received(topicCount.Count).AddMessage(Arg.Any<string>());
            });
        }
Beispiel #24
0
 public Media(NotNullable<byte[]> content, NotNullOrWhiteSpaceString mediaType)
 {
     Content = content;
     MediaType = mediaType;
 }
 public KafkaProducerFactory(NotNullable<IKafkaConfiguration> configuration)
 {
     _configuration = configuration;
 }
Beispiel #26
0
 public QuotaFactory(NotNullable<IHostConfiguration> hostConfiguration)
 {
     _hostConfiguration = hostConfiguration.Value;
 }
Beispiel #27
0
 public bool Equals(Size other)
 {
     return(Id == other.Id && Name == other.Name && Alias == other.Alias && NotNullable.GetValueOrDefault() == other.NotNullable.GetValueOrDefault() && Nullable == other.Nullable && SortOrder == other.SortOrder && BoolValue == other.BoolValue);
 }
Beispiel #28
0
 public ServiceResult<User> Register(NotNullable<UserRegistration> registration)
 {
     throw new NotImplementedException();
 }
 public MessageCleanerService(NotNullable<IServiceEvents> serviceEvents, NotNullable<IIncommingMessageRepository> repository)
 {
     serviceEvents.Value.SentIncommingMessageSequence.Subscribe(RemoveMessage);
     _repository = repository.Value;
     _serviceEvents = serviceEvents.Value;
 }
Beispiel #30
0
 public MomRepository(NotNullable<IKafkaProducerFactory> producerFactory)
 {
     _producerFactory = producerFactory.Value;
 }
Beispiel #31
0
 public TimeRangeQuota(NotNullable<TimeRange> timeRange)
 {
     _timeRange = timeRange.Value;
 }
 public void SendMessages(NotNullOrWhiteSpaceString topic, NotNullable<IEnumerable<NotNullOrWhiteSpaceString>> messages)
 {
     if (ReceivedSendMessages.ContainsKey(topic)) ReceivedSendMessages[topic].AddRange(messages.Value.Select(s => s.Value));
     else ReceivedSendMessages.Add(topic, messages.Value.Select(s => s.Value).ToList());
 }