public void BindMoreSites()
        {
            SiteDomainHelper.AddSite("site1", "domain1.com", "domain1.net", "domain1.org");
            SiteDomainHelper.AddSite("site2", "domain2.com", "domain2.net", "domain2.org");
            SiteDomainHelper.AddSite("site3", "domain3.com", "domain3.net", "domain3.org");
            SiteDomainHelper.AddSite("site4", "domain4.com", "domain4.net", "domain4.org");

            SiteDomainHelper.BindSites("site1", "site2");
            SiteDomainHelper.BindSites("site1", "site3");

            var bindings = SiteDomainHelper.Bindings;

            Assert.AreEqual(3, bindings.Count);
            Assert.Contains("site1", bindings.Keys);
            Assert.Contains("site2", bindings.Keys);
            Assert.Contains("site3", bindings.Keys);

            var others = bindings["site1"];

            Assert.AreEqual(2, others.Count);
            Assert.Contains("site2", others);
            Assert.Contains("site3", others);

            others = bindings["site2"];
            Assert.AreEqual(2, others.Count);
            Assert.Contains("site1", others);
            Assert.Contains("site3", others);

            others = bindings["site3"];
            Assert.AreEqual(2, others.Count);
            Assert.Contains("site1", others);
            Assert.Contains("site2", others);
        }
        public void MapDomains()
        {
            SiteDomainHelper.AddSite("site1", "domain1.com", "domain1.net", "domain1.org");
            SiteDomainHelper.AddSite("site2", "domain2.com", "domain2.net", "domain2.org");
            SiteDomainHelper.AddSite("site3", "domain3.com", "domain3.net", "domain3.org");
            SiteDomainHelper.AddSite("site4", "domain4.com", "domain4.net", "domain4.org");

            // map methods are not static because we can override them
            var helper = new SiteDomainHelper();

            // the rule is:
            // - exclude the current domain
            // - exclude what MapDomain would return
            // - return all domains from same site, or bound sites

            // current is a site1 uri, domains contains current
            //
            var current = new Uri("http://domain1.com/foo/bar");
            var output  = helper.MapDomains(current, new[]
            {
                new DomainAndUri(new UmbracoDomain("domain1.com"), Uri.UriSchemeHttp),     // no: current + what MapDomain would pick
                new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp),     // yes: same site (though bogus setup)
            }, true).ToArray();

            Assert.AreEqual(1, output.Count());
            Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());

            // current is a site1 uri, domains does not contain current
            //
            current = new Uri("http://domain1.com/foo/bar");
            output  = helper.MapDomains(current, new[]
            {
                new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp),     // no: what MapDomain would pick
                new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp),     // yes: same site (though bogus setup)
            }, true).ToArray();

            Assert.AreEqual(1, output.Count());
            Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());

            SiteDomainHelper.BindSites("site1", "site3");
            SiteDomainHelper.BindSites("site2", "site4");

            // current is a site1 uri, domains contains current
            //
            current = new Uri("http://domain1.com/foo/bar");
            output  = helper.MapDomains(current, new[]
            {
                new DomainAndUri(new UmbracoDomain("domain1.com"), Uri.UriSchemeHttp),     // no: current + what MapDomain would pick
                new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp),     // yes: bound site
                new DomainAndUri(new UmbracoDomain("domain3.org"), Uri.UriSchemeHttp),     // yes: bound site
                new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp),     // yes: same site (though bogus setup)
            }, true).ToArray();

            Assert.AreEqual(3, output.Count());
            Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
            Assert.Contains("http://domain3.com/", output.Select(d => d.Uri.ToString()).ToArray());
            Assert.Contains("http://domain3.org/", output.Select(d => d.Uri.ToString()).ToArray());

            // current is a site1 uri, domains does not contain current
            //
            current = new Uri("http://domain1.com/foo/bar");
            output  = helper.MapDomains(current, new[]
            {
                new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp),     // no: what MapDomain would pick
                new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp),     // yes: bound site
                new DomainAndUri(new UmbracoDomain("domain3.org"), Uri.UriSchemeHttp),     // yes: bound site
                new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp),     // no: not same site
                new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp),     // yes: same site (though bogus setup)
            }, true).ToArray();

            Assert.AreEqual(3, output.Count());
            Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
            Assert.Contains("http://domain3.com/", output.Select(d => d.Uri.ToString()).ToArray());
            Assert.Contains("http://domain3.org/", output.Select(d => d.Uri.ToString()).ToArray());
        }