Esempio n. 1
0
        public void ReceiveTimeout__Throws()
        {
            var timeSpan = TimeSpan.FromMilliseconds(100);

            _socket.Options.ReceiveTimeout = timeSpan;
            _socket.Options.ReceiveTimeout.Should().Be(timeSpan);

            // try to receive a message without being connected
            Func <Message> receive = () => _socket.ReceiveMessage();

            receive.Should().Throw <TimeoutException>();
        }
Esempio n. 2
0
        public void SendMessageAsync__In_Parallel__Is_Synchronized()
        {
            var messages = new[] { "a", "b", "c" }.Select(x =>
            {
                var message = new Message();
                message.SetString(x);
                return(message);
            }).ToArray();

            // send the messages at the same time to verify they are sent in order because only one can be handled at a time
            var sendTasks = messages.Select(m => _clientAsyncContext.SendMessageAsync(m, CancellationToken.None)).ToArray();

            var receivedMessages = Enumerable.Range(0, messages.Length).Select(_ => _server.ReceiveMessage()).ToArray();

            receivedMessages.Should().HaveCount(3);
            var values = receivedMessages.Select(m => m.GetString()).ToArray();

            values[0].Should().Be("a");
            values[1].Should().Be("b");
            values[2].Should().Be("c");
        }