public void ClearWorks() { var pb = new VirtualPathBuilder("/Foo"); Assert.AreEqual(string.Empty, pb.ToString()); Assert.AreEqual("/Foo/", pb.ApplicationRoot); pb.CombineWith("Doo"); Assert.AreEqual("Doo", pb.ToString()); Assert.AreEqual("/Foo/Doo", pb.Normalize().ToString()); pb.Clear(); Assert.AreEqual(string.Empty, pb.ToString()); pb.CombineWith("."); Assert.AreEqual("", pb.Normalize().ToString()); }
public void GetExtensionWorks() { var pb = new VirtualPathBuilder().CombineWith("."); Assert.IsTrue(pb == "."); Assert.IsFalse(pb.HasExtension()); Assert.IsNull(pb.GetExtension()); pb.Clear().CombineWith("~/oops.cshtml"); Assert.IsTrue(pb.HasExtension()); pb.Normalize(); Assert.IsTrue(pb.HasExtension()); Assert.IsTrue(pb.GetExtension() == "cshtml"); Assert.IsTrue(pb.HasExtension()); Assert.IsTrue(pb.GetExtension(true) == "cshtml"); Assert.IsFalse(pb.HasExtension()); }
private static VirtualPathBuilder NormalizeWorks(string appName, string part, params string[] normalizeResults) { var pb = new VirtualPathBuilder(appName); pb.CombineWith(part); Assert.IsTrue(pb == part); if (normalizeResults.Length > 0) { foreach (var normalizeResult in normalizeResults) { Assert.IsTrue(pb == normalizeResult); } pb = pb.Normalize(); } else { var caught = false; try { pb.Normalize(); } catch (InvalidOperationException ex) { Debug.WriteLine("Expected error: {0}".FormatWith(ex.Message)); caught = true; } Assert.IsTrue(caught); return null; } return pb; }
public void IsRelativePathWorks() { var pb = new VirtualPathBuilder(); Assert.IsFalse(pb.IsRelativePath()); pb.CombineWith("."); Assert.IsTrue(pb.IsRelativePath()); pb.Clear().CombineWith("Foo"); Assert.IsTrue(pb.IsRelativePath()); pb.Normalize(); Assert.IsFalse(pb.IsRelativePath()); Assert.IsTrue(pb.IsAbsolutePath()); }
public void IsAbsolutePathWorks() { var pb = new VirtualPathBuilder().CombineWith("~/"); Assert.IsFalse(pb.IsAbsolutePath()); pb.Normalize(); Assert.IsTrue(pb.IsAbsolutePath()); pb = new VirtualPathBuilder().CombineWith("~"); Assert.IsFalse(pb.IsAbsolutePath()); pb.Normalize(); Assert.IsTrue(pb.IsAbsolutePath()); pb = new VirtualPathBuilder().CombineWith("~/Foo"); Assert.IsFalse(pb.IsAbsolutePath()); pb.Normalize(); Assert.IsTrue(pb.IsAbsolutePath()); pb = new VirtualPathBuilder("/Foo"); Assert.IsFalse(pb.IsAbsolutePath()); Assert.IsTrue(pb.CombineWith("/Foo/").IsAbsolutePath()); Assert.IsTrue(pb.Clear().CombineWith("/Foo").IsAbsolutePath()); Assert.IsTrue(pb.Clear().CombineWith("/Foo/Doo").IsAbsolutePath()); Assert.IsTrue(pb.Clear().CombineWith("/Foo/Doo/Boo").IsAbsolutePath()); Assert.IsTrue(pb.CombineWith("../..") == "/Foo"); Assert.IsTrue(pb.WithRootOperator().HasRootOperator()); pb = new VirtualPathBuilder("/Foo"); pb.CombineWith("/Doo/Foo"); Assert.IsTrue(pb.IsAbsolutePath()); Assert.IsFalse(pb.IsValidAbsolutePath()); }
public void HasRootOperatorWorks() { var pb = new VirtualPathBuilder().CombineWith("~/"); Assert.IsTrue(pb.HasRootOperator()); Assert.IsFalse(pb.Normalize().HasRootOperator()); Assert.IsTrue(pb == "/"); Assert.IsTrue(pb.WithRootOperator().HasRootOperator()); pb = new VirtualPathBuilder().CombineWith("~"); Assert.IsTrue(pb.HasRootOperator()); Assert.IsFalse(pb.Normalize().HasRootOperator()); Assert.IsTrue(pb == "/"); Assert.IsTrue(pb.WithRootOperator().HasRootOperator()); pb = new VirtualPathBuilder().CombineWith("~/Foo"); Assert.IsTrue(pb.HasRootOperator()); Assert.IsFalse(pb.Normalize().HasRootOperator()); Assert.IsTrue(pb == "/Foo"); Assert.IsTrue(pb.WithRootOperator().HasRootOperator()); }