Ejemplo n.º 1
0
        public void RelativeNameSameRoot()
        {
            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("1/1/test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\1");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("1/test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\");
                var fileInfo          = new FileInfo(@"C:\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("1/test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\1\1");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\1");
                var fileInfo          = new FileInfo(@"C:\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"C:\");
                var fileInfo          = new FileInfo(@"C:\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual("test.txt".Replace('/', Path.DirectorySeparatorChar), relativeFileName);
            }
        }
Ejemplo n.º 2
0
        public void RelativeNameDifferentRoot()
        {
            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\1");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\1\1");
                var fileInfo          = new FileInfo(@"C:\1\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\");
                var fileInfo          = new FileInfo(@"C:\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\1");
                var fileInfo          = new FileInfo(@"C:\1\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }

            {
                var baseDirectoryInfo = new DirectoryInfo(@"D:\");
                var fileInfo          = new FileInfo(@"C:\test.txt");

                var allorsFileInfo   = new AllorsFileInfo(fileInfo);
                var relativeFileName = allorsFileInfo.GetRelativeName(baseDirectoryInfo);

                Assert.AreEqual(null, relativeFileName);
            }
        }