Beispiel #1
0
 public void Unsubscribe(MockSubscription sub)
 {
     lock (locker)
     {
         if (!subStrings.Contains(sub.Subject))
         {
             throw new Exception("No subscription found on subject: " + sub.Subject);
         }
         subStrings.Remove(sub.Subject);
         subs.Remove(sub);
     }
 }
Beispiel #2
0
        public IAsyncSubscription SubscribeAsync(string subject, EventHandler <MsgHandlerEventArgs> handler)
        {
            lock (locker)
            {
                if (failNextSubscription)
                {
                    failNextSubscription = false;
                    throw new Exception("Failing subscription as requested.");
                }
                if (subStrings.Contains(subject))
                {
                    throw new Exception("Already subscribing to subject: " + subject);
                }

                subStrings.Add(subject);

                MockSubscription sub = new MockSubscription(this, subject, handler);
                subs.Add(sub);

                return(sub);
            }
        }