Skip to content

Commit 0d2fd2e

Browse files
authored
Do not allow to pass null topic to IPublishConfiguration (#853)
* Clean up fluent configuration * Do not allow to set nulls
1 parent 2c9cbea commit 0d2fd2e

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

Source/EasyNetQ.Tests/FluentConfiguration/PublishConfigurationTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ public void Should_throw_if_default_topic_is_null()
1313
}
1414

1515
[Fact]
16-
public void Should_return_default_topic()
16+
public void Should_throw_if_customer_topic_is_null()
1717
{
1818
var configuration = new PublishConfiguration("default");
19+
Assert.Throws<ArgumentNullException>(() => configuration.WithTopic(null));
20+
}
1921

20-
configuration.WithTopic(null);
21-
22+
[Fact]
23+
public void Should_return_default_topic()
24+
{
25+
var configuration = new PublishConfiguration("default");
2226
Assert.Equal("default", configuration.Topic);
2327
}
2428

@@ -32,4 +36,4 @@ public void Should_return_custom_topic()
3236
Assert.Equal("custom", configuration.Topic);
3337
}
3438
}
35-
}
39+
}

Source/EasyNetQ/FluentConfiguration/IPublishConfiguration.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
2-
3-
namespace EasyNetQ.FluentConfiguration
1+
namespace EasyNetQ.FluentConfiguration
42
{
53
/// <summary>
64
/// Allows publish configuration to be fluently extended without adding overloads to IBus
7-
///
5+
///
86
/// e.g.
97
/// x => x.WithTopic("*.brighton").WithPriority(2)
108
/// </summary>
@@ -41,13 +39,11 @@ public interface IPublishConfiguration
4139

4240
public class PublishConfiguration : IPublishConfiguration
4341
{
44-
private readonly string defaultTopic;
45-
4642
public PublishConfiguration(string defaultTopic)
4743
{
4844
Preconditions.CheckNotNull(defaultTopic, "defaultTopic");
4945

50-
this.defaultTopic = defaultTopic;
46+
Topic = defaultTopic;
5147
}
5248

5349
public IPublishConfiguration WithPriority(byte priority)
@@ -58,6 +54,8 @@ public IPublishConfiguration WithPriority(byte priority)
5854

5955
public IPublishConfiguration WithTopic(string topic)
6056
{
57+
Preconditions.CheckNotNull(topic, "topic");
58+
6159
Topic = topic;
6260
return this;
6361
}
@@ -75,16 +73,8 @@ public IPublishConfiguration WithQueueName(string queueName)
7573
}
7674

7775
public byte? Priority { get; private set; }
78-
79-
private string topic;
80-
81-
public string Topic
82-
{
83-
get { return topic ?? defaultTopic; }
84-
private set { topic = value; }
85-
}
86-
76+
public string Topic { get; private set; }
8777
public int? Expires { get; private set; }
8878
public string QueueName { get; private set; }
8979
}
90-
}
80+
}

Source/EasyNetQ/FluentConfiguration/IRequestConfiguration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace EasyNetQ.FluentConfiguration
1+
namespace EasyNetQ.FluentConfiguration
62
{
73
/// <summary>
84
/// Allows request configuration to be fluently extended without adding overloads to IBus

Source/EasyNetQ/FluentConfiguration/ISubscriptionConfiguration.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32

43
namespace EasyNetQ.FluentConfiguration
54
{

0 commit comments

Comments
 (0)