public void Test_Caching_With_Timeout()
        {
            if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")
            {
                return;
            }

            var clock = new OffsetClock("2017-04-25", "2017-04-25");
            var cache = new StringCacheMem();

            // Populate cache
            {
                var mgr = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, cache);
                MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, LicenseStrings.EliteSubscriptionRemote,
                                                  null);

                var conf = new MockConfig(mgr, clock, new [] { "R_Elite", "R4Elite" }, new List <KeyValuePair <string, string> >());

                conf.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                mgr.WaitForTasks();

                var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));

                Assert.Empty(mgr.GetIssues());
                Assert.NotNull(conf.GetLicensesPage());
            }

            // Use cache
            {
                var mgr = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, cache)
                {
                    SkipHeartbeatsIfDiskCacheIsFresh = 0
                };
                MockHttpHelpers.MockRemoteLicenseException(mgr, WebExceptionStatus.NameResolutionFailure);

                var conf = new MockConfig(mgr, clock, new [] { "R_Elite", "R4Elite" }, new List <KeyValuePair <string, string> >());
                try {
                    conf.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                    conf.FireHeartbeat();
                    mgr.WaitForTasks();

                    var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);
                    Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));


                    Assert.NotNull(conf.GetLicensesPage());

                    Assert.Single(mgr.GetIssues());
                } catch {
                    output.WriteLine(conf.GetLicensesPage());
                    throw;
                }
            }
        }
        public void Test_Remote_License_Success()
        {
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")))
            {
                return;
            }
            var clock       = new OffsetClock("2017-04-25", "2017-04-25");
            var mgr         = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
            Uri invokedUri  = null;
            var httpHandler = MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, LicenseStrings.EliteSubscriptionRemote,
                                                                (r, c) => { invokedUri = r.RequestUri; });
            var conf = new MockConfig(mgr, clock, new [] { "R_Elite" }, new List <KeyValuePair <string, string> >());

            try {
                conf.AddLicense(LicenseStrings.EliteSubscriptionPlaceholder);

                Assert.Single(mgr.GetAllLicenses());
                Assert.True(mgr.GetAllLicenses().First().IsRemote);
                conf.FireHeartbeat();

                mgr.WaitForTasks();
                Assert.Empty(mgr.GetIssues());

                Mock.Verify(httpHandler);
                Assert.StartsWith(
                    "https://s3-us-west-2.amazonaws.com/licenses.imazen.net/v1/licenses/latest/",
                    invokedUri.ToString());


                Assert.NotNull(mgr.GetAllLicenses().First().FetchedLicense());

                var result = new Computation(conf, ImazenPublicKeys.Test, mgr, mgr, clock, true);

                Assert.True(result.LicensedForRequestUrl(new Uri("http://anydomain")));
                //TODO: Explore why WaitForTasks() can sometimes return 1
                mgr.WaitForTasks();
                Assert.Empty(mgr.GetIssues());
                Assert.NotNull(conf.GetLicensesPage());
            } catch {
                output.WriteLine(conf.GetLicensesPage());
                throw;
            }
        }