Пример #1
0
        public void Dispose_completes_pending_receive_and_causes_subsequent_send_and_receive_to_throw_ObjectDisposed()
        {
            Task <int>    receiveTask;
            MemoryChannel channel = new MemoryChannel();

            receiveTask = AssertTaskPending(channel.ReceiveAsync(new byte[1]));

            channel.Dispose();
            AssertTaskCompleted(0, receiveTask);

            Assert.Throws <ObjectDisposedException>(() => channel.Send(new byte[1]));
            Assert.Throws <ObjectDisposedException>(() => channel.ReceiveAsync(new byte[1]));
        }
Пример #2
0
        public void Pending_receive_followed_by_another_receive_throws_InvalidOperation_without_affecting_first_receive()
        {
            MemoryChannel channel = new MemoryChannel();

            byte[]     receiveBuffer = new byte[1];
            Task <int> receiveTask   = AssertTaskPending(channel.ReceiveAsync(receiveBuffer));

            byte[] receiveBuffer2 = new byte[1];
            Assert.Throws <InvalidOperationException>(() => channel.ReceiveAsync(receiveBuffer2));

            channel.Send(new byte[] { 1 });

            AssertTaskCompleted(1, receiveTask);
            Assert.Equal(new byte[] { 1 }, receiveBuffer);
        }
Пример #3
0
        public void Pending_receive_completes_after_send_with_greater_data_size_followed_by_another_receive_with_greater_data_size()
        {
            MemoryChannel channel = new MemoryChannel();

            byte[]     receiveBuffer = new byte[3];
            Task <int> receiveTask   = AssertTaskPending(channel.ReceiveAsync(receiveBuffer));

            channel.Send(new byte[] { 1, 2, 3, 4, 5 });

            AssertTaskCompleted(3, receiveTask);
            Assert.Equal(new byte[] { 1, 2, 3 }, receiveBuffer);

            byte[] receiveBuffer2 = new byte[3];
            AssertTaskCompleted(2, channel.ReceiveAsync(receiveBuffer2));
            Assert.Equal(new byte[] { 4, 5, 0 }, receiveBuffer2);
        }
Пример #4
0
        public void Dispose_after_create_causes_subsequent_send_and_receive_to_throw_ObjectDisposed()
        {
            MemoryChannel channel = new MemoryChannel();

            channel.Dispose();

            Assert.Throws <ObjectDisposedException>(() => channel.Send(new byte[1]));
            Assert.Throws <ObjectDisposedException>(() => channel.ReceiveAsync(new byte[1]));
        }
Пример #5
0
        public void Two_sends_then_three_receives_with_equal_data_size_completes_sync()
        {
            MemoryChannel channel = new MemoryChannel();

            channel.Send(new byte[] { 1, 2, 3 });
            channel.Send(new byte[] { 4, 5, 6 });

            byte[] receiveBuffer = new byte[2];
            AssertTaskCompleted(2, channel.ReceiveAsync(receiveBuffer));
            Assert.Equal(new byte[] { 1, 2 }, receiveBuffer);

            byte[] receiveBuffer2 = new byte[2];
            AssertTaskCompleted(2, channel.ReceiveAsync(receiveBuffer2));
            Assert.Equal(new byte[] { 3, 4 }, receiveBuffer2);

            byte[] receiveBuffer3 = new byte[2];
            AssertTaskCompleted(2, channel.ReceiveAsync(receiveBuffer3));
            Assert.Equal(new byte[] { 5, 6 }, receiveBuffer3);
        }
Пример #6
0
        public void Send_then_receive_with_greater_data_size_completes_sync()
        {
            MemoryChannel channel = new MemoryChannel();

            channel.Send(new byte[] { 1, 2, 3 });

            byte[] receiveBuffer = new byte[4];
            AssertTaskCompleted(3, channel.ReceiveAsync(receiveBuffer));
            Assert.Equal(new byte[] { 1, 2, 3, 0 }, receiveBuffer);
        }
Пример #7
0
        public void Pending_receive_completes_after_send_with_greater_data_size_followed_by_one_receive_to_read_excess_leaving_final_receive_pending()
        {
            MemoryChannel channel = new MemoryChannel();

            byte[]     receiveBuffer = new byte[3];
            Task <int> receiveTask   = AssertTaskPending(channel.ReceiveAsync(receiveBuffer));

            channel.Send(new byte[] { 1, 2, 3, 4, 5, 6 });

            AssertTaskCompleted(3, receiveTask);
            Assert.Equal(new byte[] { 1, 2, 3 }, receiveBuffer);

            byte[] receiveBuffer2 = new byte[3];
            AssertTaskCompleted(3, channel.ReceiveAsync(receiveBuffer2));
            Assert.Equal(new byte[] { 4, 5, 6 }, receiveBuffer2);

            byte[] receiveBuffer3 = new byte[1];
            AssertTaskPending(channel.ReceiveAsync(receiveBuffer3));
        }
Пример #8
0
        public void Two_sends_then_receive_with_equal_data_size_completes_sync()
        {
            MemoryChannel channel = new MemoryChannel();

            channel.Send(new byte[] { 1, 2, 3 });
            channel.Send(new byte[] { 4, 5, 6 });

            byte[] receiveBuffer = new byte[6];
            AssertTaskCompleted(6, channel.ReceiveAsync(receiveBuffer));
            Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6 }, receiveBuffer);
        }
Пример #9
0
        public void Pending_receive_completes_after_send_with_lower_data_size()
        {
            MemoryChannel channel = new MemoryChannel();

            byte[]     receiveBuffer = new byte[3];
            Task <int> receiveTask   = AssertTaskPending(channel.ReceiveAsync(receiveBuffer));

            channel.Send(new byte[] { 1, 2 });

            AssertTaskCompleted(2, receiveTask);
            Assert.Equal(new byte[] { 1, 2, 0 }, receiveBuffer);
        }