AddDirectory() 공개 메소드

public AddDirectory ( string path ) : void
path string
리턴 void
예제 #1
0
        public void TestCleanRecursive()
        {
            // Prepare the source and target directories and files.
            var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
            fileSystem.AddDirectory(@"C:\Source\SubDirectory");
            fileSystem.AddFile(@"C:\Target\SubDirectory\File.txt", new MockFileData("Data"));

            // Run the test.
            Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source");

            // Check the results
            Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\SubDirectory\File.txt"));
        }
예제 #2
0
        public void TestCleanByPattern()
        {
            // Prepare the source and target directories and files.
            var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
            fileSystem.AddDirectory(@"C:\Source");
            fileSystem.AddFile(@"C:\Target\File.txt", new MockFileData("Data"));
            fileSystem.AddFile(@"C:\Target\File.doc", new MockFileData("Data"));

            // Run the test.
            Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source", "*.txt");

            // Check the clean has worked properly.
            Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\File.txt"));
            Assert.IsTrue(fileSystem.File.Exists(@"C:\Target\File.doc"));
        }
예제 #3
0
 public void TestPushDirectoryWhenSourceIsNotFound()
 {
     var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
     fileSystem.AddDirectory(@"C:\Target");
     try
     {
         Pusher.PushDirectory(fileSystem, @"C:\Source", @"C:\Target");
         Assert.Fail("Exception not raised.");
     }
     catch (SyncDirectoryNotFoundException)
     {
     }
     catch
     {
         Assert.Fail("Wrong exception raised.");
     }
 }
예제 #4
0
        public void TestCleanByAttributes()
        {
            // Prepare the source and target directories and files.
            var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
            fileSystem.AddDirectory(@"C:\Source");
            fileSystem.AddFile(@"C:\Target\File1.txt", new MockFileData("Data"));
            fileSystem.AddFile(@"C:\Target\File2.txt", new MockFileData("Data"));
            fileSystem.File.SetAttributes(@"C:\Target\File1.txt", FileAttributes.Normal);
            fileSystem.File.SetAttributes(@"C:\Target\File2.txt", FileAttributes.Hidden);

            // Run the test.
            Cleaner.CleanResult result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source", "*.*", FileAttributes.Normal);

            // Check the results
            Assert.IsFalse(fileSystem.File.Exists(@"C:\Target\File1.txt"));
            Assert.IsTrue(fileSystem.File.Exists(@"C:\Target\File2.txt"));
        }
예제 #5
0
        public void Should_Process_Less_Imports_With_Cleanup()
        {
            // arrange
            var filepath1 = @"c:\css\subfolder\style-dependency.less";
            var fileContent1 = "@brand_color: #4D926F;";
            var filepath2 = @"c:\css\style.less";
            var fileContent2 = "@import \"subfolder/style-dependency.less\"; @import \"foldertodelete/style-dependency2.less\"; @import \"foldertodelete/style-dependency3.less\"; @import \"../_site/style-dependency4.less\"; a { color: @brand_color; width: @width; height: @height; foo: @bar; }";
            var filepath3 = @"c:\css\foldertodelete\style-dependency2.less";
            var fileContent3 = "@width: 24px;";
            var filepath4 = @"c:\css\foldertodelete\style-dependency3.less";
            var fileContent4 = "@height: 24px;";
            var filepath5 = @"c:\_site\style-dependency4.less";
            var fileContent5 = "@bar: bold;";

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { HtmlFilePath, new MockFileData(PageContent)},
                { filepath1, new MockFileData(fileContent1) },
                { filepath2, new MockFileData(fileContent2) },
                { filepath3, new MockFileData(fileContent3) },
                { filepath4, new MockFileData(fileContent4) },
                { filepath5, new MockFileData(fileContent5) },
                { @"c:\css\subfolder\anothersubfolder\anything.less", "@size: 12px;" }
            });
            fileSystem.AddDirectory(@"c:\css\emptysubfolder");

            var expectedOutput = @"a{color:#4d926f;width:24px;height:24px;foo:bold}";

            var minifier = new LessTransform(fileSystem);
            var context = new SiteContext { SourceFolder = @"C:\", OutputFolder = @"C:\_site" };
            context.Pages.Add(new NonProcessedPage { OutputFile = HtmlFilePath, Content = PageContent });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath1, Content = fileContent1, Filepath = filepath1 });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath2, Content = fileContent2, Filepath = filepath2 });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath3, Content = fileContent3, Filepath = filepath3 });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath4, Content = fileContent4, Filepath = filepath4 });
            context.Pages.Add(new NonProcessedPage { OutputFile = filepath5, Content = fileContent5, Filepath = filepath5 });

            // act
            minifier.Transform(context);

            // assert
            var minifiedFile = fileSystem.File.ReadAllText(@"c:\css\style.css", Encoding.UTF8);
            Assert.Equal(expectedOutput, minifiedFile);
            Assert.True(fileSystem.Directory.Exists(@"c:\css\emptysubfolder"));
            Assert.False(fileSystem.Directory.Exists(@"c:\css\foldertodelete"));
            Assert.False(fileSystem.File.Exists(@"c:\css\style.less"));
            Assert.True(fileSystem.Directory.Exists(@"c:\css\subfolder"));
            Assert.True(fileSystem.File.Exists(@"c:\css\subfolder\anothersubfolder\anything.less"));
            Assert.True(fileSystem.Directory.Exists(@"c:\_site"));
        }
