当前位置: 首页>>代码示例>>C#>>正文


C# TemporaryDirectory类代码示例

本文整理汇总了C#中TemporaryDirectory的典型用法代码示例。如果您正苦于以下问题:C# TemporaryDirectory类的具体用法?C# TemporaryDirectory怎么用?C# TemporaryDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TemporaryDirectory类属于命名空间,在下文中一共展示了TemporaryDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldHandleSha1

        public void ShouldHandleSha1()
        {
            using (var package = new TemporaryDirectory("0install-unit-tests"))
            {
                string innerPath = Path.Combine(package, "inner");
                Directory.CreateDirectory(innerPath);

                string manifestPath = Path.Combine(package, Manifest.ManifestFile);
                string innerExePath = Path.Combine(innerPath, "inner.exe");
                File.WriteAllText(innerExePath, @"xxxxxxx");
                if (WindowsUtils.IsWindows)
                {
                    string flagPath = Path.Combine(package, FlagUtils.XbitFile);
                    File.WriteAllText(flagPath, @"/inner/inner.exe");
                }
                else FileUtils.SetExecutable(innerExePath, true);
                CreateDotFile(package, ManifestFormat.Sha1, new MockTaskHandler());
                using (var manifestFile = File.OpenText(manifestPath))
                {
                    string currentLine = manifestFile.ReadLine();
                    Assert.True(Regex.IsMatch(currentLine, @"^D \w+ /inner$"), "Manifest didn't match expected format:\n" + currentLine);
                    currentLine = manifestFile.ReadLine();
                    Assert.True(Regex.IsMatch(currentLine, @"^X \w+ \w+ \d+ inner.exe$"), "Manifest didn't match expected format:\n" + currentLine);
                }
            }
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:26,代码来源:ManifestTest.cs

示例2: TestGetFilesAbsolute

        public void TestGetFilesAbsolute()
        {
            using (var tempDir = new TemporaryDirectory("unit-tests"))
            {
                File.WriteAllText(Path.Combine(tempDir, "a.txt"), @"a");
                File.WriteAllText(Path.Combine(tempDir, "b.txt"), @"b");
                File.WriteAllText(Path.Combine(tempDir, "c.inf"), @"c");
                File.WriteAllText(Path.Combine(tempDir, "d.nfo"), @"d");

                string subdirPath = Path.Combine(tempDir, "dir");
                Directory.CreateDirectory(subdirPath);
                File.WriteAllText(Path.Combine(subdirPath, "1.txt"), @"1");
                File.WriteAllText(Path.Combine(subdirPath, "2.inf"), @"a");

                var result = ArgumentUtils.GetFiles(new[]
                {
                    Path.Combine(tempDir, "*.txt"), // Wildcard
                    Path.Combine(tempDir, "d.nfo"), // Specifc file
                    subdirPath // Directory with implict default wildcard
                }, "*.txt");
                result[0].FullName.Should().Be(Path.Combine(tempDir, "a.txt"));
                result[1].FullName.Should().Be(Path.Combine(tempDir, "b.txt"));
                result[2].FullName.Should().Be(Path.Combine(tempDir, "d.nfo"));
                result[3].FullName.Should().Be(Path.Combine(subdirPath, "1.txt"));
            }
        }
开发者ID:nano-byte,项目名称:common,代码行数:26,代码来源:ArgumentUtilsTest.cs

示例3: LoadResourceDirectory

 // We assume that every file has structure: name.ext
 // this is obviously not true in general case, but good enough for tests
 public static TemporaryDirectory LoadResourceDirectory(string path)
 {
     string pathStart = Path.Combine(@"VisualRust\Test", path).Replace('\\', '.');
     TemporaryDirectory dir = new TemporaryDirectory();
     int lastSlash = pathStart.LastIndexOf('.');
     TemporaryDirectory actualRoot = dir.SubDir(pathStart.Substring(lastSlash + 1, pathStart.Length - lastSlash - 1));
     foreach(string resName in resourceNames.Where(p => p.StartsWith(pathStart)))
     {
         string relPath = resName.Substring(pathStart.Length, resName.Length - pathStart.Length);
         int extDot = relPath.LastIndexOf('.');
         int fileDot = relPath.LastIndexOf('.', extDot - 1);
         string subDir = relPath.Substring(1, fileDot);
         string currDir = actualRoot.DirPath;
         if(subDir.Length > 0)
         {
             currDir = Path.Combine(actualRoot.DirPath, subDir);
             Directory.CreateDirectory(currDir);
         }
         using(FileStream fileStream = File.Create(Path.Combine(currDir, relPath.Substring(fileDot + 1, relPath.Length - fileDot - 1))))
         {
             using(var resStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resName))
             {
                 resStream.CopyTo(fileStream);
             }
         }
     }
     return actualRoot;
 }
开发者ID:whuthj,项目名称:VisualRust,代码行数:30,代码来源:Utils.cs

