public async Task AcceptTransportAsync_MultipleConnections_RetunsTransports()
        {
            // Arrange
            await Target.StartAsync(CancellationToken);

            var count            = Dummy.CreateRandomInt(100) + 1;
            var clientTransports = Enumerable.Range(0, count)
                                   .Select(async i =>
            {
                var clientTransport = CreateClientTransport();
                await clientTransport.OpenAsync(ListenerUri, CancellationToken);
                return(clientTransport);
            })
                                   .ToList();

            // Act
            var acceptTasks = new List <Task <ITransport> >();

            while (count-- > 0)
            {
                acceptTasks.Add(
                    Task.Run(async() => await Target.AcceptTransportAsync(CancellationToken), CancellationToken));
            }

            await Task.WhenAll(acceptTasks);

            var actualTransports = acceptTasks.Select(t => t.Result).ToList();

            // Assert
            actualTransports.Count.ShouldBe(clientTransports.Count);
        }
        public async Task StartAsync_ValidHostAndPort_ServerStarted()
        {
            // Act
            await Target.StartAsync(CancellationToken);

            // Assert
            var acceptTransportTask = Target.AcceptTransportAsync(CancellationToken);
            var clientTransport     = CreateClientTransport();
            await clientTransport.OpenAsync(ListenerUri, CancellationToken);
        }
Esempio n. 3
0
        public async Task StartAsync_ValidHostAndPort_ServerStarted()
        {
            // Act
            await Target.StartAsync(CancellationToken);

            // Assert
            var acceptTransportTask = Target.AcceptTransportAsync(CancellationToken);
            var clientTransport     = new ClientWebSocketTransport(EnvelopeSerializer);
            await clientTransport.OpenAsync(ListenerUri, CancellationToken);
        }
Esempio n. 4
0
        public async Task AcceptTransportAsync_NewRequest_RetunsTransport()
        {
            // Act
            await Target.StartAsync();

            HttpTransportProvider.Raise(h => h.TransportCreated += null, new TransportEventArgs(Transport.Object));
            var transport = await Target.AcceptTransportAsync(CancellationToken);

            // Assert
            transport.ShouldBe(Transport.Object);
        }
Esempio n. 5
0
        public async Task AcceptTransportAsync_NewConnection_RetunsTransport()
        {
            // Arrange
            await Target.StartAsync();

            var clientTransport = new ClientWebSocketTransport(EnvelopeSerializer);
            await clientTransport.OpenAsync(ListenerUri, CancellationToken);

            // Act
            var transport = await Target.AcceptTransportAsync(CancellationToken);

            // Assert
            transport.ShouldNotBeNull();
        }
        public async Task AcceptTransportAsync_NewConnection_RetunsTransport()
        {
            // Arrange
            await Target.StartAsync(CancellationToken);

            var clientTransport = CreateClientTransport();


            // Act
            var acceptTransportTask = Target.AcceptTransportAsync(CancellationToken);
            await clientTransport.OpenAsync(ListenerUri, CancellationToken);

            var transport = await acceptTransportTask;

            // Assert
            transport.ShouldNotBeNull();
        }
 public async Task AcceptTransportAsync_ListenerNotStarted_ThrowsInvalidOperationException()
 {
     // Act
     var transport = await Target.AcceptTransportAsync(CancellationToken).ShouldThrowAsync <InvalidOperationException>();
 }