public void GetLayoutName_VirtualPath_ResolvesLayoutFileName()
        {
            // Arrange
            var expectedLayoutName = "TestTitle";
            var testVirtualPath = "~/TestPrefix/TestTitle....master";
            var pathDefinition = new PathDefinition { VirtualPath = "~/TestPrefix" };

            // Act
            var layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            var resultLayoutName = layoutVirtualPathBuilder.GetLayoutName(pathDefinition, testVirtualPath);

            // Assert
            Assert.AreEqual(expectedLayoutName, resultLayoutName, "The layout name is not extracted correctly.");
        }
        public void GetLayoutName_WithoutMasterSuffix_ReturnsNull()
        {
            // Arrange
            var testVirtualPath = "~/TestPrefix/TestTitle.test";
            var pathDefinition = new PathDefinition();
            pathDefinition.VirtualPath = "~/TestPrefix";

            // Act
            var layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            var resultLayoutName = layoutVirtualPathBuilder.GetLayoutName(pathDefinition, testVirtualPath);

            // Assert
            Assert.IsNull(resultLayoutName, "The result layout name should be null if the virtual path doesn't end with 'master'.");
        }
        /// <summary>
        /// Creates a cache dependency based on the specified virtual paths.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The path to the primary virtual resource.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Caching.CacheDependency"/> object for the specified virtual resources.
        /// </returns>
        public CacheDependency GetCacheDependency(PathDefinition definition, string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            string viewName = layoutVirtualPathBuilder.GetLayoutName(definition, virtualPath);
            var layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
                return null;

            var viewPath = layoutTemplateBuilder.LayoutViewPath(viewName);
            return HostingEnvironment.VirtualPathProvider.GetCacheDependency(viewPath, virtualPathDependencies, utcStart);
        }
        /// <summary>
        /// Determines whether a file with the specified virtual path exists.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The virtual path to check.</param>
        public virtual bool Exists(PathDefinition definition, string virtualPath)
        {
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var vpBuilder = new LayoutVirtualPathBuilder();
            string viewName = vpBuilder.GetLayoutName(definition, virtualPath);
            var layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
                return false;

            if (virtualPath.StartsWith(string.Format("~/{0}", LayoutVirtualFileResolver.ResolverPath)))
                return layoutTemplateBuilder.LayoutExists(viewName);
            else
                return false;
        }
        /// <summary>
        /// Determines whether a file with the specified virtual path exists.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The virtual path to check.</param>
        public virtual bool Exists(PathDefinition definition, string virtualPath)
        {
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            string viewName = layoutVirtualPathBuilder.GetLayoutName(definition, virtualPath);
            var layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
                return false;

            if (virtualPath.StartsWith(string.Format(System.Globalization.CultureInfo.InvariantCulture, "~/{0}", LayoutVirtualFileResolver.ResolverPath), StringComparison.Ordinal))
                return layoutTemplateBuilder.LayoutExists(viewName);
            else
                return false;
        }
        /// <summary>
        /// Opens the the file with the specified virtual path.
        /// </summary>
        /// <param name="virtualPath">The virtual path of the file to open.</param>
        public virtual Stream Open(PathDefinition definition, string virtualPath)
        {
            MemoryStream outPutStream = null;

            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);
            var    vpBuilder        = new LayoutVirtualPathBuilder();
            string viewName         = vpBuilder.GetLayoutName(definition, virtualPath);
            var    layoutHtmlString = this.RenderLayout(viewName);

            if (!string.IsNullOrEmpty(layoutHtmlString))
            {
                var layoutBytes = Encoding.Default.GetBytes(layoutHtmlString.ToCharArray());
                outPutStream = new MemoryStream(layoutBytes);
            }

            return(outPutStream);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a cache dependency based on the specified virtual paths.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The path to the primary virtual resource.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Caching.CacheDependency"/> object for the specified virtual resources.
        /// </returns>
        public CacheDependency GetCacheDependency(PathDefinition definition, string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var    layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            string viewName = layoutVirtualPathBuilder.GetLayoutName(definition, virtualPath);
            var    layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
            {
                return(null);
            }

            var viewPath = layoutTemplateBuilder.LayoutViewPath(viewName);

            return(HostingEnvironment.VirtualPathProvider.GetCacheDependency(viewPath, virtualPathDependencies, utcStart));
        }
        /// <summary>
        /// Opens the the file with the specified virtual path.
        /// </summary>
        /// <param name="virtualPath">The virtual path of the file to open.</param>
        public virtual Stream Open(PathDefinition definition, string virtualPath)
        {
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);

            MemoryStream outPutStream = null;
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);
            var virtualBuilder = new LayoutVirtualPathBuilder();
            var viewName = virtualBuilder.GetLayoutName(definition, virtualPath);
            var layoutHtmlString = this.RenderLayout(viewName);

            if (!string.IsNullOrEmpty(layoutHtmlString))
            {
                var layoutBytes = Encoding.Default.GetBytes(layoutHtmlString.ToCharArray());
                outPutStream = new MemoryStream(layoutBytes);
            }

            return outPutStream;
        }
