Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 117 lines (101 sloc) 3.57 kb
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
1 // ReSharper disable InconsistentNaming
2
3 using NUnit.Framework;
4 using RabbitMQ.Client;
5
6 namespace EasyNetQ.Tests
7 {
8 [TestFixture]
9 public class When_using_default_conventions
10 {
11 private Conventions conventions;
12
13 [SetUp]
14 public void SetUp()
15 {
16 conventions = new Conventions();
17 }
18
19 [Test]
20 public void The_default_exchange_naming_convention_should_use_the_TypeNameSerializers_Serialize_method()
21 {
67cb0cb @mikehadlow No need to call myDelegate.Invoke(arg), can use myDelegate(arg). Some ti...
mikehadlow authored
22 var result = conventions.ExchangeNamingConvention(typeof (TestMessage));
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
23 result.ShouldEqual(TypeNameSerializer.Serialize(typeof (TestMessage)));
24 }
25
26 [Test]
91e1e7b @mikehadlow Topic based routing implementation
mikehadlow authored
27 public void The_default_topic_naming_convention_should_return_an_empty_string()
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
28 {
67cb0cb @mikehadlow No need to call myDelegate.Invoke(arg), can use myDelegate(arg). Some ti...
mikehadlow authored
29 var result = conventions.TopicNamingConvention(typeof (TestMessage));
91e1e7b @mikehadlow Topic based routing implementation
mikehadlow authored
30 result.ShouldEqual("");
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
31 }
32
33 [Test]
34 public void The_default_queue_naming_convention_should_use_the_TypeNameSerializers_Serialize_method_then_an_underscore_then_the_subscription_id()
35 {
36 const string subscriptionId = "test";
67cb0cb @mikehadlow No need to call myDelegate.Invoke(arg), can use myDelegate(arg). Some ti...
mikehadlow authored
37 var result = conventions.QueueNamingConvention(typeof (TestMessage), subscriptionId);
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
38 result.ShouldEqual(TypeNameSerializer.Serialize(typeof (TestMessage)) + "_" + subscriptionId);
39 }
40 }
41
42 [TestFixture]
43 public class When_publishing_a_message
44 {
45 private RabbitBus bus;
67cb0cb @mikehadlow No need to call myDelegate.Invoke(arg), can use myDelegate(arg). Some ti...
mikehadlow authored
46 private string createdExchangeName;
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
47 private string publishedToExchangeName;
48 private string publishedToTopic;
49
50 [SetUp]
51 public void SetUp()
52 {
53 var mockModel = new MockModel
54 {
55 ExchangeDeclareAction = (exchangeName, type, durable, autoDelete, arguments) => createdExchangeName = exchangeName,
56 BasicPublishAction = (exchangeName, topic, properties, messageBody) =>
57 {
58 publishedToExchangeName = exchangeName;
59 publishedToTopic = topic;
60 }
61 };
62
63
64 var customConventions = new Conventions
65 {
66 ExchangeNamingConvention = x => "CustomExchangeNamingConvention",
67cb0cb @mikehadlow No need to call myDelegate.Invoke(arg), can use myDelegate(arg). Some ti...
mikehadlow authored
67 QueueNamingConvention = (x, y) => "CustomQueueNamingConvention",
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
68 TopicNamingConvention = x => "CustomTopicNamingConvention"
69 };
70 CreateBus(customConventions, mockModel);
efdaf4d @mikehadlow Removed Publish methods from IBus
mikehadlow authored
71 using (var publishChannel = bus.OpenPublishChannel())
72 {
73 publishChannel.Publish(new TestMessage());
74 }
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
75 }
76
77 private void CreateBus(Conventions conventions, IModel model)
78 {
c77f5e5 @mikehadlow Completed refactoring of RabbitBus. Now uses RabbitAdvancedBus internall...
mikehadlow authored
79 var advancedBus = new RabbitAdvancedBus(
80 new MockConnectionFactory(new MockConnection(model)),
81 TypeNameSerializer.Serialize,
82 new JsonSerializer(),
83 new MockConsumerFactory(),
84 new MockLogger(),
85 CorrelationIdGenerator.GetCorrelationId,
86 conventions
87 );
88
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
89 bus = new RabbitBus(
90 x => TypeNameSerializer.Serialize(x.GetType()),
91 new MockLogger(),
c77f5e5 @mikehadlow Completed refactoring of RabbitBus. Now uses RabbitAdvancedBus internall...
mikehadlow authored
92 conventions,
93 advancedBus
f12347c @ChrisEdwards Added ability to use custom conventions for naming exchanges and queues.
ChrisEdwards authored
94 );
95 }
96
97 [Test]
98 public void Should_use_exchange_name_from_conventions_to_create_the_exchange()
99 {
100 createdExchangeName.ShouldEqual("CustomExchangeNamingConvention");
101 }
102
103 [Test]
104 public void Should_use_exchange_name_from_conventions_as_the_exchange_to_publish_to()
105 {
106 publishedToExchangeName.ShouldEqual("CustomExchangeNamingConvention");
107 }
108
109 [Test]
110 public void Should_use_topic_name_from_conventions_as_the_topic_to_publish_to()
111 {
112 publishedToTopic.ShouldEqual("CustomTopicNamingConvention");
113 }
114 }
115 }
116
117 // ReSharper restore InconsistentNaming
Something went wrong with that request. Please try again.