public void TestOrder() { ConnectionCache cache = new ConnectionCache(); // set to some issue number int highNumber = ConnectionCache.CAPACITY + 100; // fill up with sequential high last-usage values for (int i = 1; i <= ConnectionCache.CAPACITY; i++) { cache.AddToCache(GetConnectionInfo(i + highNumber)); } var highestExpected = $"http://fake.fake/{highNumber + ConnectionCache.CAPACITY}"; // add connections with low last-usage values, verify that // the most recent connection is still the highest value from the // initial population for (int i = 1; i < ConnectionCache.CAPACITY; i++) { // add connection with low last-usage value cache.AddToCache(GetConnectionInfo(i)); var mostRecent = cache.GetMostRecentConnection(); Assert.IsTrue(mostRecent.ServerUri.Equals(highestExpected)); } // adding one more should bump out original highest value cache.AddToCache(GetConnectionInfo(0)); Assert.IsFalse(cache.GetMostRecentConnection().ServerUri.Equals(highestExpected)); }
public void Ctor_ConfigStringIsValidJson_CacheIsCorrect() { ConnectionCache cache = new ConnectionCache(KnownConfigString); List <Uri> connections = cache.GetCachedConnections().ToList(); Assert.AreEqual(2, connections.Count); ConnectionInfo info1 = GetConnectionInfo(1, true); ConnectionInfo info2 = GetConnectionInfo(2, true); CompareConnectionInfos(info1, cache.GetMostRecentConnection(info1.ServerUri)); CompareConnectionInfos(info2, cache.GetMostRecentConnection(info2.ServerUri)); }
private void AssertExpectedMostRecent(ConnectionCache cache, ConnectionInfo expectedMostRecent) { ConnectionInfo actualMostRecent = cache.GetMostRecentConnection(); Assert.AreEqual(expectedMostRecent.ServerUri, actualMostRecent.ServerUri); Assert.AreEqual(expectedMostRecent.LastUsage, actualMostRecent.LastUsage); }
public void TestEmpty() { ConnectionCache cache = new ConnectionCache(); Assert.IsNull(cache.GetMostRecentConnection()); }