Example #1
0
        public void TestIsSubpathOf()
        {
            // Positive tests
            foreach (var testCase in Pairs(
                         @"C:\a\b", @"C:\A\B",
                         @"C:\a\b\", @"C:\A\B",   // IsSubpathOf has a special case for this
                         @"C:\a\b", @"C:\A\B\C",
                         @"C:\a\b\", @"C:\a\b\c", // IsSubpathOf has a quick path for this
                         @"C:\a\b\", @"C:\A\B\C", // Quick path should not be taken
                         @"C:", @"C:\a\b\",
                         @"C:\a\b", @"C:\A\X\..\B\C"
                         ))
            {
                Assert.IsTrue(CommonUtils.IsSubpathOf(testCase.Item1, testCase.Item2), string.Format("{0} should be subpath of {1}", testCase.Item2, testCase.Item1));
            }

            // Negative tests
            foreach (var testCase in Pairs(
                         @"C:\a\b\c", @"C:\A\B",
                         @"C:\a\bcd", @"c:\a\b\cd", // Quick path should not be taken
                         @"C:\a\bcd", @"C:\A\B\CD", // Quick path should not be taken
                         @"C:\a\b", @"D:\A\B\C",
                         @"C:\a\b\c", @"C:\B\A\C\D",
                         @"C:\a\b\", @"C:\a\b\..\x\c" // Quick path should not be taken
                         ))
            {
                Assert.IsFalse(CommonUtils.IsSubpathOf(testCase.Item1, testCase.Item2), string.Format("{0} should not be subpath of {1}", testCase.Item2, testCase.Item1));
            }
        }
Example #2
0
        public void TestTrimEndSeparator()
        {
            // TrimEndSeparator uses System.IO.Path.(Alt)DirectorySeparatorChar
            // Here we assume these are '\\' and '/'

            foreach (var testCase in Pairs(
                         @"no separator", @"no separator",
                         @"one slash/", @"one slash",
                         @"two slashes//", @"two slashes/",
                         @"one backslash\", @"one backslash",
                         @"two backslashes\\", @"two backslashes\",
                         @"mixed/\", @"mixed/",
                         @"mixed\/", @"mixed\",
                         @"/leading", @"/leading",
                         @"\leading", @"\leading",
                         @"wit/hin", @"wit/hin",
                         @"wit\hin", @"wit\hin",
                         @"C:\a\", @"C:\a",
                         @"C:\", @"C:\",
                         @"ftp://a/", @"ftp://a",
                         @"ftp://", @"ftp://"
                         ))
            {
                var expected = testCase.Item2;
                var actual   = CommonUtils.TrimEndSeparator(testCase.Item1);

                Assert.AreEqual(expected, actual);
            }
        }
Example #3
0
        public void TestGetAbsoluteFilePath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"\file.exe", @"C:\file.exe",
                         @"C:\a\b", @"..\file.exe", @"C:\a\file.exe",
                         @"C:\a\b", @"file.exe", @"C:\a\b\file.exe",
                         @"C:\a\b", @"c\file.exe", @"C:\a\b\c\file.exe",
                         @"C:\a\b", @"D:\a\b\file.exe", @"D:\a\b\file.exe",
                         @"C:\a\b", @"\d\e\file.exe", @"C:\d\e\file.exe",
                         @"C:\a\b\c\d\", @"..\..\..\..\", @"C:\",

                         @"\\root\share\path", @"..\file.exe", @"\\root\share\file.exe",
                         @"\\root\share\path", @"file.exe", @"\\root\share\path\file.exe",
                         @"\\root\share\path", @"subpath\file.exe", @"\\root\share\path\subpath\file.exe",
                         @"\\root\share\path", @"..\otherpath\file.exe", @"\\root\share\otherpath\file.exe",

                         @"ftp://[email protected]/path", @"../file.exe", @"ftp://[email protected]/file.exe",
                         @"ftp://[email protected]/path", @"file.exe", @"ftp://[email protected]/path/file.exe",
                         @"ftp://[email protected]/path", @"subpath/file.exe", @"ftp://[email protected]/path/subpath/file.exe",
                         @"ftp://[email protected]/path", @"../otherpath/file.exe", @"ftp://[email protected]/otherpath/file.exe"
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.GetAbsoluteFilePath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual);
            }
        }