示例4: GetFile

        public string GetFile( string fileRepositoryPath, long version, TemporaryDirectory tempDir )
        {
            try
            {
                // Find the file by path in our current tree cache.
                VaultClientFile foundFile;
                if( !CanGetFile( fileRepositoryPath, version, out foundFile ) )
                {
                    return String.Empty;
                }

                // This is important: do not modify the VaultClientFile reference returned by FindFileRecursive,
                // as you will modify your tree cache (which will be saved to disk).  Make a copy of the
                // object and modify that one.
                VaultClientFile copy = new VaultClientFile( foundFile );

                // Modify the copy to represent the requested file version.
                // Files added in this feature will have an initial version of 0, which doesn't actually exist in the
                // Vault repository.  When we are asked to retrieve such a file, we bump the version number up to 1.
                copy.Version = Math.Max(1, version);

                // Get the file.
                Client.GetByDisplayVersionToNonWorkingFolder( copy, MakeWritableType.MakeAllFilesWritable, SetFileTimeType.Current, copy.Parent.FullPath, tempDir.DirectoryPath, null );

                return Path.Combine( tempDir.DirectoryPath, copy.Name );
            }
            catch( Exception e )
            {
                // Intentionally squashed.
                Trace.WriteLine( e );
                return String.Empty;
            }
        }
开发者ID:nrrrdcore,项目名称:portertwo,代码行数:33,代码来源:FileRetriever.cs

示例5: TestExtractInvalidData

        public void TestExtractInvalidData()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("7z extraction relies on a Win32 DLL and therefore will not work on non-Windows platforms");

            using (var sandbox = new TemporaryDirectory("0install-unit-tests"))
                Assert.Throws<IOException>(() => Extractor.FromStream(new MemoryStream(_garbageData), sandbox, Archive.MimeType7Z).Run());
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:7,代码来源:SevenZipExtractorTest.cs

示例6: EnumerateWithSymLinkToDirectory

        public void EnumerateWithSymLinkToDirectory()
        {
            using (var containingFolder = new TemporaryDirectory())
            {
                // Test a symlink to a directory that does and then doesn't exist
                using (var targetDir = new TemporaryDirectory())
                {
                    // Create a symlink to a folder that exists
                    string linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName());
                    Assert.True(MountHelper.CreateSymbolicLink(linkPath, targetDir.Path, isDirectory: true));

                    Assert.True(Directory.Exists(linkPath));
                    Assert.Equal(1, GetEntries(containingFolder.Path).Count());
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Assert.Equal(1, GetEntries(containingFolder.Path).Count());
                    Assert.Equal(0, Directory.GetFiles(containingFolder.Path).Count());
                }
                else
                {
                    // The target file is gone and the symlink still exists; since it can't be resolved,
                    // on Unix it's treated as a file rather than as a directory.
                    Assert.Equal(0, GetEntries(containingFolder.Path).Count());
                    Assert.Equal(1, Directory.GetFiles(containingFolder.Path).Count());
                }
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:29,代码来源:GetDirectories.cs

示例7: ServerPackageRepositoryRemovePackage

        public void ServerPackageRepositoryRemovePackage()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                // Arrange
                var serverRepository = CreateServerPackageRepository(temporaryDirectory.Path, repository =>
                {
                    repository.AddPackage(CreatePackage("test", "1.11"));
                    repository.AddPackage(CreatePackage("test", "1.9"));
                    repository.AddPackage(CreatePackage("test", "2.0-alpha"));
                });

                // Act
                serverRepository.RemovePackage(CreateMockPackage("test", "1.11"));
                serverRepository.RemovePackage(CreateMockPackage("test", "2.0-alpha"));
                var packages = serverRepository.GetPackages();

                // Assert
                Assert.Equal(1, packages.Count());
                Assert.Equal(1, packages.Count(p => p.IsLatestVersion));
                Assert.Equal("1.9", packages.First(p => p.IsLatestVersion).Version.ToString());

                Assert.Equal(1, packages.Count(p => p.IsAbsoluteLatestVersion));
                Assert.Equal("1.9", packages.First(p => p.IsAbsoluteLatestVersion).Version.ToString());
            }
        }
开发者ID:harleydk,项目名称:NuGet.Server,代码行数:26,代码来源:ServerPackageRepositoryTest.cs

示例8: Build

 public void Build( DataSet changeHistory, string fileName )
 {
     using( TemporaryDirectory revisionsDirectory = new TemporaryDirectory( ) )
     {
         RetrieveFiles( changeHistory, revisionsDirectory );
         MakeArchive( fileName, revisionsDirectory );
     }
 }
开发者ID:nrrrdcore,项目名称:portertwo,代码行数:8,代码来源:ArchiveBuilder.cs

示例9: TestExtractInvalidData

        public void TestExtractInvalidData()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("MSI extraction relies on a Win32 API and therefore will not work on non-Windows platforms");

            using (var sandbox = new TemporaryDirectory("0install-unit-tests"))
            using (var tempFile = Deploy(new MemoryStream(_garbageData)))
                Assert.Throws<IOException>(() => Extractor.FromFile(tempFile, sandbox, Archive.MimeTypeMsi));
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:8,代码来源:MsiExtractorTest.cs