예제 #6
0
        public void TestSaveMaxEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { });
            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add("FileSystem", fsp);
            fsp.Add(new Entry(@"c:\dir1\", 12, DateTime.Now, false));
            fsp.Add(new Entry(@"c:\dir1\file2", 34, DateTime.Now, true));
            db.Save(1);
            db.Load();

            Assert.AreEqual(1,db.Providers["FileSystem"].Entries.Count);
        }
예제 #7
0
        public void TestGetEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { });
            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add("FileSystem", fsp);
            var e1 = new Entry(@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry(@"c:\dir1\file2", 34, DateTime.Now, true);
            fsp.Add(e1);
            fsp.Add(e2);

            Entry[] entries = null;
            Assert.IsTrue(db.GetEntries("FileSystem", out entries));
            Assert.AreEqual(e2, entries[0]);
            Assert.AreEqual(e1, entries[1]);
        }
예제 #8
0
        public void TestConfigSimpleDatabase()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> {});
            fileSystem.AddDirectory (Database.DefaultConfigDir);

            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add ("FileSystem", fsp);
            var e1 = new Entry (@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry (@"c:\dir1\file2", 34, DateTime.Now, true);

            fsp.Add(e1);
            fsp.Add(e2);
            db.Save(100);

            var fsFileName = System.IO.Path.Combine (Database.DefaultConfigDir,$"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            Assert.AreEqual(
                string.Join(Environment.NewLine,e1.ToString(),e2.ToString(),""),
                fileSystem.File.ReadAllText(fsFileName));
        }
예제 #9
0
        public void TestConfigLoadFileNotFound()
        {
            var fileSystem = new MockFileSystem();
            fileSystem.AddDirectory(Database.DefaultConfigDir);

            var db = new Database(fileSystem);
            db.Load();
        }
예제 #10
0
 public void TestPushDirectoryWhenSourcePathIsNull()
 {
     var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
     fileSystem.AddDirectory(@"C:\Target");
     try
     {
         Pusher.PushDirectory(fileSystem, null, @"C:\Target");
         Assert.Fail("Exception not raised.");
     }
     catch (ArgumentNullException)
     {
     }
     catch
     {
         Assert.Fail("Wrong exception raised.");
     }
 }
예제 #11
0
        public void Setup()
        {
            _mocker = new AutoMoqer();

            // GetMock of the abstract class before create to prevent automoq bugs
            _mocker.GetMock<FileSystemWatcherBase>();

            _fileSystem = new MockFileSystem();
            _fileSystem.AddDirectory(BaseDirectory);
            _mocker.SetInstance<IFileSystem>(_fileSystem);
        }
예제 #12
0
        public void TestCleanResult()
        {
            // Prepare the source and target directories and files.
            var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
            fileSystem.AddFile(@"C:\Source\File1.txt", new MockFileData("Data"));
            fileSystem.AddFile(@"C:\Target\File1.txt", new MockFileData("Data"));
            fileSystem.AddFile(@"C:\Target\File2.txt", new MockFileData("Data"));
            fileSystem.AddDirectory(@"C:\Source\SubDirectory");
            fileSystem.AddDirectory(@"C:\Target\SubDirectory");

            // Run the test.
            var result = Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source");

            // Check the result.
            Assert.AreEqual(1, result.MatchedFiles.Count);
            Assert.AreEqual("File1.txt", result.MatchedFiles[0]);
            Assert.AreEqual(1, result.DeletedEntries.Count);
            Assert.AreEqual("File2.txt", result.DeletedEntries[0]);
            Assert.AreEqual(0, result.FailedEntries.Count);
            // TODO:: figure out how to spoof a fail an entry?
            Assert.AreEqual(1, result.DirectoryResults.Count);
        }
예제 #13
0
 public void TestCleanWhenSourceIsNotFound()
 {
     var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem();
     fileSystem.AddDirectory(@"C:\Target");
     try
     {
         Cleaner.Clean(fileSystem, @"C:\Target", @"C:\Source");
         Assert.Fail("Exception not raised.");
     }
     catch (SyncDirectoryNotFoundException)//TODO:: replace with straight System.IO.Exception?
     { }
     catch
     {
         Assert.Fail("Wrong exception raised.");
     }
 }