Example #4
0
        public void TestGetAbsoluteDirectoryPath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"\", @"C:\",
                         @"C:\a\b", @"..\", @"C:\a\",
                         @"C:\a\b", @"", @"C:\a\b\",
                         @"C:\a\b", @".", @"C:\a\b\",
                         @"C:\a\b", @"c", @"C:\a\b\c\",
                         @"C:\a\b", @"D:\a\b", @"D:\a\b\",
                         @"C:\a\b", @"\d\e", @"C:\d\e\",
                         @"C:\a\b\c\d", @"..\..\..\..", @"C:\",

                         @"\\root\share\path", @"..", @"\\root\share\",
                         @"\\root\share\path", @"subpath", @"\\root\share\path\subpath\",
                         @"\\root\share\path", @"..\otherpath\", @"\\root\share\otherpath\",

                         @"ftp://[email protected]/path", @"..", @"ftp://[email protected]/",
                         @"ftp://[email protected]/path", @"subpath", @"ftp://[email protected]/path/subpath/",
                         @"ftp://[email protected]/path", @"../otherpath/", @"ftp://[email protected]/otherpath/"
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.GetAbsoluteDirectoryPath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual);
            }
        }
Example #5
0
        public void TestCreateFriendlyFilePath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"C:\file.exe", @"..\..\file.exe",
                         @"C:\a\b", @"C:\a\file.exe", @"..\file.exe",
                         @"C:\a\b", @"C:\a\b\file.exe", @"file.exe",
                         @"C:\a\b", @"C:\a\b\c\file.exe", @"c\file.exe",
                         @"C:\a\b", @"D:\a\b\file.exe", @"D:\a\b\file.exe",

                         @"\\pc\share\a\b", @"\\pc\share\file.exe", @"..\..\file.exe",
                         @"\\pc\share\a\b", @"\\pc\share\a\file.exe", @"..\file.exe",
                         @"\\pc\share\a\b", @"\\pc\share\a\b\file.exe", @"file.exe",
                         @"\\pc\share\a\b", @"\\pc\share\a\b\c\file.exe", @"c\file.exe",
                         @"\\pc\share\a\b", @"\\pc\othershare\a\b\file.exe", @"..\..\..\othershare\a\b\file.exe",

                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/file.exe", @"../../file.exe",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/file.exe", @"../file.exe",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b/file.exe", @"file.exe",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b/c/file.exe", @"c/file.exe",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b/file.exe", @"ftp://[email protected]/a/b/file.exe"
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.CreateFriendlyFilePath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual);
            }
        }
Example #6
0
        public void TestCreateFriendlyDirectoryPath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"C:\", @"..\..",
                         @"C:\a\b", @"C:\a", @"..",
                         @"C:\a\b", @"C:\a\b", @".",
                         @"C:\a\b", @"C:\a\b\c", @"c",
                         @"C:\a\b", @"D:\a\b", @"D:\a\b",
                         @"C:\a\b", @"C:\", @"..\..",

                         @"\\pc\share\a\b", @"\\pc\share\", @"..\..",
                         @"\\pc\share\a\b", @"\\pc\share\a", @"..",
                         @"\\pc\share\a\b", @"\\pc\share\a\b", @".",
                         @"\\pc\share\a\b", @"\\pc\share\a\b\c", @"c",
                         @"\\pc\share\a\b", @"\\pc\othershare\a\b", @"..\..\..\othershare\a\b",

                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/", @"../..",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a", @"..",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b", @".",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b/c", @"c",
                         @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b", @"ftp://[email protected]/a/b"
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.CreateFriendlyDirectoryPath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual);
            }
        }
