Browse Source

Add missing unit test for CqlPeerRepository.RemoveAllDynamicSubscriptionsForPeer

Olivier Coanet 10 years ago
parent
commit
76b08d9927

+ 21 - 2
src/Abc.Zebus.Directory.Cassandra.Tests/Storage/CqlPeerRepositoryTests.DynamicSubscriptions.cs

@@ -304,6 +304,25 @@ namespace Abc.Zebus.Directory.Cassandra.Tests.Storage
                 CreateSubscriptionFor<FakeCommand>()
             });
         }
-    }
-}
 
+        [Test]
+        public void should_use_specified_timestamp_to_remove_dynamic_subscriptions()
+        {
+            var peer = _peer1.ToPeerDescriptor(true);
+            var subscriptionsForType = CreateSubscriptionsForType<FakeCommand>(new BindingKey("X"));
+
+            _repository.AddOrUpdatePeer(peer);
+            _repository.AddDynamicSubscriptionsForTypes(peer.PeerId, peer.TimestampUtc.Value.AddMilliseconds(1), new[] { subscriptionsForType });
+
+            using (SystemDateTime.Set(utcNow: DateTime.UtcNow.AddHours(1)))
+            {
+                _repository.RemoveAllDynamicSubscriptionsForPeer(peer.PeerId, peer.TimestampUtc.Value.AddMilliseconds(2));
+            }
+            
+            _repository.AddDynamicSubscriptionsForTypes(peer.PeerId, peer.TimestampUtc.Value.AddMilliseconds(3), new[] { subscriptionsForType });
+
+            var fetched = _repository.GetPeers().ExpectedSingle();
+            fetched.Subscriptions.ShouldNotBeEmpty();
+        }
+    }
+}

+ 1 - 2
src/Abc.Zebus.Directory.Cassandra/Storage/CqlPeerRepository.cs

@@ -1,5 +1,4 @@
-using Abc.Zebus.Directory.Cassandra.Cql;
-using Abc.Zebus.Directory.Storage;
+using Abc.Zebus.Directory.Storage;
 using Cassandra;
 using Cassandra.Data.Linq;
 using System;