public async Task FolderPropertyTest() { await STATask.Run(() => { var path = TestConfig.TestDirectory.FullName; var actual = ShellFactory.FromFolderPath(path); actual.Parent.IsNotNull(); actual.Parent.ParsingName.Is(TestConfig.TestDirectory.Parent?.FullName); }); }
public async Task FromFilePathErrorTest() { await STATask.Run(() => { const string filename = @"xxxx.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, filename); var ex = Assert.Throws <FileNotFoundException>(() => ShellFactory.FromFilePath(path)); Assert.Equal(path, ex.FileName); }); }
public async Task GetHashCodeTest() { await STATask.Run(() => { const string fileName = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, fileName); var actual = ShellFactory.FromFilePath(path); Assert.NotEqual(0, actual.GetHashCode()); }); }
public async Task SizePropertyTest() { await STATask.Run(() => { const string fileName = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, fileName); var actual = ShellFactory.FromFilePath(path); Console.WriteLine(actual.Size); Assert.True(0 < actual.Size); }); }
public async Task FolderPropertyTest() { await STATask.Run(() => { const string fileName = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, fileName); var actual = ShellFactory.FromFilePath(path); Assert.NotNull(actual.Folder); Assert.Equal(TestConfig.TestDirectory.FullName, actual.Folder.ParsingName); }); }
public async Task ToStringTest() { await STATask.Run(() => { const string fileName = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, fileName); var actual = ShellFactory.FromFilePath(path); Console.WriteLine(actual.ToString()); Assert.NotEqual(-1, actual.ToString().IndexOf(path, StringComparison.InvariantCultureIgnoreCase)); }); }
public async Task EqualsTest1() { await STATask.Run(() => { var folder1 = ShellFactory.FromFolderPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); var folder2 = ShellFactory.FromFolderPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); folder1.IsNotSameReferenceAs(folder2); folder1.Equals(folder2).IsTrue(); (folder1 == folder2).IsTrue(); (folder1.Path == folder2.Path).IsTrue(); (folder1.GetHashCode() == folder2.GetHashCode()).IsTrue(); }); }
public async Task FromFolderPathTest() { await STATask.Run(() => { var path = TestConfig.TestDirectory.FullName; var actual = ShellFactory.FromFolderPath(path); actual.IsNotNull(); actual.Path.Is(path); actual.ParsingName.Is(path); actual.Name.Is(TestConfig.TestDirectoryName); actual.Parent.ParsingName.Is(TestConfig.TestDirectory.Parent?.FullName); // Flags actual.IsFileSystem.IsTrue(); }); }
/// <summary> /// Create a new instance of the <see cref="ShellLibrary" /> class /// to the specified library name and folder path. /// </summary> /// <param name="libraryName">Name of the library to be created.</param> /// <param name="sourcePath">Folder path.</param> /// <param name="isReadOnly">A value that indicates whether the library is readonly.</param> /// <returns>Created <see cref="ShellLibrary" />.</returns> public static ShellLibrary Load(string libraryName, string sourcePath, bool isReadOnly = true) { Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(libraryName)); Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(sourcePath)); Contract.Ensures(Contract.Result <ShellLibrary>() != null); var shellItemPath = Path.Combine(sourcePath, libraryName + FileExtension); var shellLibraryInterface = CreateShellLibraryNativeInterface(); var item = ShellFactory.FromFilePath(shellItemPath); var shellItem = item.ShellItem.ShellItemInterface; var flags = isReadOnly ? STGM.STGM_READ : STGM.STGM_READWRITE; shellLibraryInterface.LoadLibraryFromItem(shellItem, flags); return(new ShellLibrary(new ShellItem(shellItem), shellLibraryInterface, libraryName)); }
public async Task GetDisplayNameTest() { await STATask.Run(() => { const string fileName = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, fileName); var actual = ShellFactory.FromFilePath(path); Assert.NotNull(actual); Assert.Equal(fileName, actual.GetDisplayName(DisplayNameTypes.Default)); Assert.Equal(fileName, actual.GetDisplayName(DisplayNameTypes.RelativeToParent)); Assert.Equal(fileName, actual.GetDisplayName(DisplayNameTypes.RelativeToParentAddressBar)); Assert.Equal(path, actual.GetDisplayName(DisplayNameTypes.RelativeToDesktop)); Assert.Equal(fileName, actual.GetDisplayName(DisplayNameTypes.RelativeToParentEditing)); Assert.Equal(path, actual.GetDisplayName(DisplayNameTypes.RelativeToDesktopEditing)); Assert.Equal(path, actual.GetDisplayName(DisplayNameTypes.FileSystemPath)); }); }
public async Task GetItemsTest() { await STATask.Run(() => { var path = TestConfig.TestDirectory.FullName; var folder = ShellFactory.FromFolderPath(path); var actual = folder.EnumerateObjects().ToList(); var folder1 = actual.Find(item => ShellTestConfig.CompareFileName(item.Name, "Pictures")); folder1.IsNotNull(); var file1 = actual.Find(item => ShellTestConfig.CompareFileName(item.Name, "Test.txt")); file1.IsNotNull(); file1.IsInstanceOf <ShellFile>(); var file2 = actual.Find(Item => ShellTestConfig.CompareFileName(Item.Name, "Test2.txt")); file2.IsNotNull(); file2.IsInstanceOf <ShellFile>(); }); }
public async Task FromFilePathTest() { await STATask.Run(() => { const string filename = @"Test.txt"; var path = Path.Combine(TestConfig.TestDirectory.FullName, filename); var actual = ShellFactory.FromFilePath(path); // Path Assert.NotNull(actual); Assert.Equal(path, actual.Path); Assert.Equal(path, actual.ParsingName); Assert.Equal(filename, actual.Name); Assert.Equal(".txt", actual.Extension); Assert.Equal(TestConfig.TestDirectory.FullName, actual.Folder.ParsingName); // Flags Assert.True(actual.IsFileSystem); }); }
public async Task FromParsingNameTest1() { await STATask.Run(() => { const string parsingName = @"::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Documents.library-ms"; var actual = ShellItem.FromParsingName(parsingName); Assert.NotNull(actual); Assert.Equal(parsingName, actual.GetParsingName()); Assert.Equal(".library-ms", actual.GetItemType()); Console.WriteLine("ParsingName = {0}", actual.GetParsingName()); Console.WriteLine("ItemType = {0}", actual.GetItemType()); var folder = ShellFactory.FromShellItem(actual); Console.WriteLine("folder.ParsingName = {0}", folder.ParsingName); Console.WriteLine("folder.Type = {0}", folder.GetType()); }); }