Esempio n. 1
0
        public void FileSystemWatcher_Renamed_Negative()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
            using (var watcher = new FileSystemWatcher(testDirectory.Path))
            {
                // put everything in our own directory to avoid collisions
                watcher.Path = Path.GetFullPath(dir.Path);
                watcher.Filter = "*.*";
                AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Renamed);

                watcher.EnableRaisingEvents = true;

                // run all scenarios together to avoid unnecessary waits, 
                // assert information is verbose enough to trace to failure cause

                // create a file
                using (var testFile = new TempFile(Path.Combine(dir.Path, "file")))
                using (var testDir = new TempDirectory(Path.Combine(dir.Path, "dir")))
                {
                    // change a file
                    File.WriteAllText(testFile.Path, "changed");

                    // deleting a file & directory by leaving the using block
                }

                ExpectNoEvent(eventOccurred, "created");
            }
        }
 public void GetFile_returns_null_when_file_not_found()
 {
     using(var dir = new TempDirectory())
     {
         Assert.IsNull(dir.DirectoryInfo.GetFile("does_not_exist.txt"));
     }
 }
Esempio n. 3
0
        public void FileSystemWatcher_Created_MoveDirectory()
        {
            // create two test directories
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (TempDirectory originalDir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
            using (TempDirectory targetDir = new TempDirectory(originalDir.Path + "_target"))
            using (var watcher = new FileSystemWatcher(testDirectory.Path))
            {
                string testFileName = GetTestFileName();

                // watch the target dir
                watcher.Path = Path.GetFullPath(targetDir.Path);
                watcher.Filter = testFileName;
                AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Created);

                string sourceFile = Path.Combine(originalDir.Path, testFileName);
                string targetFile = Path.Combine(targetDir.Path, testFileName);

                // create a test file in source
                File.WriteAllText(sourceFile, "test content");

                watcher.EnableRaisingEvents = true;

                // move the test file from source to target directory
                File.Move(sourceFile, targetFile);

                ExpectEvent(eventOccurred, "created");
            }
        }
        public void AddFileNamesTest()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                tempDirectory.AddDirectory("A");

                var manager = new ResultImageManager2(tempDirectory.Name);
                manager.AddFileNames(new []
                {
                    tempDirectory.FullPath(@"A\file0.png"),
                    tempDirectory.FullPath(@"A\file1.png"),
            //					tempDirectory.FullPath(@"file2.png"),
                });

                CollectionAssert.AreEquivalent(new []
                {
                    tempDirectory.FullPath(@"A\file0.png"),
                    tempDirectory.FullPath(@"A\file1.png"),
            //					tempDirectory.FullPath(@"file2.png"),
                }, manager.Files);

            //				Assert.AreEqual(tempDirectory.FullPath(@"file2.png"), manager.GetFile("B"));
                Assert.Null(manager.GetFile("B"));
                Assert.AreEqual(tempDirectory.FullPath(@"A\file0.png"), manager.GetFile("A"));
                Assert.AreEqual(tempDirectory.FullPath(@"A\file1.png"), manager.GetFile("A"));
            }
        }
Esempio n. 5
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenBundleAssetsReplacedWithCachedAsset()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"1\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test.bundle"),
                    "asset"
                    );
                var bundleWithAsset = new TestableBundle("~/test");
                var asset = StubAsset();
                bundleWithAsset.Assets.Add(asset.Object);
                var sourceBundles = new[] { bundleWithAsset };

                var settings = new CassetteSettings
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
                bundleWithAsset.Assets[0].OpenStream().ReadToEnd().ShouldEqual("asset");
            }
        }
Esempio n. 6
0
        public void CanRobocopy()
        {
            var executableDirectory = DirectoryHelper.ExecutingDirectory();

            var outputDirectory = Path.Combine(executableDirectory.FullName, "Robo");

            var tasks = TaskHelper.Start()
            .AddTask("Initialize directories", (ctx, arg) => {
                var tempDir1 = new TempDirectory(outputDirectory, ctx.ProjectName);
                var tempDir2 = new TempDirectory(outputDirectory, ctx.ProjectName);

                File.AppendAllText(Path.Combine(tempDir1.DirectoryPath, "testfile.txt"), "test data");

                ctx.RegisterCleanup(() => { tempDir1.Dispose(); tempDir2.Dispose(); });

                return new RobocopyArgs(tempDir1.DirectoryPath, tempDir2.DirectoryPath);
            })
            .Robocopy()
            .AddStep((ctx, arg) => {
                var exists = File.Exists(Path.Combine(arg.CopiedToDirectory, "testfile.txt"));
                Assert.IsTrue(exists);
                return exists;
            })
            .Finalize();

            var command = new KissCommand("build", tasks);

            var project = new KissProject("TestProject", "UI", command);

            using (var projectService = TestHelper.GetService())
            {
                projectService.RegisterProject(project);
                ProjectHelper.Run(project, command, projectService);
            }
        }