示例10: SetUp

        public override void SetUp()
        {
            base.SetUp();

            _destination = new TemporaryDirectory("0install-unit-test");
            var selections = SelectionsTest.CreateTestSelections();
            _target = new Exporter(selections, new Architecture(), _destination);
        }
开发者ID:0install,项目名称:0install-win,代码行数:8,代码来源:ExporterTest.cs

示例11: SetUp

        public override void SetUp()
        {
            base.SetUp();

            _destinationDirectory = new TemporaryDirectory("0install-unit-tests");
            _destinationManifestPath = Path.Combine(_destinationDirectory, Manifest.ManifestFile);
            _destinationFile1Path = Path.Combine(_destinationDirectory, "file1");
            _destinationSubdirPath = Path.Combine(_destinationDirectory, "subdir");
            _destinationFile2Path = Path.Combine(_destinationSubdirPath, "file2");
        }
开发者ID:0install,项目名称:0install-win,代码行数:10,代码来源:DeployDirectoryTest.cs

示例12: ShouldAllowToAddFolder

        public void ShouldAllowToAddFolder()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                var digest = new ManifestDigest(ManifestTest.CreateDotFile(packageDir, ManifestFormat.Sha256, _handler));
                _store.AddDirectory(packageDir, digest, _handler);

                Assert.IsTrue(_store.Contains(digest), "After adding, Store must contain the added package");
                CollectionAssert.AreEqual(new[] {digest}, _store.ListAll(), "After adding, Store must show the added package in the complete list");
            }
        }
开发者ID:modulexcite,项目名称:0install-win,代码行数:11,代码来源:DirectoryStoreTest.cs

示例13: SetUp

        public void SetUp()
        {
            // Create a temporary cache
            _tempDir = new TemporaryDirectory("0install-unit-tests");
            _cache = new DiskIconCache(_tempDir);

            // Add some dummy icons to the cache
            File.WriteAllText(Path.Combine(_tempDir, new FeedUri("http://0install.de/feeds/images/test1.png").Escape()), "");
            File.WriteAllText(Path.Combine(_tempDir, new FeedUri("http://0install.de/feeds/images/test2.png").Escape()), "");
            File.WriteAllText(Path.Combine(_tempDir, "http_invalid"), "");
        }
开发者ID:0install,项目名称:0install-win,代码行数:11,代码来源:DiskIconCacheTest.cs

示例14: DoDiff

        private void DoDiff( string fileRepositoryPath, long firstVersion, long secondVersion )
        {
            // We need two temp folders because we'll retrieve two files, which will probably have the
            // same name, and we don't want to overwrite the other.
            using( TemporaryDirectory tempDir1 = new TemporaryDirectory(),
                tempDir2 = new TemporaryDirectory() )
            {
                try
                {
                    string firstVersionFilePath = fileRetriever.GetFile( fileRepositoryPath, firstVersion, tempDir1 );
                    string secondVersionFilePath = fileRetriever.GetFile( fileRepositoryPath, secondVersion, tempDir2 );

                    if (firstVersionFilePath == String.Empty || secondVersionFilePath == String.Empty)
                    {
                        return;
                    }

                    #region Diff the files

                    string diffApplication = "sgdm.exe";
                    string diffArgsFormatString = Client.UserOptions.GetString( VaultOptions.CustomDiff_Args );

                    // Process the arg format string to insert the correct paths and captions.
                    string processedArgString = Client.ReplaceDiffArgs(
                        diffArgsFormatString,
                        firstVersionFilePath,
                        Path.GetFileName( firstVersionFilePath ) + " " + firstVersion.ToString( ),
                        secondVersionFilePath,
                        Path.GetFileName( secondVersionFilePath ) + " " + secondVersion.ToString( ) );

                    Console.WriteLine( "Launching diff application." );

                    Process diffProc = ExternalToolsHelper.GetDiffProgram(
                        firstVersionFilePath,
                        secondVersionFilePath,
                        diffApplication,
                        processedArgString,
                        externalToolsSettings);

                    diffProc.Start();

                    // Do we want to wait?  Probably not
                    diffProc.WaitForExit();

                    #endregion
                }
                catch( Exception e )
                {
                    // Intentionally squashed.
                    System.Diagnostics.Trace.WriteLine( e );
                }
            }
        }
开发者ID:nrrrdcore,项目名称:portertwo,代码行数:53,代码来源:DiffTwoFileVersions.cs

示例15: TestCreateSymlink

        public void TestCreateSymlink()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("The 'system' file attribute can only be set on the Windows platform.");

            using (var tempDir = new TemporaryDirectory("unit-tests"))
            {
                string symlinkFile = Path.Combine(tempDir, "symlink");
                CygwinUtils.CreateSymlink(symlinkFile, "target");

                File.Exists(symlinkFile).Should().BeTrue();
                CollectionAssert.AreEqual(expected: _symlinkBytes, actual: File.ReadAllBytes(symlinkFile));
            }
        }
开发者ID:nano-byte,项目名称:common,代码行数:13,代码来源:CygwinUtilsTest.cs


注:本文中的TemporaryDirectory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。