Beispiel #1
0
        public void Get_singleton_success()
        {
            UmbracoContext.Init <TestSite>(new TestCacheConfig(), new TestUmbracoConfig(), new TestMapBuild(), new TestCacheBuild());

            var first  = UmbracoContext.MapRegistry;
            var second = UmbracoContext.MapRegistry;

            Assert.AreEqual(first, second);
        }
Beispiel #2
0
        public void Get_cache_function_different_success()
        {
            var root1 = new TestSite
            {
                Id    = 1,
                Key   = Guid.NewGuid(),
                Hosts = new List <string> {
                    "root1"
                },
                SiteName = "one"
            };
            var root2 = new TestSite
            {
                Id    = 2,
                Key   = Guid.NewGuid(),
                Hosts = new List <string> {
                    "root2"
                },
                SiteName = "two"
            };

            async Task <IEnumerable <TestSite> > GetRoots(ICache cache)
            {
                return(await Task.Run(() =>
                                      new[]
                {
                    root1, root2
                }).ConfigureAwait(false));
            }

            UmbracoContext.Init <TestSite>(new TestCacheConfig(), new TestUmbracoConfig(), new TestMapBuild(), new TestCacheBuild());
            UmbracoContext.CacheRegistry.Add(GetRoots);

            HttpContext.Current = new HttpContext(
                new HttpRequest("", "http://root1", ""),
                new HttpResponse(null)
                );
            var first = UmbracoContext.Cache;

            HttpContext.Current = new HttpContext(
                new HttpRequest("", "http://root2", ""),
                new HttpResponse(null)
                );
            var second = UmbracoContext.Cache;

            var cache1 = UmbracoContext.SiteCaches.Get(root1);
            var cache2 = UmbracoContext.SiteCaches.Get(root2);

            Assert.AreNotEqual(first, second);
            Assert.AreEqual(first, cache1);
            Assert.AreEqual(second, cache2);
        }