public async void TestSiteLicense()
        {
            using (var contentRoot = new TempContentRoot()
                                     .AddResource("images/fire.jpg", "TestFiles.fire-umbrella-small.jpg"))
            {
                var clock = new FakeClock("2017-04-25", "2017-04-25");
                var set   = LicenseStrings.GetSets("SiteWideImageflow").First();
                var mgr   = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
                MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, set.Remote, null);
                var url       = new RequestUrlProvider();
                var licensing = new Licensing(mgr, url.Get);

                using var host = await StartAsyncWithOptions(new ImageflowMiddlewareOptions ()
                {
                    Licensing = licensing,
                    MyOpenSourceProjectUrl = null
                }
                                                             .SetLicenseKey (EnforceLicenseWith.Http402Error,
                                                                             set.Placeholder)
                                                             .MapPath("/", Path.Combine(contentRoot.PhysicalPath, "images")));

                // Create an HttpClient to send requests to the TestServer
                using var client = host.GetTestClient();

                mgr.WaitForTasks();

                Assert.Empty(mgr.GetIssues());


                url.Url = new Uri("https://acme.com");
                using var licensedResponse1 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse1.EnsureSuccessStatusCode();

                url.Url = new Uri("https://acmestaging.com");
                using var licensedResponse2 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse2.EnsureSuccessStatusCode();

                url.Url = new Uri("https://subdomain.acme.com");
                using var licensedResponse3 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse3.EnsureSuccessStatusCode();

                Assert.Empty(mgr.GetIssues());

                var page = licensing.Result.ProvidePublicLicensesPage();
                Assert.Contains("License Validation ON", page);
                Assert.Contains("License key valid for all domains.", page);
                Assert.Contains("No resale of usage. Only for organizations with less than 500 employees.", page);
                Assert.Contains("You are using EnforceLicenseWith.Http402Error", page);
                Assert.Contains("Manage your subscription at https://account.imazen.io", page);


                await host.StopAsync(CancellationToken.None);
            }
        }
        public async void TestRevocations()
        {
            using (var contentRoot = new TempContentRoot()
                                     .AddResource("images/fire.jpg", "TestFiles.fire-umbrella-small.jpg"))
            {
                // set clock to present, and build date to far future
                var clock = new FakeClock("2017-04-25", "2022-01-01");

                foreach (var set in LicenseStrings.GetSets("CancelledImageflow", "SoftRevocationImageflow",
                                                           "HardRevocationImageflow"))
                {
                    output.WriteLine($"Testing revocation for {set.Name}");
                    var mgr = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
                    MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, set.Remote, null);

                    var url       = new RequestUrlProvider();
                    var licensing = new Licensing(mgr, url.Get);

                    using var host = await StartAsyncWithOptions(new ImageflowMiddlewareOptions ()
                    {
                        Licensing = licensing,
                        MyOpenSourceProjectUrl = null
                    }
                                                                 .SetLicenseKey (EnforceLicenseWith.Http402Error,
                                                                                 set.Placeholder)
                                                                 .MapPath("/", Path.Combine(contentRoot.PhysicalPath, "images")));

                    // Create an HttpClient to send requests to the TestServer
                    using var client = host.GetTestClient();

                    mgr.WaitForTasks();


                    url.Url = new Uri("https://domain.com");
                    using var notLicensedResponse = await client.GetAsync("/fire.jpg?w=1");

                    Assert.Equal(HttpStatusCode.PaymentRequired, notLicensedResponse.StatusCode);

                    url.Url = null;
                    using var notLicensedResponse2 = await client.GetAsync("/fire.jpg?w=1");

                    Assert.Equal(HttpStatusCode.PaymentRequired, notLicensedResponse2.StatusCode);


                    Assert.NotEmpty(mgr.GetIssues());

                    var page = licensing.Result.ProvidePublicLicensesPage();
                    Assert.Contains("License Validation ON", page);
                    Assert.Contains("You are using EnforceLicenseWith.Http402Error", page);
                    Assert.Contains("No valid license keys found.", page);

                    Assert.Contains(
                        "Your license is invalid. Please renew your license via the management portal or purchase a new one at",
                        page);
                    Assert.DoesNotContain("Your license needs to be upgraded.", page);

                    if (set.Name == "CancelledImageflow")
                    {
                        Assert.Contains("Your subscription has lapsed; please renew to continue using product.", page);
                    }

                    if (set.Name == "SoftRevocationImageflow")
                    {
                        Assert.Contains(
                            "This license has been compromised; please contact Vendor Gamma for an updated license",
                            page);
                    }
                    if (set.Name == "HardRevocationImageflow")
                    {
                        Assert.Contains(
                            "Please contact support; the license was shared with an unauthorized party and has been revoked.",
                            page);
                    }



                    await host.StopAsync(CancellationToken.None);
                }
            }
        }
        public async void TestDomainsLicense()
        {
            using (var contentRoot = new TempContentRoot()
                                     .AddResource("images/fire.jpg", "TestFiles.fire-umbrella-small.jpg"))
            {
                var clock = new FakeClock("2017-04-25", "2017-04-25");
                var set   = LicenseStrings.GetSets("PerCore2DomainsImageflow").First();
                var mgr   = new LicenseManagerSingleton(ImazenPublicKeys.Test, clock, new StringCacheMem());
                MockHttpHelpers.MockRemoteLicense(mgr, HttpStatusCode.OK, set.Remote, null);
                var url       = new RequestUrlProvider();
                var licensing = new Licensing(mgr, url.Get);

                using var host = await StartAsyncWithOptions(new ImageflowMiddlewareOptions ()
                {
                    Licensing = licensing,
                    MyOpenSourceProjectUrl = null
                }
                                                             .SetLicenseKey (EnforceLicenseWith.Http402Error,
                                                                             set.Placeholder)
                                                             .MapPath("/", Path.Combine(contentRoot.PhysicalPath, "images")));

                // Create an HttpClient to send requests to the TestServer
                using var client = host.GetTestClient();

                mgr.WaitForTasks();

                Assert.Empty(mgr.GetIssues());

                url.Url = new Uri("https://unlicenseddomain.com");
                using var notLicensedResponse = await client.GetAsync("/fire.jpg?w=1");

                Assert.Equal(HttpStatusCode.PaymentRequired, notLicensedResponse.StatusCode);



                url.Url = new Uri("https://acme.com");
                using var licensedResponse1 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse1.EnsureSuccessStatusCode();

                url.Url = new Uri("https://acmestaging.com");
                using var licensedResponse2 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse2.EnsureSuccessStatusCode();

                url.Url = new Uri("https://subdomain.acme.com");
                using var licensedResponse3 = await client.GetAsync("/fire.jpg?w=1");

                licensedResponse3.EnsureSuccessStatusCode();

                Assert.Empty(mgr.GetIssues());

                var page = licensing.Result.ProvidePublicLicensesPage();
                Assert.Contains("License Validation ON", page);
                Assert.DoesNotContain("No license keys found.", page);
                Assert.Contains("License valid for 2 domains, missing for 1 domains", page);
                Assert.Contains("Your license needs to be upgraded", page);
                Assert.Contains("You are using EnforceLicenseWith.Http402Error", page);


                await host.StopAsync(CancellationToken.None);
            }
        }