public void CanAppend(string first, string second, VirtualPathType expectedType, string expectedPath)
 {
     var v1 = new VirtualPath(first);
     var v2 = new VirtualPath(second);
     var actual = v1.Append(v2);
     Assert.AreEqual(expectedType, actual.Type);
     Assert.AreEqual(expectedPath, actual.Path);
 }
 public void CanGetSubPath(string first, string second, bool ignoreCase, string expected)
 {
     var v1 = new VirtualPath(first);
     var v2 = new VirtualPath(second);
     var diff = v1.GetSubPath(v2, ignoreCase);
     if (expected == null) {
         Assert.IsNull(diff);
     }
     else {
         Assert.AreEqual(expected, diff.ToString());
     }
 }
Example #3
0
 private VirtualPath GetSubPathInternal(VirtualPath other, bool ignoreCase, VirtualPathType type)
 {
     if (this.Parts.Count > other.Parts.Count) return null;
     var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
     for (var i = 0; i < this.Parts.Count; i++) {
         if (!this.Parts[i].Equals(other.Parts[i], comparison)) return null;
     }
     return new VirtualPath(other.Parts.Skip(this.Parts.Count), type);
 }
Example #4
0
        /// <summary>
        ///  Given that this path is the application path, and that the other path is the
        ///  request path, gets the app-relative path.
        /// </summary>
        /// <param name="other">
        ///  The request path.
        /// </param>
        /// <param name="ignoreCase">
        ///  true to perform a case-insensitive comparison, or false for case-sensitive.
        /// </param>
        /// <returns>
        ///  A request-relative virtual path from this path to other. Returns null if
        ///    (a) either path is not absolute, or
        ///    (c) other is not a sub-path of this.
        /// </returns>

        public VirtualPath GetAppRelativePath(VirtualPath other, bool ignoreCase)
        {
            if (other == null) return null;
            if (this.Type != VirtualPathType.Absolute || other.Type != VirtualPathType.Absolute) return null;
            return GetSubPathInternal(other, ignoreCase, VirtualPathType.AppRelative);
        }
Example #5
0
        /// <summary>
        ///  Given a path that is a sub-path of this path, returns the difference
        ///  between the two of them.
        /// </summary>
        /// <param name="other">
        ///  The longer of the two paths.
        /// </param>
        /// <param name="ignoreCase">
        ///  true to perform a case-insensitive comparison, or false for case-sensitive.
        /// </param>
        /// <returns>
        ///  A request-relative virtual path from this path to other. Returns null if
        ///    (a) both paths are differnt types
        ///    (b) both paths are request-relative, or
        ///    (c) other is not a sub-path of this.
        /// </returns>

        public VirtualPath GetSubPath(VirtualPath other, bool ignoreCase)
        {
            if (other == null) return null;
            if (other.Type != this.Type) return null;
            if (this.Type == VirtualPathType.RequestRelative) return null;
            return GetSubPathInternal(other, ignoreCase, VirtualPathType.RequestRelative);
        }
Example #6
0
        /// <summary>
        ///  Appends one virtual path to another.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>

        public VirtualPath Append(VirtualPath other)
        {
            if (other.Type == VirtualPathType.Absolute || 
                (other.Type == VirtualPathType.AppRelative && this.Type != VirtualPathType.Absolute)) {
                return other;
            }
            else {
                return new VirtualPath(this.Parts.Concat(other.Parts), this.Type);
            }
        }
 public void CanGetRootPath(string path, VirtualPathType expectedType)
 {
     var vPath = new VirtualPath(path);
     CollectionAssert.IsEmpty(vPath.Parts);
     Assert.AreEqual(expectedType, vPath.Type);
 }
 public void CanDetectPathType(string path, VirtualPathType type, string expectedPath)
 {
     var vpath = new VirtualPath(path);
     Assert.AreEqual(type, vpath.Type);
     Assert.AreEqual(expectedPath, vpath.Path);
 }