public void TestSubscriptionOfMultipleObservers()
        {
            using (IMessageStreamReader streamReader = new JsonMessageStreamReader(this.BaseStream))
            {
                Mock <IObserver <IMessageEnvelope> > observerMock1 = new Mock <IObserver <IMessageEnvelope> >();
                Mock <IObserver <IMessageEnvelope> > observerMock2 = new Mock <IObserver <IMessageEnvelope> >();

                using (ManualResetEventSlim observerMock1Sync = new ManualResetEventSlim())
                {
                    using (ManualResetEventSlim observerMock2Sync = new ManualResetEventSlim())
                    {
                        observerMock1.Setup(x => x.OnCompleted()).Callback(() =>
                        {
                            observerMock1Sync.Set();
                        });

                        observerMock2.Setup(x => x.OnCompleted()).Callback(() =>
                        {
                            observerMock2Sync.Set();
                        });

                        IConnectableObservable <IMessageEnvelope> observable = (from messageEnvelope in streamReader
                                                                                select messageEnvelope).Publish();

                        observable.Subscribe(observerMock1.Object);
                        observable.Subscribe(observerMock2.Object);

                        observable.Connect();

                        observerMock1Sync.Wait();
                        observerMock2Sync.Wait();

                        observerMock1.Verify(x => x.OnNext(It.IsAny <IMessageEnvelope>()), Times.Exactly(this.Messages.Count));
                        observerMock2.Verify(x => x.OnNext(It.IsAny <IMessageEnvelope>()), Times.Exactly(this.Messages.Count));
                    }
                }
            }
        }
        public void TestSubscriptionOfSingleObserver()
        {
            using (IMessageStreamReader streamReader = new JsonMessageStreamReader(this.BaseStream))
            {
                Mock <IObserver <IMessageEnvelope> > observerMock = new Mock <IObserver <IMessageEnvelope> >();

                using (ManualResetEventSlim sync = new() )
                {
                    observerMock.Setup(x => x.OnCompleted()).Callback(() =>
                    {
                        sync.Set();
                    });

                    using (IDisposable subscription = streamReader.Subscribe(observerMock.Object))
                    {
                        sync.Wait();

                        observerMock.Verify(x => x.OnNext(It.IsAny <IMessageEnvelope>()), Times.Exactly(this.Messages.Count));

                        Assert.IsNotNull(subscription);
                    }
                }
            }
        }