コード例 #1
0
        public void ShadowGetUrl()
        {
            // Arrange
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "rootUrl");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "rootUrl");
            var ss  = new ShadowFileSystem(fs, sfs);

            // Act
            File.WriteAllText(path + "/ShadowTests/f1.txt", "foo");
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("f2.txt", ms);

            // Assert
            var f1Url = ss.GetUrl("f1.txt");
            var f2Url = ss.GetUrl("f2.txt");

            Assert.AreEqual("rootUrl/f1.txt", f1Url);
            Assert.AreEqual("rootUrl/f2.txt", f2Url);
            Assert.IsTrue(File.Exists(Path.Combine(path, "ShadowTests", "f1.txt")));
            Assert.IsFalse(File.Exists(Path.Combine(path, "ShadowTests", "f2.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(path, "ShadowSystem", "f2.txt")));
            Assert.IsFalse(File.Exists(Path.Combine(path, "ShadowSystem", "f1.txt")));
        }
コード例 #2
0
        public void ShadowDeleteDirectory()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            Directory.CreateDirectory(path + "/ShadowTests/d1");
            Directory.CreateDirectory(path + "/ShadowTests/d2");

            var files = fs.GetFiles("");

            Assert.AreEqual(0, files.Count());

            var dirs = fs.GetDirectories("");

            Assert.AreEqual(2, dirs.Count());
            Assert.IsTrue(dirs.Contains("d1"));
            Assert.IsTrue(dirs.Contains("d2"));

            ss.DeleteDirectory("d1");

            Assert.IsTrue(Directory.Exists(path + "/ShadowTests/d1"));
            Assert.IsTrue(fs.DirectoryExists("d1"));
            Assert.IsFalse(ss.DirectoryExists("d1"));

            dirs = ss.GetDirectories("");
            Assert.AreEqual(1, dirs.Count());
            Assert.IsTrue(dirs.Contains("d2"));
        }
コード例 #3
0
        public void ShadowGetFilesUsingNullFilter()
        {
            // Arrange
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            // Act
            File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("f1.txt", ms);

            // Assert
            // ensure we get 2 files from the shadow
            var getFiles = ss.GetFiles(string.Empty);

            Assert.AreEqual(2, getFiles.Count());
            // ensure we get 2 files when using null in filter parameter
            var getFilesWithNullFilter = ss.GetFiles(string.Empty, null);

            Assert.AreEqual(2, getFilesWithNullFilter.Count());

            var fsFiles = fs.GetFiles(string.Empty).ToArray();

            Assert.AreEqual(1, fsFiles.Length);
            var sfsFiles = sfs.GetFiles(string.Empty).ToArray();

            Assert.AreEqual(1, sfsFiles.Length);
        }
コード例 #4
0
        public void ShadowGetFullPath()
        {
            // Arrange
            var path = Current.IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            // Act
            File.WriteAllText(path + "/ShadowTests/f1.txt", "foo");
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("f2.txt", ms);

            // Assert
            var f1FullPath = ss.GetFullPath("f1.txt");
            var f2FullPath = ss.GetFullPath("f2.txt");

            Assert.AreEqual(Path.Combine(path, "ShadowTests", "f1.txt"), f1FullPath);
            Assert.AreEqual(Path.Combine(path, "ShadowSystem", "f2.txt"), f2FullPath);
        }
コード例 #5
0
        public void ShadowComplete()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            Directory.CreateDirectory(path + "/ShadowTests/sub/sub");
            File.WriteAllText(path + "/ShadowTests/sub/sub/f2.txt", "foo");

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("path/to/some/dir/f1.txt", ms);
            ss.DeleteFile("sub/sub/f2.txt");

            Assert.IsTrue(File.Exists(path + "/ShadowSystem/path/to/some/dir/f1.txt"));

            ss.Complete();

            // yes we are cleaning now
            //Assert.IsTrue(File.Exists(path + "/ShadowSystem/path/to/some/dir/f1.txt")); // *not* cleaning
            Assert.IsTrue(File.Exists(path + "/ShadowTests/path/to/some/dir/f1.txt"));
            Assert.IsFalse(File.Exists(path + "/ShadowTests/sub/sub/f2.txt"));
        }
コード例 #6
0
    public void ShadowGetFilesUsingEmptyFilter()
    {
        // Arrange
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        // Act
        File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");
        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("f1.txt", ms);
        }

        // Assert
        // ensure we get 2 files from the shadow
        var getFiles = ss.GetFiles(string.Empty);

        Assert.AreEqual(2, getFiles.Count());

        var fsFiles = fs.GetFiles(string.Empty).ToArray();

        Assert.AreEqual(1, fsFiles.Length);
        var sfsFiles = sfs.GetFiles(string.Empty).ToArray();

        Assert.AreEqual(1, sfsFiles.Length);
    }
