Ejemplo n.º 1
0
        public void AddedMappingShouldBeRetrievableAsFromType()
        {
            //Arrange
            var sut = new MessageTypeRegistry();
            var uri = new Uri("http://messages.skutt.net/tests");

            //Act
            sut.Add<TestMessage>(uri);

            //Assert
            Assert.Equal(uri, sut.GetUri<TestMessage>());
            Assert.Equal(typeof(TestMessage), sut.GetType(uri));
            Assert.Equal(typeof(TestMessage), sut.GetType("http://messages.skutt.net/tests"));
        }
Ejemplo n.º 2
0
        public void AddedMappingShouldBeRetrievableAsFromType()
        {
            //Arrange
            var sut = new MessageTypeRegistry();
            var uri = new Uri("http://messages.skutt.net/tests");

            //Act
            sut.Add <TestMessage>(uri);

            //Assert
            Assert.Equal(uri, sut.GetUri <TestMessage>());
            Assert.Equal(typeof(TestMessage), sut.GetType(uri));
            Assert.Equal(typeof(TestMessage), sut.GetType("http://messages.skutt.net/tests"));
        }
Ejemplo n.º 3
0
        public void GetType_ShouldFailPreconditionsIfPassedNullUri()
        {
            var sut = new MessageTypeRegistry();
            Uri uri = null;

            Assert.Throws <ArgumentException>(() => sut.GetType(uri));
        }
Ejemplo n.º 4
0
        private void ProcessQueue(IConnection connection)
        {
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue, true, false, false, null);
                consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume(queue, false, consumer);

                while (true)
                {
                    var deliveryEventArgs = consumer.Queue.Dequeue() as BasicDeliverEventArgs;

                    if (deliveryEventArgs == null) // poison
                    {
                        Console.WriteLine("Poison message received.");
                        break;
                    }

                    var body        = deliveryEventArgs.Body;
                    var typeLen     = BitConverter.ToInt16(body, 0);
                    var messageType = registry.GetType(deliveryEventArgs.BasicProperties.Type);

                    if (messageType != null)
                    {
                        var serializedMessage = Encoding.UTF8.GetString(body, typeLen + 2,
                                                                        body.Length - typeLen - 2);
                        var messageObject = JsonConvert.DeserializeObject(serializedMessage, messageType);

                        queueAdd(messageObject);
                        channel.BasicAck(deliveryEventArgs.DeliveryTag, false);
                    }
                    else
                    {
                        //TODO messageHandler dead letter queue
                        channel.BasicReject(deliveryEventArgs.DeliveryTag, false);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void GetType_ShouldThrowWhenNoRegistryAdded()
        {
            var sut = new MessageTypeRegistry();

            Assert.Throws<SkuttException>(() => sut.GetType(new Uri("http://www.google.com")));
        }
Ejemplo n.º 6
0
 public void GetType_ShouldFailPreconditionsIfPassedNullUri()
 {
     var sut = new MessageTypeRegistry();
     Uri uri = null;
     Assert.Throws<ArgumentException>(() => sut.GetType(uri));
 }
Ejemplo n.º 7
0
        public void GetType_ShouldThrowWhenNoRegistryAdded()
        {
            var sut = new MessageTypeRegistry();

            Assert.Throws <SkuttException>(() => sut.GetType(new Uri("http://www.google.com")));
        }