Esempio n. 7
0
        public void GivenCacheIsUpToDate_WhenInitializeBundlesFromCacheIfUpToDate_ThenReturnTrue()
        {
            using (var cacheDir = new TempDirectory())
            {
                File.WriteAllText(
                    Path.Combine(cacheDir, "container.xml"),
                    "<?xml version=\"1.0\"?><Container Version=\"VERSION\" AssetCount=\"0\"><Bundle Path=\"~/test\" Hash=\"01\"/></Container>"
                    );
                File.WriteAllText(
                    Path.Combine(cacheDir, "test.bundle"),
                    "asset"
                    );

                var bundle = new TestableBundle("~/test");
                var sourceBundles = new[] { bundle };

                var settings = new CassetteSettings("")
                {
                    SourceDirectory = Mock.Of<IDirectory>(),
                    CacheDirectory = new FileSystemDirectory(cacheDir)
                };
                var cache = new BundleCache("VERSION", settings);
                var result = cache.InitializeBundlesFromCacheIfUpToDate(sourceBundles);

                result.ShouldBeTrue();
            }
        }
        public CreateBundlesWithRawFilesTests()
        {
            root = new TempDirectory();

            CreateDirectory("source");
            CreateDirectory("source\\bin");
            CreateDirectory("output");

            WriteFile("source\\test.css", @"p { background: url(test.png); } .other { background: url(notfound.png); }");
            WriteFile("source\\test.png", "image");

            var configurationDll = CompileConfigurationDll();

            File.Move(configurationDll, PathUtilities.Combine(root, "source", "bin", "test.dll"));
            File.Copy("Cassette.dll", PathUtilities.Combine(root, "source", "bin", "Cassette.dll"));
            File.Copy("Cassette.pdb", PathUtilities.Combine(root, "source", "bin", "Cassette.pdb"));
            File.Copy("AjaxMin.dll", PathUtilities.Combine(root, "source", "bin", "AjaxMin.dll"));
            #if NET35
            File.Copy("Iesi.Collections.dll", PathUtilities.Combine(root, "source", "bin", "Iesi.Collections.dll"));
            #endif

            var command = new CreateBundlesCommand(
                PathUtilities.Combine(root, "source"),
                PathUtilities.Combine(root, "source", "bin"),
                PathUtilities.Combine(root, "output"),
                true
            );

            CreateBundlesCommand.ExecuteInSeparateAppDomain(command);
        }
        public void FileSystemWatcher_IncludeSubDirectories_Directory()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
            using (var watcher = new FileSystemWatcher(Path.GetFullPath(dir.Path)))
            {
                string dirPath = Path.GetFullPath(dir.Path);
                string subDirPath = Path.Combine(dirPath, "subdir");

                watcher.Path = dirPath;
                watcher.IncludeSubdirectories = true;
                AutoResetEvent eventOccurred = WatchForEvents(watcher, WatcherChangeTypes.Created);

                Directory.CreateDirectory(subDirPath);

                watcher.EnableRaisingEvents = true;

                Directory.CreateDirectory(Path.Combine(subDirPath, "1"));
                ExpectEvent(eventOccurred, "created");

                watcher.IncludeSubdirectories = false;
                Directory.CreateDirectory(Path.Combine(subDirPath, "2"));
                ExpectNoEvent(eventOccurred, "created");

                watcher.IncludeSubdirectories = true;
                Directory.CreateDirectory(Path.Combine(subDirPath, "3"));
                ExpectEvent(eventOccurred, "created");
            }
        }
Esempio n. 10
0
 public void GivenSubDirectoryDoesNotExist_WhenDirectoryExists_ThenReturnFalse()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("sub").ShouldBeFalse();
     }
 }