コード例 #7
0
    public void ShadowGetRelativePath()
    {
        // Arrange
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        // Act
        File.WriteAllText(path + "/ShadowTests/f1.txt", "foo");
        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("f2.txt", ms);
        }

        // Assert
        var f1RelativePath = ss.GetRelativePath("f1.txt");
        var f2RelativePath = ss.GetRelativePath("f2.txt");

        Assert.AreEqual("f1.txt", f1RelativePath);
        Assert.AreEqual("f2.txt", f2RelativePath);
        Assert.IsTrue(File.Exists(Path.Combine(path, "ShadowTests", "f1.txt")));
        Assert.IsFalse(File.Exists(Path.Combine(path, "ShadowTests", "f2.txt")));
        Assert.IsTrue(File.Exists(Path.Combine(path, "ShadowSystem", "f2.txt")));
        Assert.IsFalse(File.Exists(Path.Combine(path, "ShadowSystem", "f1.txt")));
    }
コード例 #8
0
    public void ShadowDeleteDirectory()
    {
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        Directory.CreateDirectory(path + "/ShadowTests/d1");
        Directory.CreateDirectory(path + "/ShadowTests/d2");

        var files = fs.GetFiles(string.Empty);

        Assert.AreEqual(0, files.Count());

        var dirs = fs.GetDirectories(string.Empty);

        Assert.AreEqual(2, dirs.Count());
        Assert.IsTrue(dirs.Contains("d1"));
        Assert.IsTrue(dirs.Contains("d2"));

        ss.DeleteDirectory("d1");

        Assert.IsTrue(Directory.Exists(path + "/ShadowTests/d1"));
        Assert.IsTrue(fs.DirectoryExists("d1"));
        Assert.IsFalse(ss.DirectoryExists("d1"));

        dirs = ss.GetDirectories(string.Empty);
        Assert.AreEqual(1, dirs.Count());
        Assert.IsTrue(dirs.Contains("d2"));
    }
コード例 #9
0
        public void ShadowDeleteFileInDir()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            Directory.CreateDirectory(path + "/ShadowTests/sub");
            File.WriteAllText(path + "/ShadowTests/sub/f1.txt", "foo");
            File.WriteAllText(path + "/ShadowTests/sub/f2.txt", "foo");

            var files = fs.GetFiles("");

            Assert.AreEqual(0, files.Count());

            files = fs.GetFiles("sub");
            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.Contains("sub/f1.txt"));
            Assert.IsTrue(files.Contains("sub/f2.txt"));

            files = ss.GetFiles("");
            Assert.AreEqual(0, files.Count());

            var dirs = ss.GetDirectories("");

            Assert.AreEqual(1, dirs.Count());
            Assert.IsTrue(dirs.Contains("sub"));

            files = ss.GetFiles("sub");
            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.Contains("sub/f1.txt"));
            Assert.IsTrue(files.Contains("sub/f2.txt"));

            dirs = ss.GetDirectories("sub");
            Assert.AreEqual(0, dirs.Count());

            ss.DeleteFile("sub/f1.txt");

            Assert.IsTrue(File.Exists(path + "/ShadowTests/sub/f1.txt"));
            Assert.IsTrue(fs.FileExists("sub/f1.txt"));
            Assert.IsFalse(ss.FileExists("sub/f1.txt"));

            files = fs.GetFiles("sub");
            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.Contains("sub/f1.txt"));
            Assert.IsTrue(files.Contains("sub/f2.txt"));

            files = ss.GetFiles("sub");
            Assert.AreEqual(1, files.Count());
            Assert.IsTrue(files.Contains("sub/f2.txt"));
        }
コード例 #10
0
    public void ShadowGetFilesUsingSingleCharacterFilter()
    {
        // Arrange
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        // Act
        File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");
        File.WriteAllText(path + "/ShadowTests/f2.doc", "foo");
        File.WriteAllText(path + "/ShadowTests/f2.docx", "foo");
        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("f1.txt", ms);
        }

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("f1.doc", ms);
        }

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("f1.docx", ms);
        }

        // Assert
        // ensure we get 6 files from the shadow
        var getFiles = ss.GetFiles(string.Empty);

        Assert.AreEqual(6, getFiles.Count());
        // ensure we get only 2 of 6 files from the shadow when using filter on shadow
        var getFilesWithWildcardSinglecharFilter = ss.GetFiles(string.Empty, "f1.d?c");

        Assert.AreEqual(1, getFilesWithWildcardSinglecharFilter.Count());
        // ensure we get only 2 of 6 files from the shadow when using filter on disk
        var getFilesWithWildcardSinglecharFilter2 = ss.GetFiles(string.Empty, "f2.d?c");

        Assert.AreEqual(1, getFilesWithWildcardSinglecharFilter2.Count());

        var fsFiles = fs.GetFiles(string.Empty).ToArray();

        Assert.AreEqual(3, fsFiles.Length);
        var sfsFiles = sfs.GetFiles(string.Empty).ToArray();

        Assert.AreEqual(3, sfsFiles.Length);
    }
