コード例 #1
0
        private static async Task SubtestReadWriteMessageAsync(MessageStream stream, LengthPrefixStyle lps, Action reset)
        {
            var rand = new Random(Environment.TickCount);
            var msgs = Enumerable.Range(0, 64).Select(_ =>
            {
                var msg = new byte[ReaderWriterTests.GetMaxLength(lps, rand.Next(16, 1024))];
                rand.NextBytes(msg);
                return(msg);
            }).ToList();

            var tasks = msgs.Select(msg => stream.WriteMessageAsync(msg, CancellationToken.None));
            await Task.WhenAll(tasks);

            reset();

            foreach (var msg in msgs)
            {
                var msg2 = await stream.ReadMessageAsync(CancellationToken.None);

                Assert.That(msg2, Is.EqualTo(msg));
            }
        }