Пример #1
0
        public void MultipleReadAttemptsTest()
        {
            //test that multiple attempts to read when the first read operation has not finished triggers an error

            var buffer = new ReadWriteBuffer(0);

            var writeBuffer = Guid.NewGuid().ToByteArray();
            var readBuffer  = new byte[writeBuffer.Length];

            buffer.ReadAsync(readBuffer, 0, readBuffer.Length);

            Assert.Catch <InvalidOperationException>(() => buffer.ReadAsync(readBuffer, 0, readBuffer.Length));
        }
Пример #2
0
        public async Task ReadThenWriteTest()
        {
            var buffer = new ReadWriteBuffer(0);

            var writeBuffer = Guid.NewGuid().ToByteArray();
            var readBuffer  = new byte[writeBuffer.Length];

            var read = buffer.ReadAsync(readBuffer, 0, readBuffer.Length);

            await buffer.Fill(new MemoryStream(writeBuffer), writeBuffer.Length, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(readBuffer.Length, await read.ConfigureAwait(false));
            Assert.AreEqual(new Guid(writeBuffer), new Guid(readBuffer));
        }