Exemplo n.º 1
0
        public async Task Return_One_Of_Many_Connections()
        {
            using (IWebHost host = TestServerHelper.CreateServer(out int port))
            {
                // arrange
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddWebSocketClient(
                    "Foo",
                    c => c.Uri = new Uri("ws://localhost:" + port));
                serviceCollection.AddWebSocketConnectionPool();
                IServiceProvider services =
                    serviceCollection.BuildServiceProvider();
                ISocketConnectionPool connectionPool =
                    services.GetRequiredService <ISocketConnectionPool>();
                await connectionPool.RentAsync("Foo");

                ISocketConnection connection =
                    await connectionPool.RentAsync("Foo");

                // act
                await connectionPool.ReturnAsync(connection);

                // assert
                Assert.False(connection.IsClosed);
            }
        }
Exemplo n.º 2
0
        public async Task Rent_Two_Connections()
        {
            using (IWebHost host = TestServerHelper.CreateServer(out int port))
            {
                // arrange
                var serviceCollection = new ServiceCollection();
                serviceCollection.AddWebSocketClient(
                    "Foo",
                    c => c.Uri = new Uri("ws://localhost:" + port));
                serviceCollection.AddWebSocketConnectionPool();
                IServiceProvider services =
                    serviceCollection.BuildServiceProvider();
                ISocketConnectionPool connectionPool =
                    services.GetRequiredService <ISocketConnectionPool>();
                ISocketConnection firstConnection =
                    await connectionPool.RentAsync("Foo");

                // act
                ISocketConnection secondConnection =
                    await connectionPool.RentAsync("Foo");

                // assert
                Assert.Equal(firstConnection, secondConnection);
            }
        }