public async Task CanRemoveTimedOut() { // Arrange var timeoutSeconds = 5; var inactiveSessions = new List <Session>(); var activeSessions = new List <Session>(); var sessionTracker = new SessionTracker(new NullLogger <SessionTracker>(), new TimeSpan(0, 0, 0, timeoutSeconds), DefaultTimeoutCheckInterval); var game = Helpers.GetOrCreateGame("CanRemoveTimedOut"); for (var i = 0; i < 5; i++) { var user = Helpers.GetOrCreateUser($"CanRemoveTimedOut_ShouldRemove_{i}"); var session = sessionTracker.StartSession(game.Id, user.Id); inactiveSessions.Add(session); } await Task.Delay(timeoutSeconds * 1000); for (var i = 0; i < 5; i++) { var user = Helpers.GetOrCreateUser($"CanRemoveTimedOut_ShouldNotRemove_{i}"); var session = sessionTracker.StartSession(game.Id, user.Id); activeSessions.Add(session); } // Act sessionTracker .GetType() .GetMethod("RemoveTimedOut", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(sessionTracker, null); // Assert inactiveSessions.ForEach(s => Assert.False(sessionTracker.IsActive(s.Id))); activeSessions.ForEach(s => Assert.True(sessionTracker.IsActive(s.Id))); }