public void PassEventSubscriptionToRepository()
        {
            this.eventResourceToSubscribeTo = string.Format("match", this.eventId);
            this.eventSubscriptionMessage = new EventSubscriptionMessage(this.eventClientId, this.eventResourceToSubscribeTo);

            this.externalEventSubscriber.Subscribe(this.eventSubscriptionMessage);

            this.repository.Verify(x => x.Add(It.IsAny<AlwaysNotifyingEventSubscription>()));
        }
        public EventSubscription Subscribe(EventSubscriptionMessage subscriptionMessage)
        {
            foreach (var resourceMatcher in this.resourceToDomainIdentityMatcherFactory.GetResourceMatchers())
            {
                var subscription = resourceMatcher.CreateSubscription(
                    subscriptionMessage.EventResource,
                    subscriptionMessage.Subscriber);

                if (!(subscription is NoMatchingEventSubscription))
                {
                    this.subscriptionRepository.Add(subscription);
                    return subscription;
                }
            }

            throw new CouldNotFindMatchingSubscriptionForResourceException();
        }
        public void RemoveSubscriptionFromRepositoryWhenUnsubscribeCalled()
        {
            this.eventResourceToSubscribeTo = string.Format("match", this.eventId);
            this.eventSubscriptionMessage = new EventSubscriptionMessage(this.eventClientId, this.eventResourceToSubscribeTo);
            var subscription = this.externalEventSubscriber.Subscribe(this.eventSubscriptionMessage);

            this.externalEventSubscriber.Unsubscribe(subscription.Id);

            this.repository.Verify(x => x.Remove(subscription.Id));
        }
        public void ThrowCouldNotFindMAtchingSubscriptionMessageIfNoMatchCanBeFound()
        {
            this.eventResourceToSubscribeTo = string.Format("nomatch", this.eventId);
            this.eventSubscriptionMessage = new EventSubscriptionMessage(this.eventClientId, this.eventResourceToSubscribeTo);

            try
            {
                this.externalEventSubscriber.Subscribe(this.eventSubscriptionMessage);
                Assert.Fail();
            }
            catch (CouldNotFindMatchingSubscriptionForResourceException)
            {

            }
        }
        public void ReturnTheSubscription()
        {
            this.eventResourceToSubscribeTo = string.Format("match", this.eventId);
            this.eventSubscriptionMessage = new EventSubscriptionMessage(this.eventClientId, this.eventResourceToSubscribeTo);
            var returnedValue = this.externalEventSubscriber.Subscribe(this.eventSubscriptionMessage);

            Assert.AreEqual(this.eventSubscriptionId, returnedValue.Id);
        }