浏览代码

PeerDirectoryClient: should_support_null_binding_keys_in_subscriptions_for_types

Olivier Coanet 11 年之前
父节点
当前提交
286d9a62ea

+ 13 - 0
src/Abc.Zebus.Tests/Directory/PeerDirectoryClientTests.cs

@@ -694,6 +694,19 @@ namespace Abc.Zebus.Tests.Directory
             _directory.GetPeersHandlingMessage(new OtherFakeEvent3(4)).ExpectedSingle().Id.ShouldEqual(_otherPeer.Id);
         }
 
+        [Test]
+        public void should_support_null_binding_keys_in_subscriptions_for_types()
+        {
+            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(true)));
+
+            _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow.AddTicks(1), new MessageTypeId(typeof(FakeEvent)), BindingKey.Empty));
+            _directory.GetPeersHandlingMessage(new FakeEvent(0)).ShouldNotBeEmpty();
+
+            Assert.DoesNotThrow(() => _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow.AddTicks(1), new MessageTypeId(typeof(FakeEvent)), null)));
+
+            _directory.GetPeersHandlingMessage(new FakeEvent(0)).ShouldBeEmpty();
+        }
+
         [Test]
         public void should_ignore_outdated_subscriptions_by_type()
         {

+ 3 - 1
src/Abc.Zebus/Directory/PeerDirectoryClient.PeerEntry.cs

@@ -66,7 +66,9 @@ namespace Abc.Zebus.Directory
                 {
                     foreach (var subscriptionsForType in subscriptionsForTypes)
                     {
-                        SetSubscriptionsForType(subscriptionsForType.MessageTypeId, subscriptionsForType.BindingKeys, timestampUtc);
+                        var messageTypeId = subscriptionsForType.MessageTypeId;
+                        var bindingKeys = subscriptionsForType.BindingKeys ?? Enumerable.Empty<BindingKey>();
+                        SetSubscriptionsForType(messageTypeId, bindingKeys, timestampUtc);
                     }
                 }
             }