Beispiel #1
0
        public void BindMoreSites()
        {
            SiteDomainMapper siteDomainMapper = CreateSut();

            siteDomainMapper.AddSite("site1", "domain1.com", "domain1.net", "domain1.org");
            siteDomainMapper.AddSite("site2", "domain2.com", "domain2.net", "domain2.org");
            siteDomainMapper.AddSite("site3", "domain3.com", "domain3.net", "domain3.org");
            siteDomainMapper.AddSite("site4", "domain4.com", "domain4.net", "domain4.org");

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

            Dictionary <string, List <string> > bindings = siteDomainMapper.Bindings;

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

            List <string> 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);
        }
Beispiel #2
0
        public void MapDomains()
        {
            SiteDomainMapper siteDomainMapper = CreateSut();

            siteDomainMapper.AddSite("site1", "domain1.com", "domain1.net", "domain1.org");
            siteDomainMapper.AddSite("site2", "domain2.com", "domain2.net", "domain2.org");
            siteDomainMapper.AddSite("site3", "domain3.com", "domain3.net", "domain3.org");
            siteDomainMapper.AddSite("site4", "domain4.com", "domain4.net", "domain4.org");

            // 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");

            DomainAndUri[] output = siteDomainMapper.MapDomains(
                new[]
            {
                new DomainAndUri(new Domain(1, "domain1.com", -1, s_cultureFr, false), current),     // no: current + what MapDomain would pick
                new DomainAndUri(new Domain(1, "domain2.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain3.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain4.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain1.org", -1, s_cultureGb, false), current),     // yes: same site (though bogus setup)
            },
                current,
                true,
                s_cultureFr,
                s_cultureFr).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  = siteDomainMapper.MapDomains(
                new[]
            {
                new DomainAndUri(new Domain(1, "domain1.net", -1, s_cultureFr, false), current),     // no: what MapDomain would pick
                new DomainAndUri(new Domain(1, "domain2.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain3.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain4.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain1.org", -1, s_cultureGb, false), current),     // yes: same site (though bogus setup)
            },
                current,
                true,
                s_cultureFr,
                s_cultureFr).ToArray();

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

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

            // current is a site1 uri, domains contains current
            current = new Uri("http://domain1.com/foo/bar");
            output  = siteDomainMapper.MapDomains(
                new[]
            {
                new DomainAndUri(new Domain(1, "domain1.com", -1, s_cultureFr, false), current),     // no: current + what MapDomain would pick
                new DomainAndUri(new Domain(1, "domain2.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain3.com", -1, s_cultureGb, false), current),     // yes: bound site
                new DomainAndUri(new Domain(1, "domain3.org", -1, s_cultureGb, false), current),     // yes: bound site
                new DomainAndUri(new Domain(1, "domain4.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain1.org", -1, s_cultureGb, false), current),     // yes: same site (though bogus setup)
            },
                current,
                true,
                s_cultureFr,
                s_cultureFr).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  = siteDomainMapper.MapDomains(
                new[]
            {
                new DomainAndUri(new Domain(1, "domain1.net", -1, s_cultureFr, false), current),     // no: what MapDomain would pick
                new DomainAndUri(new Domain(1, "domain2.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain3.com", -1, s_cultureGb, false), current),     // yes: bound site
                new DomainAndUri(new Domain(1, "domain3.org", -1, s_cultureGb, false), current),     // yes: bound site
                new DomainAndUri(new Domain(1, "domain4.com", -1, s_cultureGb, false), current),     // no: not same site
                new DomainAndUri(new Domain(1, "domain1.org", -1, s_cultureGb, false), current),     // yes: same site (though bogus setup)
            }, current,
                true,
                s_cultureFr,
                s_cultureFr).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());
        }