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 TestOrder()
        {
            ConnectionCache cache = new ConnectionCache();

            // set to some high number
            const int      highNumber = ConnectionCache.CAPACITY + 100;
            ConnectionInfo expectedMostRecentConnection = null;

            // Full cache with lastUsage values in reverse order (to force sorting).
            // Intentionally add one more than will fit in the cache
            for (int i = ConnectionCache.CAPACITY; i >= 0; i--)
            {
                ConnectionInfo newConnectionInfo = GetConnectionInfo(i + highNumber);
                cache.AddToCache(newConnectionInfo);

                if (expectedMostRecentConnection == null)
                {
                    expectedMostRecentConnection = newConnectionInfo;
                }
                AssertExpectedMostRecent(cache, expectedMostRecentConnection);
            }

            // Add a new ConnectionInfo with a newer time--GetMostRecentConnectionInfo should update
            ConnectionInfo newerConnection = GetConnectionInfo(2 * highNumber);

            cache.AddToCache(newerConnection);
            AssertExpectedMostRecent(cache, newerConnection);

            // Revise a ConnectionInfo with an even newer time--GetMostRecentConnectionInfo should update
            newerConnection.SetLastUsage(newerConnection.LastUsage.AddDays(1));
            cache.AddToCache(newerConnection);
            AssertExpectedMostRecent(cache, newerConnection);
        }
        public void ToConfigString_MatchesExpectedString()
        {
            // Note: This test might break if the serialization order changes
            ConnectionCache cache = new ConnectionCache();

            cache.AddToCache(GetConnectionInfo(1, true));
            cache.AddToCache(GetConnectionInfo(2, true));
            string configString = cache.ToConfigString();

            Assert.AreEqual(KnownConfigString, configString);
        }
        public void TestCapacity()
        {
            ConnectionCache cache = new ConnectionCache();

            for (int i = 0; i < ConnectionCache.CAPACITY; i++)
            {
                cache.AddToCache(GetConnectionInfo(i));
                Assert.AreEqual(i + 1, cache.GetCachedConnections().Count());
            }

            // add one more over capacity
            cache.AddToCache(GetConnectionInfo(ConnectionCache.CAPACITY));
            Assert.AreEqual(ConnectionCache.CAPACITY, cache.GetCachedConnections().Count());
        }