Exemplo n.º 1
0
        public async Task DisposeAsync_CallsClose_Success()
        {
            ConnectionCloseMethod?method = null;

            var con = new MockConnection();

            con.OnCloseAsyncCore = (m, t) =>
            {
                method = m;
                return(default(ValueTask));
            };

            await con.DisposeAsync();

            Assert.Equal(ConnectionCloseMethod.GracefulShutdown, method);
        }
Exemplo n.º 2
0
        public void CreatePipe_CalledOnce_Success()
        {
            int callCount = 0;

            var con = new MockConnection();

            con.OnCreatePipe = () =>
            {
                ++callCount;
                return(new MockPipe());
            };

            _ = con.Pipe;
            _ = con.Pipe;

            Assert.Equal(1, callCount);
        }
Exemplo n.º 3
0
        public void CreateStream_CalledOnce_Success()
        {
            int callCount = 0;

            var con = new MockConnection();

            con.OnCreateStream = () =>
            {
                ++callCount;
                return(new MemoryStream());
            };

            _ = con.Stream;
            _ = con.Stream;

            Assert.Equal(1, callCount);
        }
Exemplo n.º 4
0
        public void Dispose_CalledOnce_Success()
        {
            int callCount = 0;

            var con = new MockConnection();

            con.OnCloseAsyncCore = delegate
            {
                ++callCount;
                return(default(ValueTask));
            };

            con.Dispose();
            con.Dispose();

            Assert.Equal(1, callCount);
        }
Exemplo n.º 5
0
        public async Task WrappedStream_Success()
        {
            var bytesA = Encoding.ASCII.GetBytes("foo");
            var bytesB = Encoding.ASCII.GetBytes("bar");

            var stream = new MemoryStream();

            stream.Write(bytesA);
            stream.Position = 0;

            var con = new MockConnection();

            con.OnCreateStream = () => stream;

            IDuplexPipe pipe = con.Pipe;

            ReadResult res = await pipe.Input.ReadAsync();

            Assert.Equal(bytesA, res.Buffer.ToArray());

            await pipe.Output.WriteAsync(bytesB);

            Assert.Equal(bytesA.Concat(bytesB).ToArray(), stream.ToArray());
        }