Esempio n. 11
0
 public void WhenCallDirectoryExistsWithJustTilder_ThenReturnTrue()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         dir.DirectoryExists("~").ShouldBeTrue();
     }
 }
Esempio n. 12
0
 public TempConfig(string contents)
 {
     _directory = new TempDirectory();
     ExePath = Path.Combine(_directory.Path, Path.GetRandomFileName() + ".exe");
     File.WriteAllText(ExePath, "dummy exe");
     ConfigPath = ExePath + ".config";
     File.WriteAllText(ConfigPath, contents);
 }
 public void Can_create_temporary_file()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile();
         Assert.IsTrue(file.Exists);
     }
 }
Esempio n. 14
0
 public void GivenFileDoesNotExist_WhenGetFile_ThenReturnFileSystemFile()
 {
     using (var path = new TempDirectory())
     {
         var dir = new FileSystemDirectory(path);
         var file = dir.GetFile("test.txt");
         file.ShouldBeType<FileSystemFile>();
     }
 }
        public void MergedSecrets_PrioritizesFunctionSecrets()
        {
            using (var directory = new TempDirectory())
            {
                string hostSecrets =
                    @"{
    'masterKey': {
        'name': 'master',
        'value': '1234',
        'encrypted': false
    },
    'functionKeys': [
        {
            'name': 'Key1',
            'value': 'HostValue1',
            'encrypted': false
        },
        {
            'name': 'Key3',
            'value': 'HostValue3',
            'encrypted': false
        }
    ]
}";
                string functionSecrets =
                    @"{
    'keys': [
        {
            'name': 'Key1',
            'value': 'FunctionValue1',
            'encrypted': false
        },
        {
            'name': 'Key2',
            'value': 'FunctionValue2',
            'encrypted': false
        }
    ]
}";
                File.WriteAllText(Path.Combine(directory.Path, ScriptConstants.HostMetadataFileName), hostSecrets);
                File.WriteAllText(Path.Combine(directory.Path, "testfunction.json"), functionSecrets);

                IDictionary<string, string> result;
                using (var secretManager = new SecretManager(_settingsManager, directory.Path, NullTraceWriter.Instance))
                {
                    result = secretManager.GetFunctionSecrets("testfunction", true);
                }

                Assert.Contains("Key1", result.Keys);
                Assert.Contains("Key2", result.Keys);
                Assert.Contains("Key3", result.Keys);
                Assert.Equal("FunctionValue1", result["Key1"]);
                Assert.Equal("FunctionValue2", result["Key2"]);
                Assert.Equal("HostValue3", result["Key3"]);
            }
        }
 public void Can_write_to_temporary_file()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile();
         Assert.IsTrue(file.Exists);
         File.WriteAllText(file.FullName, "Test\r\nLine2");
         Assert.AreEqual(File.ReadAllText(file.FullName), "Test\r\nLine2");
     }
 }
 public void GivenEmptyDirectory_ThenCacheReadFails()
 {
     using (var path = new TempDirectory())
     {
         var directory = new FileSystemDirectory(path);
         var cache = new BundleCollectionCache(directory, b => deserializers[b]);
         var result = cache.Read();
         result.IsSuccess.ShouldBeFalse();
     }
 }
 public void Can_create_temporary_file_with_a_specific_filename()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile("test.tmp");
         Assert.IsTrue(file.Exists);
         Assert.AreEqual(file.Name, "test.tmp");
         Assert.AreEqual(Path.Combine(dir.DirectoryInfo.FullName, "test.tmp"), file.FullName);
     }
 }
 public void Site_NonNullSetEnablesRaisingEvents()
 {
     using (var testDirectory = new TempDirectory(GetTestFilePath()))
     using (var watcher = new TestFileSystemWatcher(testDirectory.Path, "*"))
     {
         TestSite site = new TestSite() { designMode = true };
         watcher.Site = site;
         Assert.True(watcher.EnableRaisingEvents);
     }
 }
Esempio n. 20
0
        public void GivenSubDirectoryDoesNotExist_WhenGetDirectoryWithCreateTrue_ThenDirectoryIsCreated()
        {
            using (var path = new TempDirectory())
            {
                var dir = new FileSystemDirectory(path);
                dir.GetDirectory("sub", true);

                Directory.Exists(Path.Combine(path, "sub")).ShouldBeTrue();
            }
        }
        public void GetFile_throws_exception_if_more_than_one_file_matches()
        {
            using(var dir = new TempDirectory())
            {
                dir.CreateTempFile("test1.txt");
                dir.CreateTempFile("test2.txt");

                dir.DirectoryInfo.GetFile("test*.txt");
            }
        }
