[PlatformSpecific(PlatformID.Windows | PlatformID.OSX)] // testing case insensitivity public static void Exists_DoesCaseInsensitiveInvariantComparions() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var paths = new string[] { directory.Path, directory.Path.ToUpperInvariant(), directory.Path.ToLowerInvariant() }; foreach (string path in paths) { bool result = Directory.Exists(path); Assert.True(result, path); } } }
public static void Exists_ExistentValidPathAsPath_ReturnsTrue() { var components = IOInputs.GetValidPathComponentNames(); foreach (string component in components) { using (TemporaryDirectory directory = new TemporaryDirectory()) { string path = Path.Combine(directory.Path, component); Directory.CreateDirectory(path); bool result = Directory.Exists(path); Assert.True(result, path); } } }
/// <summary>Создаёт тело утилиты, внедрённое в ресурсы сборки</summary> /// <param name="ContainingAssembly">Сборка, содержащая тело утилиты</param> /// <param name="BodyNamespacePath">Путь к к ресурсу папки, содержащей утилиту</param> /// <param name="ExecutableFileName">Относительный путь к выполняемому файлу утилиты</param> public EmbeddedToolBody(Assembly ContainingAssembly, string BodyNamespacePath, string ExecutableFileName) { _executableFileName = ExecutableFileName; IEnumerable<string> resourceNames = ContainingAssembly .GetManifestResourceNames() .Where(resourceName => resourceName.StartsWith(BodyNamespacePath)); _bodyDirectory = GetTemporaryDirectory(); foreach (string resourceName in resourceNames) { string fileName = resourceName.Substring(BodyNamespacePath.Length).TrimStart('.'); Stream resourceStream = ContainingAssembly.GetManifestResourceStream(resourceName); using (FileStream fileStream = File.Create(Path.Combine(WorkingDirectoryPath, fileName))) { resourceStream.CopyTo(fileStream); } } }
public void Constuctor_ValueAsCatalogArgument_ShouldSetSearchPatternProperty() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var expectations = new ExpectationCollection<string, string>(); expectations.Add("*.*", "*.*"); expectations.Add("*.doc", "*.doc"); expectations.Add("*.exe", "*.exe"); expectations.Add("*.dll", "*.dll"); foreach (var e in expectations) { var catalog = CreateDirectoryCatalog(directory.DirectoryPath, e.Input); var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog); Assert.AreEqual(e.Output, proxy.SearchPattern); } } }
public static void CreateDirectory_ReadOnlyExistingDirectoryAsPath_DoesNotThrow() { // DevDivBugs #33833 using (TemporaryDirectory directory = new TemporaryDirectory()) { directory.IsReadOnly = true; DirectoryInfo result = Directory.CreateDirectory(directory.Path); Assert.Equal(directory.Path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } }
public static void CreateDirectory_NonSignificantTrailingWhiteSpace_TreatsAsNonSignificant() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var components = IOInputs.GetNonSignificantTrailingWhiteSpace(); foreach (string component in components) { string path = directory.Path + component; DirectoryInfo result = Directory.CreateDirectory(path); Assert.True(Directory.Exists(result.FullName)); Assert.Equal(directory.Path, result.FullName); } } }
public static void CreateDirectory_ExistingDirectoryWithTrailingSlashAsPath_DoesNotThrow() { using (TemporaryDirectory directory = new TemporaryDirectory()) { string path = IOServices.AddTrailingSlashIfNeeded(directory.Path); DirectoryInfo result = Directory.CreateDirectory(path); Assert.Equal(path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } }
public void LoadedFiles_ContainsMultipleDllsAndSomeNonDll_ShouldOnlyContainDlls() { using (var directory = new TemporaryDirectory()) { // Add one text file using (File.CreateText(Path.Combine(directory.DirectoryPath, "Test.txt"))) { } // Add two dll's string dll1 = Path.Combine(directory.DirectoryPath, "Test1.dll"); string dll2 = Path.Combine(directory.DirectoryPath, "Test2.dll"); File.Copy(Assembly.GetExecutingAssembly().Location, dll1); File.Copy(Assembly.GetExecutingAssembly().Location, dll2); var cat = new DirectoryCatalog(directory.DirectoryPath); CollectionAssert.AreEquivalent(new string[] { dll1.ToUpperInvariant(), dll2.ToUpperInvariant() }, cat.LoadedFiles); } }
public static void CreateDirectory_ValidPathWithoutTrailingSlashAsPath_CanBeCreated() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var components = IOInputs.GetValidPathComponentNames(); foreach (var component in components) { string path = directory.Path + Path.DirectorySeparatorChar + component; DirectoryInfo result = Directory.CreateDirectory(path); Assert.Equal(path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } } }
[PlatformSpecific(PlatformID.Windows)] // max directory length not fixed on Unix public static void CreateDirectory_DirectoryEqualToMaxDirectory_CanBeCreatedAllAtOnce() { // Creates directories up to the maximum directory length all at once using (TemporaryDirectory directory = new TemporaryDirectory()) { PathInfo path = IOServices.GetPath(directory.Path, IOInputs.MaxDirectory, maxComponent: 10); DirectoryInfo result = Directory.CreateDirectory(path.FullPath); Assert.Equal(path.FullPath, result.FullName); Assert.True(Directory.Exists(result.FullName)); } }
public static void Exists_ExistingDirectoryWithNonSignificantTrailingWhiteSpaceAsPath_ReturnsTrue() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var components = IOInputs.GetNonSignificantTrailingWhiteSpace(); foreach (string component in components) { string path = directory.Path + component; bool result = Directory.Exists(path); Assert.True(result, path); } } }
public static void Exists_ExistingDirectoryWithTrailingSlashAsPath_ReturnsTrue() { using (TemporaryDirectory directory = new TemporaryDirectory()) { string path = IOServices.AddTrailingSlashIfNeeded(directory.Path); bool result = Directory.Exists(path); Assert.True(result); } }
[PlatformSpecific(PlatformID.Windows)] // max directory length not fixed on Unix public static void Exists_DirectoryEqualToMaxDirectory_ReturnsTrue() { // Creates directories up to the maximum directory length all at once using (TemporaryDirectory directory = new TemporaryDirectory()) { PathInfo path = IOServices.GetPath(directory.Path, IOInputs.MaxDirectory, maxComponent: 10); Directory.CreateDirectory(path.FullPath); bool result = Directory.Exists(path.FullPath); Assert.True(result, path.FullPath); } }
private void ShareMinimal(ZipFile zip) { TemporaryDirectory tempDir = null; try { var docOriginal = Document; if (Document.Settings.HasBackgroundProteome) { // Remove any background proteome reference Document = Document.ChangeSettings(Document.Settings.ChangePeptideSettings( set => set.ChangeBackgroundProteome(BackgroundProteome.NONE))); } if (Document.Settings.HasRTCalcPersisted) { // Minimize any persistable retention time calculator tempDir = new TemporaryDirectory(); string tempDbPath = Document.Settings.PeptideSettings.Prediction.RetentionTime .Calculator.PersistMinimized(tempDir.DirPath, Document); if (tempDbPath != null) zip.AddFile(tempDbPath, string.Empty); } if (Document.Settings.HasOptimizationLibraryPersisted) { tempDir = new TemporaryDirectory(); string tempDbPath = Document.Settings.TransitionSettings.Prediction.OptimizedLibrary.PersistMinimized( tempDir.DirPath, Document); if (tempDbPath != null) zip.AddFile(tempDbPath, string.Empty); } if (Document.Settings.HasIonMobilityLibraryPersisted) { // Minimize any persistable drift time predictor tempDir = new TemporaryDirectory(); string tempDbPath = Document.Settings.PeptideSettings.Prediction.DriftTimePredictor .IonMobilityLibrary.PersistMinimized(tempDir.DirPath, Document); if (tempDbPath != null) zip.AddFile(tempDbPath, string.Empty); } if (Document.Settings.HasLibraries) { // Minimize all libraries in a temporary directory, and add them if (tempDir == null) tempDir = new TemporaryDirectory(); Document = BlibDb.MinimizeLibraries(Document, tempDir.DirPath, Path.GetFileNameWithoutExtension(DocumentPath), ProgressMonitor); if (ProgressMonitor != null && ProgressMonitor.IsCanceled) return; foreach (var librarySpec in Document.Settings.PeptideSettings.Libraries.LibrarySpecs) { var tempLibPath = Path.Combine(tempDir.DirPath, Path.GetFileName(librarySpec.FilePath) ?? string.Empty); zip.AddFile(tempLibPath, string.Empty); // If there is a .redundant.blib file that corresponds to a .blib file // in the temp temporary directory, add that as well IncludeRedundantBlib(librarySpec, zip, tempLibPath); } } ShareDataAndView(zip); if (ReferenceEquals(docOriginal, Document)) zip.AddFile(DocumentPath, string.Empty); else { // If minimizing changed the document, then serialize and archive the new document var stringWriter = new XmlStringWriter(); using (var writer = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented }) { XmlSerializer ser = new XmlSerializer(typeof(SrmDocument)); ser.Serialize(writer, Document); zip.AddEntry(Path.GetFileName(DocumentPath), stringWriter.ToString(), Encoding.UTF8); } } Save(zip); } finally { if (tempDir != null) { try { tempDir.Dispose(); } catch (IOException x) { var message = TextUtil.LineSeparate(string.Format(Resources.SrmDocumentSharing_ShareMinimal_Failure_removing_temporary_directory__0__, tempDir.DirPath), x.Message); throw new IOException(message); } } } }
public static void CreateDirectory_HiddenExistingDirectoryAsPath_DoesNotThrow() { using (TemporaryDirectory directory = new TemporaryDirectory()) { directory.IsHidden = true; DirectoryInfo result = Directory.CreateDirectory(directory.Path); Assert.Equal(directory.Path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } }
[PlatformSpecific(PlatformID.Windows)] // max directory length not fixed on Unix public static void CreateDirectory_DirectoryEqualToMaxDirectory_CanBeCreated() { // Recursively creates directories right up to the maximum directory length ("247 chars not including null") using (TemporaryDirectory directory = new TemporaryDirectory()) { PathInfo path = IOServices.GetPath(directory.Path, IOInputs.MaxDirectory, IOInputs.MaxComponent); // First create 'C:\AAA...AA', followed by 'C:\AAA...AAA\AAA...AAA', etc foreach (string subpath in path.SubPaths) { DirectoryInfo result = Directory.CreateDirectory(subpath); Assert.Equal(subpath, result.FullName); Assert.True(Directory.Exists(result.FullName)); } } }
public void LoadedFiles_EmptyDirectory_ShouldBeFine() { using (var directory = new TemporaryDirectory()) { var cat = CreateDirectoryCatalog(directory.DirectoryPath); var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat); Assert.AreEqual(0, proxy.LoadedFiles.Count); } }
public static void CreateDirectory_ValidPathWithTrailingSlash_CanBeCreated() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var components = IOInputs.GetValidPathComponentNames(); foreach (var component in components) { string path = IOServices.AddTrailingSlashIfNeeded(Path.Combine(directory.Path, component)); DirectoryInfo result = Directory.CreateDirectory(path); Assert.Equal(path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } } }
public void FullPath_ValidPath_ShouldBeFine() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var expectations = new ExpectationCollection<string, string>(); // Ensure the path is always normalized properly. string rootTempPath = Path.GetFullPath(FileIO.GetRootTemporaryDirectory()).ToUpperInvariant(); // Note: These relative paths work properly because the unit test temporary directories are always // created as a subfolder off the AppDomain.CurrentDomain.BaseDirectory. expectations.Add(".", Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".")).ToUpperInvariant()); expectations.Add(FileIO.RootTemporaryDirectoryName, rootTempPath); expectations.Add(FileIO.GetRootTemporaryDirectory(), rootTempPath); expectations.Add(directory.DirectoryPath, Path.GetFullPath(directory.DirectoryPath).ToUpperInvariant()); foreach (var e in expectations) { var cat = CreateDirectoryCatalog(e.Input, DirectoryCatalogTests.NonExistentSearchPattern); var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat); Assert.AreEqual(e.Output, proxy.FullPath); } } }
public void LoadedFiles_EmptyDirectory_ShouldBeFine() { using (var directory = new TemporaryDirectory()) { var cat = new DirectoryCatalog(directory.DirectoryPath); Assert.AreEqual(0, cat.LoadedFiles.Count); } }
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.Equal(0, symlink(targetDir.Path, linkPath)); Assert.True(Directory.Exists(linkPath)); Assert.Equal(1, Directory.GetDirectories(containingFolder.Path).Count()); } // The target file is gone and the symlink still exists; since it can't be resolved, // it's treated as a file rather than as a directory. Assert.Equal(0, Directory.GetDirectories(containingFolder.Path).Count()); Assert.Equal(1, Directory.GetFiles(containingFolder.Path).Count()); } }
public void Refresh_AssemblyAdded_ShouldFireOnChanged() { using (var directory = new TemporaryDirectory()) { bool changedFired = false; bool changingFired = false; var cat = new DirectoryCatalog(directory.DirectoryPath); Assert.AreEqual(0, cat.Parts.Count(), "Catalog should initially be empty"); cat.Changing += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) => { Assert.AreEqual(0, cat.Parts.Count(), "Catalog changes should NOT have been completeed yet"); changingFired = true; }); cat.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) => { Assert.AreNotEqual(0, cat.Parts.Count(), "Catalog changes should have been completeed"); changedFired = true; }); File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(directory.DirectoryPath, "Test.dll")); cat.Refresh(); Assert.IsTrue(changingFired); Assert.IsTrue(changedFired); } }
public void EnumerateWithSymLinkToFile() { using (var containingFolder = new TemporaryDirectory()) { string linkPath; // Test a symlink to a file that does and then doesn't exist using (var targetFile = new TemporaryFile()) { linkPath = Path.Combine(containingFolder.Path, Path.GetRandomFileName()); Assert.Equal(0, symlink(targetFile.Path, linkPath)); Assert.True(File.Exists(linkPath)); Assert.Equal(1, GetFiles(containingFolder.Path).Count()); } // The symlink still exists even though the target file is gone. Assert.Equal(1, GetFiles(containingFolder.Path).Count()); // The symlink is gone File.Delete(linkPath); Assert.Equal(0, GetFiles(containingFolder.Path).Count()); } }