Skip to content

Commit

Permalink
topicmetadata should allow adding empty strings (#940)
Browse files Browse the repository at this point in the history
* topicmetadata should allow adding empty strings
Signed-off-by: saberwang <saberwang@hotmail.com>

* fix test errors
Signed-off-by: saberwang <saberwang@hotmail.com>
  • Loading branch information
saber-wang authored Aug 29, 2022
1 parent 2ab1b7c commit 0998b0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Dapr.AspNetCore/TopicMetadataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TopicMetadataAttribute : Attribute, IOriginalTopicMetadata
public TopicMetadataAttribute(string name, string value)
{
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
ArgumentVerifier.ThrowIfNullOrEmpty(value, nameof(value));
ArgumentVerifier.ThrowIfNull(value, nameof(value));
Name = name;
Value = value;
}
Expand All @@ -44,7 +44,7 @@ public TopicMetadataAttribute(string id, string name, string value)
{
ArgumentVerifier.ThrowIfNullOrEmpty(id, nameof(name));
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
ArgumentVerifier.ThrowIfNullOrEmpty(value, nameof(value));
ArgumentVerifier.ThrowIfNull(value, nameof(value));
Id = id;
Name = name;
Value = value;
Expand Down
8 changes: 8 additions & 0 deletions test/Dapr.AspNetCore.IntegrationTest.App/DaprController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public void TopicMetadataSeparator()
{
}

[Topic("pubsub", "metadataseparatorbyemptytring")]
[HttpPost("/topicmetadataseparatorattrbyemptytring")]
[TopicMetadata("n1", "v1")]
[TopicMetadata("n1", "")]
public void TopicMetadataSeparatorByemptytring ()
{
}

[Topic("pubsub", "splitTopicAttr", true)]
[HttpPost("/splitTopics")]
public void SplitTopic()
Expand Down
4 changes: 2 additions & 2 deletions test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task SubscribeEndpoint_ReportsTopics()
var json = await JsonSerializer.DeserializeAsync<JsonElement>(stream);

json.ValueKind.Should().Be(JsonValueKind.Array);
json.GetArrayLength().Should().Be(17);
json.GetArrayLength().Should().Be(18);

var subscriptions = new List<(string PubsubName, string Topic, string Route, string rawPayload, string match, string metadata, string DeadLetterTopic)>();

Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task SubscribeEndpoint_ReportsTopics()
subscriptions.Should().Contain(("pubsub", "metadata", "multiMetadataTopicAttr", string.Empty, string.Empty, "n1=v1;n2=v2,v3", string.Empty));
subscriptions.Should().Contain(("pubsub", "metadata.1", "multiMetadataTopicAttr", "true", string.Empty, "n1=v1", string.Empty));
subscriptions.Should().Contain(("pubsub", "splitMetadataTopicBuilder", "splitMetadataTopics", string.Empty, string.Empty, "n1=v1;n2=v1", string.Empty));

subscriptions.Should().Contain(("pubsub", "metadataseparatorbyemptytring", "topicmetadataseparatorattrbyemptytring", string.Empty, string.Empty, "n1=v1,", string.Empty));
// Test priority route sorting
var eTopic = subscriptions.FindAll(e => e.Topic == "E");
eTopic.Count.Should().Be(3);
Expand Down

0 comments on commit 0998b0d

Please sign in to comment.