public void ReliableMultiSubjectProxy_AsObserver_InvalidEnvironment()
        {
            Run(client =>
            {
                var env = new TestExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri      = new Uri("test://subject");
                var observer = new SubscriptionObserver <int>();
                var subject  = new TestSubject <int>(observer);
                env.AddArtifact(uri, subject);

                var proxy = new ReliableMultiSubjectProxy <int, int>(uri);
                var sub   = SubscribeRoot(Subscribable.Never <int>(), new ObserverToReliableObserver <int>(proxy.CreateObserver()));
                Assert.ThrowsException <InvalidOperationException>(() => new SubscriptionInitializeVisitor(sub).Initialize(ctx));
            });
        }
        public void ReliableMultiSubjectProxy_AsObserver()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var inputUri      = new Uri("test://stream/input");
                var outputUri     = new Uri("test://stream/output");
                var inputSubject  = new ReliableSubject <int>();
                var outputSubject = new ReliableSubject <int>();
                env.AddArtifact(inputUri, inputSubject);
                env.AddArtifact(outputUri, outputSubject);

                var inputProxy  = new ReliableMultiSubjectProxy <int, int>(inputUri);
                var outputProxy = new ReliableMultiSubjectProxy <int, int>(outputUri);
                var observer    = new MockObserver <int>(client);
                var inputSub    = SubscribeRoot(inputProxy.ToSubscribable(), new ObserverToReliableObserver <int>(outputProxy.CreateObserver()));
                var outputSub   = SubscribeRoot(outputProxy.ToSubscribable(), observer);
                new SubscriptionInitializeVisitor(inputSub).Initialize(ctx);
                new SubscriptionInitializeVisitor(outputSub).Initialize(ctx);

                var subjObsvr = inputSubject.CreateObserver();
                Schedule(client, 10, () => subjObsvr.OnNext(1, 0L));
                Schedule(client, 20, () => subjObsvr.OnNext(2, 1L));
                Schedule(client, 30, () => subjObsvr.OnNext(3, 2L));
                client.Start();

                observer.Messages.AssertEqual(
                    OnNext(10, 1),
                    OnNext(20, 2),
                    OnNext(30, 3)
                    );
            });
        }
        public void ReliableMultiSubjectProxy_AsObserver_AsOperator()
        {
            Run(client =>
            {
                var env = new TestReliableExecutionEnvironment();
                var ctx = client.CreateContext(env);

                var uri      = new Uri("test://subject");
                var observer = new OperatorObserver <int>();
                var subject  = new TestSubject <int>(observer);
                env.AddArtifact(uri, subject);

                var proxy = new ReliableMultiSubjectProxy <int, int>(uri);
                var sub   = SubscribeRoot(Subscribable.Never <int>(), new ObserverToReliableObserver <int>(proxy.CreateObserver()));
                new SubscriptionInitializeVisitor(sub).Initialize(ctx);
                Assert.IsTrue(observer.IsInputsCalled);
                Assert.IsTrue(observer.IsSetContextCalled);
                Assert.IsTrue(observer.IsStartCalled);

                sub.Dispose();
                Assert.IsTrue(observer.IsDisposeCalled);
            });
        }