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")); }
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")); }
public void GetType_ShouldFailPreconditionsIfPassedNullUri() { var sut = new MessageTypeRegistry(); Uri uri = null; Assert.Throws <ArgumentException>(() => sut.GetType(uri)); }
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); } } } }
public void GetType_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws<SkuttException>(() => sut.GetType(new Uri("http://www.google.com"))); }
public void GetType_ShouldFailPreconditionsIfPassedNullUri() { var sut = new MessageTypeRegistry(); Uri uri = null; Assert.Throws<ArgumentException>(() => sut.GetType(uri)); }
public void GetType_ShouldThrowWhenNoRegistryAdded() { var sut = new MessageTypeRegistry(); Assert.Throws <SkuttException>(() => sut.GetType(new Uri("http://www.google.com"))); }