コード例 #1
0
        public async Task Send10000EnvelopesAsync()
        {
            // Arrange
            var count     = 10000;
            var envelopes = Enumerable
                            .Range(0, count)
                            .Select(i => Dummy.CreateMessage(Dummy.CreateTextContent()));

            var receivedEnvelopes = Enumerable
                                    .Range(0, count)
                                    .Select(i => _serverTcpTransport.ReceiveAsync(_cancellationToken))
                                    .ToArray();

            // Act
            var sw = Stopwatch.StartNew();

            foreach (var envelope in envelopes)
            {
                await _clientTcpTransport.SendAsync(envelope, _cancellationToken);
            }

            await Task.WhenAll(receivedEnvelopes);

            sw.Stop();

            // Assert
            sw.ElapsedMilliseconds.ShouldBeLessThan(count * 2);
        }