Esempio n. 22
0
        public void GivenSubDirectoryExists_WhenCallDirectoryExistsWithApplicationAbsolutePath_ThenReturnTrue()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "sub"));

                var dir = new FileSystemDirectory(path);
                dir.DirectoryExists("~/sub").ShouldBeTrue();
            }
        }
 public void CreateFromImageFilesTest()
 {
     using (var tempDirectory = new TempDirectory(true))
     {
         tempDirectory.AddFile("help0.png", "");
         tempDirectory.AddFile("help1.png", "");
         var helpDocument = HelpDocument.CreateFromImageFiles(new [] { tempDirectory.FullPath("help0.png"), tempDirectory.FullPath("help1.png"), });
         CollectionAssert.AreEqual(new [] { "help0", "help1" }, helpDocument.Items.Select(item => item.Id));
         CollectionAssert.AreEqual(new [] { "help0.png", "help1.png" }, helpDocument.Items.Select(item => item.ImageFile));
     }
 }
 CassetteApplicationContainerFactory CreateCassetteApplicationContainerFactory(TempDirectory path)
 {
     return new CassetteApplicationContainerFactory(
         new DelegateCassetteConfigurationFactory(Enumerable.Empty<ICassetteConfiguration>),
         new CassetteConfigurationSection(),
         path,
         "/",
         false,
         Mock.Of<HttpContextBase>
     );
 }
Esempio n. 25
0
        public void FileSystemWatcher_EmptyAction_TriggersNothing()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var file = new TempFile(Path.Combine(testDirectory.Path, "file")))
            using (var watcher = new FileSystemWatcher(testDirectory.Path, Path.GetFileName(file.Path)))
            {
                Action action = () => { };

                ExpectEvent(watcher, 0, action, expectedPath: file.Path);
            }
        }
        public void Test0()
        {
            using (var tempDirectory = new TempDirectory(true))
            {
                EPuzzlePronuncer.Instance.DirectoryName = tempDirectory.Name;
                Assert.Null(EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));

                tempDirectory.AddFile("pronunce.wav", "");
                Assert.AreEqual(tempDirectory.GetFullPath("pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("pronunce"));
                Assert.AreEqual(tempDirectory.GetFullPath("Pronunce.wav"), EPuzzlePronuncer.Instance.FindSoundFile("Pronunce"));
            }
        }
Esempio n. 27
0
        public void FullPathsReturned()
        {
            using (var path = new TempDirectory())
            {
                Directory.CreateDirectory(Path.Combine(path, "test"));
                File.WriteAllText(PathUtilities.Combine(path, "test", "asset.js"), "");

                var dir = new FileSystemDirectory(path);
                var filePaths = dir.GetFiles("*.js", SearchOption.AllDirectories).ToArray();
                filePaths[0].FullPath.ShouldEqual("~/test/asset.js");
            }
        }
        public void WhenCreateContainer_ThenBundleIsLoadedFromManifest()
        {
            using (var path = new TempDirectory())
            {
                CompileTimeManifestWithBundleExists(path);

                var factory = CreateCassetteApplicationContainerFactory(path);
                var container = factory.CreateContainer();

                container.Application.FindBundleContainingPath<ScriptBundle>("~/test.js").ShouldNotBeNull();
            }
        }
        public SpritingIntegrationTest()
        {
            container = CreateContainer();
            cache = new TempDirectory();
            InitDirectories();

            bundle = CreateStylesheetBundle();

            // SpriteImages expects image URLs to be expanded into absolute Cassette file URLs.
            ExpandUrls(bundle);
            SpriteImages(bundle);
        }
Esempio n. 30
0
        public void FileSystemWatcher_FileInfoGetter_TriggersNothing()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var file = new TempFile(Path.Combine(testDirectory.Path, "file")))
            using (var watcher = new FileSystemWatcher(testDirectory.Path, Path.GetFileName(file.Path)))
            {
                FileAttributes res;
                Action action = () => res = new FileInfo(file.Path).Attributes;

                ExpectEvent(watcher, 0, action, expectedPath: file.Path);
            }
        }