public void SingleSubscriptionShouldOnlyCreateOneSubscription( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, string messageTypeString) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString, "1.0.0.0") }; sut.Subscribe(client, messageTypes); var subscriptions = storage.GetSubscriptions(messageTypes).ToList(); subscriptions.Should().HaveCount(messageTypes.Count); var subscription = subscriptions.First(); subscription.MessageType.Should().Be(messageTypes.First()); subscription.Clients.Should().HaveCount(1); subscription.Clients.First().Should().Be(client); }
public void SameClientSubscribesTwiceShouldOnlyCreateOneSubscribtion( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, string messageTypeString) { var client = new Address("testqueue.publisher", "localhost"); var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString, "1.0.0.0") }; sut.Subscribe(client, messageTypes); sut.Subscribe(client, messageTypes); var subscriptions = storage.GetSubscriptions(messageTypes).ToList(); subscriptions.Should().HaveCount(messageTypes.Count); var subscription = subscriptions.First(); subscription.MessageType.Should().Be(messageTypes.First()); subscription.Clients.Should().HaveCount(1); subscription.Clients.First().Should().Be(client); }
public void UnsubscribeWhenThereAreSubscriptionsShouldRemoveClientsAddress( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, Address otherClient1, Address otherClient2, string messageTypeString1) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), }; sut.Subscribe(client, messageTypes); sut.Subscribe(otherClient1, messageTypes); sut.Subscribe(otherClient2, messageTypes); sut.GetSubscriberAddressesForMessage(messageTypes).Should().HaveCount(3); sut.Unsubscribe(client, messageTypes); var clients = sut.GetSubscriberAddressesForMessage(messageTypes).ToList(); clients.Should().HaveCount(2); clients.First().Should().Be(otherClient1); clients.Last().Should().Be(otherClient2); }
public void BasicMongoSubscriptionStorageConstruction(MongoDatabaseFactory factory) { var sut = new MongoSubscriptionPersister(factory); }
public void UnsubscribeWhenClientSubscriptionIsTheOnlyOneShouldRemoveOnlyClient( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, string messageTypeString1) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), }; sut.Subscribe(client, messageTypes); storage.GetSubscriptions(messageTypes).Should().HaveCount(1); sut.GetSubscriberAddressesForMessage(messageTypes).Should().HaveCount(1); sut.Unsubscribe(client, messageTypes); storage.GetSubscriptions(messageTypes).Should().HaveCount(1); sut.GetSubscriberAddressesForMessage(messageTypes).Should().HaveCount(0); }
public void UnsubscribeFromAllMessages( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, string messageTypeString1, string messageTypeString2, string messageTypeString3) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), new MessageType(messageTypeString2, "1.0.0.0"), new MessageType(messageTypeString3, "1.0.0.0"), }; sut.Subscribe(client, messageTypes); storage.GetSubscriptions(messageTypes).Should().HaveCount(3); sut.Unsubscribe(client, messageTypes); storage.GetSubscriptions(messageTypes).ToList().ForEach(s => s.Clients.Should().HaveCount(0)); }
public void UnsubscribeWhenThereIsNoSubscriptionShouldNotCreateSubscription( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, string messageTypeString1) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), }; sut.Unsubscribe(client, messageTypes); storage.GetSubscriptions(messageTypes).Should().BeEmpty(); }
public void SubscribeTwoClientsOneMessageTypeShouldCreateOneSubscriptionWithMultipleAddresses( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client1, Address client2, string messageTypeString1) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), }; sut.Subscribe(client1, messageTypes); sut.Subscribe(client2, messageTypes); var clients = sut.GetSubscriberAddressesForMessage(messageTypes).ToList(); clients.Should().HaveCount(2); clients.Should().ContainSingle(a => client1 == a); clients.Should().ContainSingle(a => client2 == a); }
public void SubscribeTwoMessageTypesShouldCreateTwoSubscriptions( MongoSubscriptionPersister storage, MongoDatabaseFactory factory, Address client, string messageTypeString1, string messageTypeString2) { var sut = storage as ISubscriptionStorage; var messageTypes = new List<MessageType>() { new MessageType(messageTypeString1, "1.0.0.0"), new MessageType(messageTypeString2, "1.0.0.0") }; sut.Subscribe(client, messageTypes); var subscriptions = storage.GetSubscriptions(messageTypes).ToList(); subscriptions.Should().HaveCount(messageTypes.Count); subscriptions.ForEach(s => { s.Clients.Should().HaveCount(1); s.Clients.First().Should().Be(client); }); }