Exemple #1
0
        public void UnsubscribeWhenClientSubscriptionIsTheOnlyOneShouldRemoveOnlyClient(
            MongoSubscriptionPersister storage,
            MongoDatabaseFactory factory,
            Subscriber subscriber,
            ContextBag context,
            string messageTypeString)
        {
            var sut         = storage as ISubscriptionStorage;
            var messageType = new MessageType(messageTypeString, "1.0.0.0");

            sut.Subscribe(subscriber, messageType, context).Wait();
            storage.GetSubscription(messageType).Result.Should().HaveCount(1);
            sut.GetSubscriberAddressesForMessage(new List <MessageType>()
            {
                messageType
            }, context)
            .Result.Should()
            .HaveCount(1);

            sut.Unsubscribe(subscriber, messageType, context).Wait();
            storage.GetSubscription(messageType).Result.Should().HaveCount(1);

            sut.GetSubscriberAddressesForMessage(new List <MessageType>()
            {
                messageType
            }, context)
            .Result.Should()
            .HaveCount(0);
        }
Exemple #2
0
        public void SubscribeTwoMessageTypesShouldCreateTwoDifferentSubscriptions(
            MongoSubscriptionPersister storage,
            MongoDatabaseFactory factory,
            Subscriber subscriber,
            ContextBag context,
            string messageTypeString1,
            string messageTypeString2)
        {
            var sut          = storage as ISubscriptionStorage;
            var messageType1 = new MessageType(messageTypeString1, "1.0.0.0");
            var messageType2 = new MessageType(messageTypeString2, "1.0.0.0");

            sut.Subscribe(subscriber, messageType1, context).Wait();
            sut.Subscribe(subscriber, messageType2, context).Wait();

            var subscriptions = storage.GetSubscription(messageType1).Result.ToList();

            subscriptions.Should().HaveCount(1);

            var subscription = subscriptions.First();

            subscription.Id.TypeName.Should().Be(messageType1.TypeName);
            subscription.Subscribers.Should().HaveCount(1);

            subscriptions = storage.GetSubscription(messageType2).Result.ToList();
            subscriptions.Should().HaveCount(1);

            subscription = subscriptions.First();
            subscription.Id.TypeName.Should().Be(messageType2.TypeName);
            subscription.Subscribers.Should().HaveCount(1);
        }
Exemple #3
0
        public void SameClientSubscribesTwiceShouldOnlyCreateOneSubscribtion(
            MongoSubscriptionPersister storage,
            MongoDatabaseFactory factory,
            Subscriber subscriber,
            ContextBag context,
            string messageTypeString)
        {
            var sut         = storage as ISubscriptionStorage;
            var messageType = new MessageType(messageTypeString, "1.0.0.0");

            sut.Subscribe(subscriber, messageType, context).Wait();
            sut.Subscribe(subscriber, messageType, context).Wait();

            var subscriptions = storage.GetSubscription(messageType).Result.ToList();

            subscriptions.Should().HaveCount(1);

            var subscription = subscriptions.First();

            subscription.Id.TypeName.Should().Be(messageType.TypeName);
            subscription.Subscribers.Should().HaveCount(1);

            var firstSubscriber = subscription.Subscribers.First();

            firstSubscriber.ShouldBeEquivalentTo(subscriber);
        }
Exemple #4
0
        public void UnsubscribeWhenThereIsNoSubscriptionShouldNotCreateSubscription(
            MongoSubscriptionPersister storage,
            MongoDatabaseFactory factory,
            Subscriber subscriber,
            ContextBag context,
            string messageTypeString)
        {
            var sut         = storage as ISubscriptionStorage;
            var messageType = new MessageType(messageTypeString, "1.0.0.0");

            sut.Unsubscribe(subscriber, messageType, context).Wait();

            var subscriptions = storage.GetSubscription(messageType).Result.ToList();

            subscriptions.Should().BeEmpty();
        }