public async Task TestIfConnectionWillRestartAfterShutdown() { List <IServiceConnection> connections = new List <IServiceConnection> { new SimpleTestServiceConnection(), new SimpleTestServiceConnection() // A connection which is not in Connected status could be replaced. }; IServiceConnection connection = connections[1]; using TestServiceConnectionContainer container = new TestServiceConnectionContainer(connections, factory: new SimpleTestServiceConnectionFactory()); container.ShutdownForTest(); await container.OnConnectionCompleteForTestShutdown(connection); // connection should be replaced, but it's StartAsync method should not be called. Assert.NotEqual(container.Connections[1], connection); Assert.NotEqual(ServiceConnectionStatus.Connected, container.Connections[1].Status); }
internal async Task TestIfConnectionWillNotRestartAfterShutdown(ServiceConnectionStatus status) { List <IServiceConnection> connections = new List <IServiceConnection> { new SimpleTestServiceConnection(), new SimpleTestServiceConnection(status: status) }; IServiceConnection connection = connections[1]; using TestServiceConnectionContainer container = new TestServiceConnectionContainer(connections, factory: new SimpleTestServiceConnectionFactory()); container.ShutdownForTest(); await container.OnConnectionCompleteForTestShutdown(connection); // the connection should not be replaced when shutting down Assert.Equal(container.Connections[1], connection); // its status is not changed Assert.Equal(status, container.Connections[1].Status); // the container is not listening to the connection's status changes after shutdown Assert.Equal(1, (connection as SimpleTestServiceConnection).ConnectionStatusChangedRemoveCount); }