Example #7
0
        public void TestNormalizePath()
        {
            foreach (var testCase in Pairs(
                         @"a\b\c", @"a\b\c",
                         @"a\b\.\c", @"a\b\.\c",
                         @"a\b\d\..\c", @"a\b\d\..\c"
                         ))
            {
                foreach (var root in new[] { "", @".\", @"..\", @"\" })
                {
                    var expected = root + testCase.Item2;
                    var actual   = CommonUtils.NormalizePath(root + testCase.Item1);

                    Assert.AreEqual(expected, actual);

                    expected += @"\";
                    actual    = CommonUtils.NormalizePath(root + testCase.Item1 + @"\");

                    Assert.AreEqual(expected, actual);
                }
            }

            foreach (var testCase in Pairs(
                         @"a\b\c", @"a\b\c",
                         @"a\b\.\c", @"a\b\c",
                         @"a\b\d\..\c", @"a\b\c"
                         ))
            {
                foreach (var root in new[] { @"C:\", @"\\pc\share\", @"ftp://[email protected]/" })
                {
                    var expected = root + testCase.Item2;
                    var actual   = CommonUtils.NormalizePath(root + testCase.Item1);
                    if (root.StartsWith("ftp", StringComparison.OrdinalIgnoreCase))
                    {
                        expected = expected.Replace('\\', '/');
                    }

                    Assert.AreEqual(expected, actual);

                    expected += @"\";
                    actual    = CommonUtils.NormalizePath(root + testCase.Item1 + @"\");
                    if (root.StartsWith("ftp", StringComparison.OrdinalIgnoreCase))
                    {
                        expected = expected.Replace('\\', '/');
                    }

                    Assert.AreEqual(expected, actual);
                }
            }
        }
Example #8
0
        public void TestGetRelativeFilePath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"C:\file.exe", @"..\..\file.exe",
                         @"C:\a\b", @"C:\a\file.exe", @"..\file.exe",
                         @"C:\a\b\c", @"C:\a\file.exe", @"..\..\file.exe",
                         @"C:\a\b", @"C:\A\B\file.exe", @"file.exe",
                         @"C:\a\b", @"C:\a\B\C\file.exe", @"C\file.exe",
                         @"C:\a\b", @"D:\a\b\file.exe", @"D:\a\b\file.exe",
                         @"C:\a\b", @"C:\d\e\file.exe", @"..\..\d\e\file.exe",

                         @"\\root\share\path", @"\\Root\Share\file.exe", @"..\file.exe",
                         @"\\root\share\path", @"\\Root\Share\Path\file.exe", @"file.exe",
                         @"\\root\share\path", @"\\Root\share\Path\subpath\file.exe", @"subpath\file.exe",
                         @"\\root\share\path\subpath", @"\\Root\share\Path\othersubpath\file.exe", @"..\othersubpath\file.exe",
                         @"\\root\share\path", @"\\root\othershare\path\file.exe", @"..\..\othershare\path\file.exe",
                         @"\\root\share\path", @"\\root\share\otherpath\file.exe", @"..\otherpath\file.exe",
                         @"\\root\share\", @"\\otherroot\share\file.exe", @"\\otherroot\share\file.exe",

                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/file.exe", @"../../file.exe",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/Share/file.exe", @"../../Share/file.exe",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/share/path/subpath/file.exe", @"subpath/file.exe",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/share/Path/subpath/file.exe", @"../Path/subpath/file.exe",
                         @"ftp://[email protected]/share/path/subpath", @"ftp://[email protected]/share/path/othersubpath/file.exe", @"../othersubpath/file.exe",
                         @"ftp://[email protected]/share/path/subpath", @"ftp://[email protected]/share/Path/othersubpath/file.exe", @"../../Path/othersubpath/file.exe",
                         @"ftp://[email protected]/path", @"ftp://[email protected]/otherpath/file.exe", @"../otherpath/file.exe",

                         @"C:\a\b", "C:\\a\\b\\", @"",
                         // This is the expected behavior for GetRelativeFilePath
                         // because the 'b' in the second part is assumed to be a file
                         // and hence may be different to the directory 'b' in the first
                         // part.
                         // GetRelativeDirectoryPath returns an empty string, because it
                         // assumes that both paths are directories.
                         "C:\\a\\b\\", @"C:\a\b", @"..\b",

                         // Ensure end-separators are retained when the target is a
                         // directory rather than a file.
                         "C:\\a\\", "C:\\a\\b\\", "b\\",
                         "C:\\a", "C:\\a\\b\\", "b\\"
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.GetRelativeFilePath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual, string.Format("From {0} to {1}", testCase.Item1, testCase.Item2));
            }
        }
Example #9
0
        public void TestMakeUri()
        {
            Assert.AreEqual(@"C:\a\b\c\", CommonUtils.MakeUri(@"C:\a\b\c", true, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"C:\a\b\c", CommonUtils.MakeUri(@"C:\a\b\c", false, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"\\a\b\c\", CommonUtils.MakeUri(@"\\a\b\c", true, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"\\a\b\c", CommonUtils.MakeUri(@"\\a\b\c", false, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"ftp://[email protected]:123/b/c/", CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c", true, UriKind.Absolute).AbsoluteUri);
            Assert.AreEqual(@"ftp://[email protected]:123/b/c", CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c", false, UriKind.Absolute).AbsoluteUri);
            Assert.AreEqual(@"C:\a b c\d e f\g\", CommonUtils.MakeUri(@"C:\a b c\d e f\g", true, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"C:\a b c\d e f\g", CommonUtils.MakeUri(@"C:\a b c\d e f\g", false, UriKind.Absolute).LocalPath);

            Assert.AreEqual(@"C:\a\b\c\", CommonUtils.MakeUri(@"C:\a\b\c\d\..", true, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"C:\a\b\c\e", CommonUtils.MakeUri(@"C:\a\b\c\d\..\e", false, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"\\a\b\c\", CommonUtils.MakeUri(@"\\a\b\c\d\..", true, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"\\a\b\c\e", CommonUtils.MakeUri(@"\\a\b\c\d\..\e", false, UriKind.Absolute).LocalPath);
            Assert.AreEqual(@"ftp://[email protected]:123/b/c/", CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c/d/..", true, UriKind.Absolute).AbsoluteUri);
            Assert.AreEqual(@"ftp://[email protected]:123/b/c/e", CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c/d/../e", false, UriKind.Absolute).AbsoluteUri);

            Assert.IsTrue(CommonUtils.MakeUri(@"C:\a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);
            Assert.IsTrue(CommonUtils.MakeUri(@"\\a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);
            Assert.IsTrue(CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);

            Assert.IsFalse(CommonUtils.MakeUri(@"a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);
            Assert.IsFalse(CommonUtils.MakeUri(@"\a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);
            Assert.IsFalse(CommonUtils.MakeUri(@".\a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);
            Assert.IsFalse(CommonUtils.MakeUri(@"..\a\b", false, UriKind.RelativeOrAbsolute).IsAbsoluteUri);

            Assert.IsTrue(CommonUtils.MakeUri(@"C:\a\b", false, UriKind.RelativeOrAbsolute).IsFile);
            Assert.IsTrue(CommonUtils.MakeUri(@"C:\a\b", true, UriKind.RelativeOrAbsolute).IsFile);
            Assert.IsTrue(CommonUtils.MakeUri(@"\\a\b", false, UriKind.RelativeOrAbsolute).IsFile);
            Assert.IsTrue(CommonUtils.MakeUri(@"\\a\b", true, UriKind.RelativeOrAbsolute).IsFile);
            Assert.IsFalse(CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c", false, UriKind.RelativeOrAbsolute).IsFile);
            Assert.IsFalse(CommonUtils.MakeUri(@"ftp://[email protected]:123/b/c", true, UriKind.RelativeOrAbsolute).IsFile);

            Assert.AreEqual(@"..\a\b\c\", CommonUtils.MakeUri(@"..\a\b\c", true, UriKind.Relative).ToString());
            Assert.AreEqual(@"..\a\b\c", CommonUtils.MakeUri(@"..\a\b\c", false, UriKind.Relative).ToString());
            Assert.AreEqual(@"..\a b c\", CommonUtils.MakeUri(@"..\a b c", true, UriKind.Relative).ToString());
            Assert.AreEqual(@"..\a b c", CommonUtils.MakeUri(@"..\a b c", false, UriKind.Relative).ToString());
            Assert.AreEqual(@"../a/b/c\", CommonUtils.MakeUri(@"../a/b/c", true, UriKind.Relative).ToString());
            Assert.AreEqual(@"../a/b/c", CommonUtils.MakeUri(@"../a/b/c", false, UriKind.Relative).ToString());
            Assert.AreEqual(@"../a b c\", CommonUtils.MakeUri(@"../a b c", true, UriKind.Relative).ToString());
            Assert.AreEqual(@"../a b c", CommonUtils.MakeUri(@"../a b c", false, UriKind.Relative).ToString());
        }
Example #10
0
        public void TestGetRelativeDirectoryPath()
        {
            foreach (var testCase in Triples(
                         @"C:\a\b", @"C:\", @"..\..\",
                         @"C:\a\b", @"C:\a", @"..\",
                         @"C:\a\b\c", @"C:\a", @"..\..\",
                         @"C:\a\b", @"C:\a\b", @"",
                         @"C:\a\b", @"C:\a\b\c", @"c\",
                         @"C:\a\b", @"D:\a\b", @"D:\a\b\",
                         @"C:\a\b", @"C:\d\e", @"..\..\d\e\",

                         @"\\root\share\path", @"\\Root\Share", @"..\",
                         @"\\root\share\path", @"\\Root\share\Path\subpath", @"subpath\",
                         @"\\root\share\path\subpath", @"\\Root\share\Path\othersubpath", @"..\othersubpath\",
                         @"\\root\share\path", @"\\root\othershare\path", @"..\..\othershare\path\",
                         @"\\root\share\path", @"\\root\share\otherpath\", @"..\otherpath\",

                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/", @"../../",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/Share", @"../../Share/",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/share/path/subpath", @"subpath/",
                         @"ftp://[email protected]/share/path", @"ftp://[email protected]/share/Path/subpath", @"../Path/subpath/",
                         @"ftp://[email protected]/share/path/subpath", @"ftp://[email protected]/share/path/othersubpath", @"../othersubpath/",
                         @"ftp://[email protected]/share/path/subpath", @"ftp://[email protected]/share/Path/othersubpath", @"../../Path/othersubpath/",
                         @"ftp://[email protected]/path", @"ftp://[email protected]/otherpath/", @"../otherpath/",

                         @"C:\a\b\c\d", @"C:\.dottedname", @"..\..\..\..\.dottedname\",
                         @"C:\a\b\c\d", @"C:\..dottedname", @"..\..\..\..\..dottedname\",
                         @"C:\a\b\c\d", @"C:\a\.dottedname", @"..\..\..\.dottedname\",
                         @"C:\a\b\c\d", @"C:\a\..dottedname", @"..\..\..\..dottedname\",

                         "C:\\a\\b\\", @"C:\a\b", @"",
                         @"C:\a\b", "C:\\a\\b\\", @""
                         ))
            {
                var expected = testCase.Item3;
                var actual   = CommonUtils.GetRelativeDirectoryPath(testCase.Item1, testCase.Item2);

                Assert.AreEqual(expected, actual, string.Format("From {0} to {1}", testCase.Item1, testCase.Item2));
            }
        }
Example #11
0
        public void TestGetFileOrDirectoryName()
        {
            foreach (var testCase in Pairs(
                         @"a\b\c", @"c",
                         @"a\b\", @"b",
                         @"a\b\c\", @"c",
                         @"a", @"a",
                         @"a\", @"a"
                         ))
            {
                foreach (var scheme in new[] { "", "C:\\", "\\", ".\\", "\\\\share\\root\\", "ftp://" })
                {
                    var path     = scheme + testCase.Item1;
                    var expected = testCase.Item2;

                    Assert.AreEqual(expected, CommonUtils.GetFileOrDirectoryName(path), "Path: " + path);

                    if (scheme.Contains("://"))
                    {
                        // Path.GetFileName will always fail on these, so don't
                        // even bother testing.
                        continue;
                    }

                    string ioPathResult;
                    try {
                        ioPathResult = CommonUtils.GetFileOrDirectoryName(path);
                    } catch (ArgumentException) {
                        continue;
                    }

                    Assert.AreEqual(
                        CommonUtils.GetFileOrDirectoryName(path),
                        ioPathResult ?? string.Empty,
                        "Did not match Path.GetDirectoryName(...) result for " + path
                        );
                }
            }
        }
Example #12
0
        public void TestPublishVirtualEnvironment(VisualStudioApp app)
        {
            var project = app.OpenProject(app.CopyProjectForTest(@"TestData\VirtualEnv.sln"));
            var dir     = TestData.GetTempPath();

            project.Properties.Item("PublishUrl").Value = dir;
            app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");

            app.OpenSolutionExplorer().SelectProject(project);
            var files = PublishAndWaitForFiles(app, "Build.PublishSelection", dir);

            Assert.IsNotNull(files, "Timed out waiting for files to publish");
            AssertUtil.ContainsAtLeast(
                files.Select(f => CommonUtils.GetRelativeFilePath(dir, f).ToLowerInvariant()),
                "env\\include\\pyconfig.h",
                "env\\lib\\site.py",
                "env\\scripts\\python.exe",
                "program.py"
                );

            Directory.Delete(dir, true);
        }
Example #13
0
        public void TestGetLastDirectoryName()
        {
            foreach (var testCase in Pairs(
                         @"a\b\c", "b",
                         @"a\b\", "b",
                         @"a\b\c\", "c",
                         @"a\b\.\c", "b",
                         @"a\b\.\.\.\.\.\.\c", "b"
                         ))
            {
                foreach (var scheme in new[] { "", "C:\\", "\\", ".\\", "\\\\share\\root\\", "ftp://" })
                {
                    var path = scheme + testCase.Item1;

                    Assert.AreEqual(testCase.Item2, CommonUtils.GetLastDirectoryName(path), "Path: " + path);

                    if (path.IndexOf('.') >= 0)
                    {
                        // Path.GetFileName will always fail on these, so don't
                        // even bother testing.
                        continue;
                    }

                    string ioPathResult;
                    try {
                        ioPathResult = Path.GetFileName(CommonUtils.TrimEndSeparator(Path.GetDirectoryName(path)));
                    } catch (ArgumentException) {
                        continue;
                    }

                    Assert.AreEqual(
                        CommonUtils.GetLastDirectoryName(path),
                        ioPathResult ?? string.Empty,
                        "Did not match Path.GetFileName(...) result for " + path
                        );
                }
            }
        }