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 WithRootOperatorWorks()
 {
     var pb = new VirtualPathBuilder("/Foo");
     var caught = false;
     try{
         pb.WithRootOperator();
     }
     catch(InvalidOperationException){
         caught = true;
     }
     Assert.IsTrue(caught);
     Assert.IsTrue(pb.CombineWith("/Foo").WithRootOperator() == "~/");
     Assert.IsTrue(pb.Clear().CombineWith("Doo").WithRootOperator() == "~/Doo");
 }
        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 RemoveExtensionWorks()
 {
     var pb = new VirtualPathBuilder();
     pb.RemoveExtension();
     pb.CombineWith("oops.cs");
     Assert.IsTrue(pb.GetExtension() == "cs");
     pb.RemoveExtension();
     Assert.IsNull(pb.GetExtension());
 }
 public void ResolveRootOperatorWorks()
 {
     var pb = new VirtualPathBuilder();
     Assert.IsTrue(pb.CombineWith("Foo").ResolveRootOperator().ToString() == "/Foo");
     Assert.IsTrue(pb.Clear().CombineWith("~/").ResolveRootOperator().ToString() == "/");
     Assert.IsTrue(pb.Clear().CombineWith("~").ResolveRootOperator().ToString() == "/");
     pb = new VirtualPathBuilder("/Foo");
     Assert.IsTrue(pb.CombineWith("~/Doo").ResolveRootOperator().ToString() == "/Foo/Doo");
     var caught = false;
     try{
         pb.Clear().CombineWith("/Oops").ResolveRootOperator();
     }
     catch(InvalidOperationException){
         caught = true;
     }
     Assert.IsTrue(caught);
 }
 public void PathBuilderWorksWithRootPartAdded()
 {
     var pb = new VirtualPathBuilder();
     pb.CombineWith("/");
     pb.CombineWith("/");
     Assert.AreEqual("/", pb.ToString());
 }
 public void PathBuilderCanBeCreatedFromTwoParts()
 {
     var pb = new VirtualPathBuilder();
     pb.CombineWith("~/part1", "part2").Normalize();
     Assert.AreEqual("/part1/part2",pb.ToString());
     pb.WithRootOperator();
     Assert.AreEqual("~/part1/part2", pb.ToString());
 }
 public void NormalizingToRootRelativeWorksForCurrentDirectory()
 {
     var pb = new VirtualPathBuilder();
     pb
         .CombineWith("/")
         .CombineWith("/./././.")
         .Normalize()
         .WithRootOperator();
     Assert.AreEqual("~/", pb.ToString());
 }
 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());
        }