コード例 #1
0
        public void StopMultiple()
        {
            // Setup: Create json rpc host and start it
            var mr = new Mock <MessageReader>(Stream.Null, null);
            var mw = new Mock <MessageWriter>(Stream.Null);
            var jh = new JsonRpcHost(GetChannelBase(mr.Object, mw.Object).Object);

            jh.Start();

            // If: I stop the JSON RPC host after stopping it
            // Then: I should get an exception
            jh.Stop();
            Assert.Throws <InvalidOperationException>(() => jh.Stop());
        }
コード例 #2
0
        public void StopBeforeStarting()
        {
            // If: I stop the JSON RPC host without starting it first
            // Then: I should get an exception
            var jh = new JsonRpcHost(GetChannelBase(null, null).Object);

            Assert.Throws <InvalidOperationException>(() => jh.Stop());
        }
コード例 #3
0
        public async Task WaitForExit()
        {
            // Setup: Create json rpc host and start it
            var mr = new Mock <MessageReader>(Stream.Null, null);
            var mw = new Mock <MessageWriter>(Stream.Null);
            var jh = new JsonRpcHost(GetChannelBase(mr.Object, mw.Object).Object);

            jh.Start();

            // If: I wait for JSON RPC host to exit and stop it
            // NOTE: We are wrapping this execution in a task to make sure we can properly stop the host
            Task waitForExit = Task.Run(() => { jh.WaitForExit(); });

            jh.Stop();

            // Then: The host should be stopped
            await waitForExit.WithTimeout(TimeSpan.FromSeconds(1));
        }
コード例 #4
0
        public async Task StartMultiple()
        {
            // Setup: Create mocked message reader and writer
            var mr = new Mock <MessageReader>(Stream.Null, null);
            var mw = new Mock <MessageWriter>(Stream.Null);

            // If:
            // ... I start a JSON RPC host
            var cb = GetChannelBase(mr.Object, mw.Object);
            var jh = new JsonRpcHost(cb.Object);

            jh.Start();

            // ... And I start it again
            // Then: I should get an exception
            Assert.Throws <InvalidOperationException>(() => jh.Start());

            // Cleanup: Stop the JSON RPC host
            jh.Stop();
            await Task.WhenAll(jh.consumeInputTask, jh.consumeOutputTask).WithTimeout(TimeSpan.FromSeconds(1));
        }
コード例 #5
0
        public async Task StartStop()
        {
            // Setup: Create mocked message reader and writer
            var mr = new Mock <MessageReader>(Stream.Null, null);
            var mw = new Mock <MessageWriter>(Stream.Null);

            // If: I start a JSON RPC host
            var cb = GetChannelBase(mr.Object, mw.Object);
            var jh = new JsonRpcHost(cb.Object);

            jh.Start();

            // Then: The channel protocol should have been
            cb.Verify(o => o.Start(), Times.Once);
            cb.Verify(o => o.WaitForConnection(), Times.Once);

            // If: I stop the JSON RPC host
            jh.Stop();

            // Then: The long running tasks should stop gracefully
            await Task.WhenAll(jh.consumeInputTask, jh.consumeOutputTask).WithTimeout(TimeSpan.FromSeconds(1));

            cb.Verify(o => o.Stop(), Times.Once);
        }