コード例 #11
0
    public void ShadowCreateFileInDir()
    {
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
        {
            ss.AddFile("sub/f1.txt", ms);
        }

        Assert.IsFalse(File.Exists(path + "/ShadowTests/sub/f1.txt"));
        Assert.IsTrue(File.Exists(path + "/ShadowSystem/sub/f1.txt"));
        Assert.IsFalse(fs.FileExists("sub/f1.txt"));
        Assert.IsTrue(ss.FileExists("sub/f1.txt"));

        Assert.IsFalse(fs.DirectoryExists("sub"));
        Assert.IsTrue(ss.DirectoryExists("sub"));

        var dirs = fs.GetDirectories(string.Empty);

        Assert.AreEqual(0, dirs.Count());

        dirs = ss.GetDirectories(string.Empty);
        Assert.AreEqual(1, dirs.Count());
        Assert.IsTrue(dirs.Contains("sub"));

        var files = ss.GetFiles("sub");

        Assert.AreEqual(1, files.Count());

        string content;

        using (var stream = ss.OpenFile("sub/f1.txt"))
        {
            content = new StreamReader(stream).ReadToEnd();
        }

        Assert.AreEqual("foo", content);
    }
コード例 #12
0
        public void ShadowCantCreateFile()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            Assert.Throws <FileSecurityException>(() =>
            {
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                    ss.AddFile("../../f1.txt", ms);
            });
        }
コード例 #13
0
        public void ShadowCantCreateFile()
        {
            var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            Assert.Throws <UnauthorizedAccessException>(() =>
            {
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                    ss.AddFile("../../f1.txt", ms);
            });
        }
コード例 #14
0
        public void ShadowAbort()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("path/to/some/dir/f1.txt", ms);

            // file is only written to the shadow fs
            Assert.IsTrue(File.Exists(path + "/ShadowSystem/path/to/some/dir/f1.txt"));
            Assert.IsFalse(File.Exists(path + "/ShadowTests/path/to/some/dir/f1.txt"));
            // let the shadow fs die
        }
コード例 #15
0
        public void ShadowCreateFile()
        {
            var path = IOHelper.MapPath("FileSysTests");

            Directory.CreateDirectory(path);
            Directory.CreateDirectory(path + "/ShadowTests");
            Directory.CreateDirectory(path + "/ShadowSystem");

            var fs  = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
            var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
            var ss  = new ShadowFileSystem(fs, sfs);

            File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
                ss.AddFile("f1.txt", ms);

            Assert.IsTrue(File.Exists(path + "/ShadowTests/f2.txt"));
            Assert.IsFalse(File.Exists(path + "/ShadowSystem/f2.txt"));
            Assert.IsTrue(fs.FileExists("f2.txt"));
            Assert.IsTrue(ss.FileExists("f2.txt"));

            Assert.IsFalse(File.Exists(path + "/ShadowTests/f1.txt"));
            Assert.IsTrue(File.Exists(path + "/ShadowSystem/f1.txt"));
            Assert.IsFalse(fs.FileExists("f1.txt"));
            Assert.IsTrue(ss.FileExists("f1.txt"));

            var files = ss.GetFiles("");

            Assert.AreEqual(2, files.Count());
            Assert.IsTrue(files.Contains("f1.txt"));
            Assert.IsTrue(files.Contains("f2.txt"));

            string content;

            using (var stream = ss.OpenFile("f1.txt"))
                content = new StreamReader(stream).ReadToEnd();

            Assert.AreEqual("foo", content);
        }
コード例 #16
0
    public void ShadowDeleteFile()
    {
        var path = HostingEnvironment.MapPathContentRoot("FileSysTests");

        Directory.CreateDirectory(path);
        Directory.CreateDirectory(path + "/ShadowTests");
        Directory.CreateDirectory(path + "/ShadowSystem");

        var fs  = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowTests/", "ignore");
        var sfs = new PhysicalFileSystem(IOHelper, HostingEnvironment, Logger, path + "/ShadowSystem/", "ignore");
        var ss  = new ShadowFileSystem(fs, sfs);

        File.WriteAllText(path + "/ShadowTests/f1.txt", "foo");
        File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");

        var files = fs.GetFiles(string.Empty);

        Assert.AreEqual(2, files.Count());
        Assert.IsTrue(files.Contains("f1.txt"));
        Assert.IsTrue(files.Contains("f2.txt"));

        files = ss.GetFiles(string.Empty);
        Assert.AreEqual(2, files.Count());
        Assert.IsTrue(files.Contains("f1.txt"));
        Assert.IsTrue(files.Contains("f2.txt"));

        var dirs = ss.GetDirectories(string.Empty);

        Assert.AreEqual(0, dirs.Count());

        ss.DeleteFile("f1.txt");

        Assert.IsTrue(File.Exists(path + "/ShadowTests/f1.txt"));
        Assert.IsTrue(fs.FileExists("f1.txt"));
        Assert.IsFalse(ss.FileExists("f1.txt"));

        files = ss.GetFiles(string.Empty);
        Assert.AreEqual(1, files.Count());
        Assert.IsTrue(files.Contains("f2.txt"));
    }