Beispiel #9
0
        /// <summary>
        /// Opens the the file with the specified virtual path.
        /// </summary>
        /// <param name="virtualPath">The virtual path of the file to open.</param>
        public virtual Stream Open(PathDefinition definition, string virtualPath)
        {
            var placeholdersOnly = virtualPath.EndsWith(".master", StringComparison.OrdinalIgnoreCase);

            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);

            MemoryStream outPutStream = null;

            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);
            var virtualBuilder   = new LayoutVirtualPathBuilder();
            var viewName         = virtualBuilder.GetLayoutName(definition, virtualPath);
            var layoutHtmlString = this.RenderLayout(viewName, placeholdersOnly);

            if (!string.IsNullOrEmpty(layoutHtmlString))
            {
                var layoutBytes = Encoding.UTF8.GetBytes(layoutHtmlString.ToCharArray());
                outPutStream = new MemoryStream(layoutBytes);
            }

            return(outPutStream);
        }
        /// <summary>
        /// Determines whether a file with the specified virtual path exists.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The virtual path to check.</param>
        public virtual bool Exists(PathDefinition definition, string virtualPath)
        {
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var    vpBuilder             = new LayoutVirtualPathBuilder();
            string viewName              = vpBuilder.GetLayoutName(definition, virtualPath);
            var    layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
            {
                return(false);
            }

            if (virtualPath.StartsWith(string.Format("~/{0}", LayoutVirtualFileResolver.ResolverPath)))
            {
                return(layoutTemplateBuilder.LayoutExists(viewName));
            }
            else
            {
                return(false);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Determines whether a file with the specified virtual path exists.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="virtualPath">The virtual path to check.</param>
        public virtual bool Exists(PathDefinition definition, string virtualPath)
        {
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);

            var    layoutVirtualPathBuilder = new LayoutVirtualPathBuilder();
            string viewName = layoutVirtualPathBuilder.GetLayoutName(definition, virtualPath);
            var    layoutTemplateBuilder = new LayoutRenderer();

            if (string.IsNullOrEmpty(viewName))
            {
                return(false);
            }

            if (virtualPath.StartsWith(string.Format(System.Globalization.CultureInfo.InvariantCulture, "~/{0}", LayoutVirtualFileResolver.ResolverPath), StringComparison.Ordinal))
            {
                return(layoutTemplateBuilder.LayoutExists(viewName));
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Opens the the file with the specified virtual path.
        /// </summary>
        /// <param name="virtualPath">The virtual path of the file to open.</param>
        public virtual Stream Open(PathDefinition definition, string virtualPath)
        {
            var placeholdersOnly = virtualPath.EndsWith(".master", StringComparison.OrdinalIgnoreCase);
            virtualPath = this.virtualPathBuilder.RemoveParams(virtualPath);

            MemoryStream outPutStream = null;
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);
            var virtualBuilder = new LayoutVirtualPathBuilder();
            var viewName = virtualBuilder.GetLayoutName(definition, virtualPath);
            var layoutHtmlString = this.RenderLayout(viewName, placeholdersOnly);

            if (!string.IsNullOrEmpty(layoutHtmlString))
            {
                var layoutBytes = Encoding.UTF8.GetBytes(layoutHtmlString.ToCharArray());
                outPutStream = new MemoryStream(layoutBytes);
            }

            return outPutStream;
        }