Esempio n. 1
0
        private static Func <SiteMapBase> CreateDefaultSiteMapFactory()
        {
            Func <SiteMapBase> factory = () =>
            {
                XmlSiteMap siteMap = new XmlSiteMap();

                siteMap.Load();

                return(siteMap);
            };

            return(factory);
        }
Esempio n. 2
0
        public static SiteMapBase CreateXmlSiteMap()
        {
            if (siteMap == null)
            {
                lock (syncSiteMap)
                {
                    if (siteMap == null)
                    {
                        Mock <IPathResolver>        pathResolver  = new Mock <IPathResolver>();
                        Mock <IVirtualPathProvider> fileSystem    = new Mock <IVirtualPathProvider>();
                        Mock <ICacheProvider>       cacheProvider = new Mock <ICacheProvider>();

                        const string Xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>" + "\r\n" +
                                           @"<siteMap compress=""false"" cacheDurationInMinutes=""120"" generateSearchEngineMap=""true"">" +
                                           "\r\n" +
                                           @"    <siteMapNode title=""Home"" route=""Home"" foo=""bar"">" + "\r\n" +
                                           @"        <siteMapNode title=""Products"" route=""ProductList"" visible=""true"" " +
                                           @"lastModifiedAt=""2009/1/3"" changeFrequency=""hourly"" updatePriority=""high"" >" +
                                           "\r\n" +
                                           @"            <siteMapNode title=""Product 1"" controller=""Product"" action=""Detail"">" +
                                           "\r\n" +
                                           @"                <routeValues>" + "\r\n" +
                                           @"                    <id>1</id>" + "\r\n" +
                                           @"                </routeValues>" + "\r\n" +
                                           @"            </siteMapNode>" + "\r\n" +
                                           @"            <siteMapNode title=""Product 2"" controller=""Product"" action=""Detail"" " +
                                           @"includeInSearchEngineIndex=""true"">" + "\r\n" +
                                           @"                <routeValues>" + "\r\n" +
                                           @"                    <id>2</id>" + "\r\n" +
                                           @"                </routeValues>" + "\r\n" +
                                           @"            </siteMapNode>" + "\r\n" +
                                           @"        </siteMapNode>" + "\r\n" +
                                           @"        <siteMapNode title=""Faq"" url=""~/faq"" />" + "\r\n" +
                                           @"    </siteMapNode>" + "\r\n" +
                                           @"</siteMap>";

                        pathResolver.Setup(p => p.Resolve(It.IsAny <string>())).Returns("C:\\Web.sitemap").Verifiable();
                        fileSystem.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns(Xml).Verifiable();
                        cacheProvider.Setup(cache => cache.Insert(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CacheItemRemovedCallback>(), It.IsAny <string>())).Verifiable();

                        siteMap = new XmlSiteMap(pathResolver.Object, fileSystem.Object, cacheProvider.Object);
                        siteMap.Load();
                    }
                }
            }
            return(siteMap);
        }