public void GetDocumentType_ReturnsExpectedResults(string name, DocumentType expected) { var mockDelegate = new Mock <FileTypeInfoProvider.TryGetMimeDelegate>(); var provider = new FileTypeInfoProvider(mockDelegate.Object); var result = provider.GetDocumentType(name); Assert.Equal(expected, result); }
public void GetDocumentType_Throws_OnNullOrEmpty() { var mockDelegate = new Mock <FileTypeInfoProvider.TryGetMimeDelegate>(); var provider = new FileTypeInfoProvider(mockDelegate.Object); Assert.Throws <ArgumentNullException>(() => provider.GetDocumentType(null)); Assert.Throws <ArgumentException>(() => provider.GetDocumentType("")); Assert.Throws <ArgumentException>(() => provider.GetDocumentType(" ")); }
public void GetMimeType_InvokesDelegate_ReturnsApplicationOctet_WhenFalse() { var mockDelegate = new Mock <FileTypeInfoProvider.TryGetMimeDelegate>(); mockDelegate.Setup(c => c.Invoke("dummy.txt", out It.Ref <string> .IsAny)) .Returns(false) .Verifiable(); var provider = new FileTypeInfoProvider(mockDelegate.Object); var resultMime = provider.GetMimeType("dummy.txt"); const string expected = System.Net.Mime.MediaTypeNames.Application.Octet; Assert.Equal(expected, resultMime); mockDelegate.Verify(c => c("dummy.txt", out It.Ref <string> .IsAny), Times.Once); }
public IEnumerable <ICommandModel> GetCommands(FileSystemInfoExModel appliedModel) { if (!appliedModel.IsDirectory) { string ext = PathEx.GetExtension(appliedModel.Name); foreach (OpenWithInfo info in FileTypeInfoProvider.GetFileTypeInfo(ext).OpenWithList) { if (info.OpenCommand != null) { string executePath = OpenWithInfo.GetExecutablePath(info.OpenCommand); string exeName = Path.GetFileNameWithoutExtension(executePath); if (info.OpenCommand != null && File.Exists(executePath)) { IEntryModel exeModel = AsyncUtils.RunSync(() => _profile.ParseAsync(executePath)); if (exeModel != null) { yield return new CommandModel(new OpenWithScriptCommand(info)) { Header = String.Format("{0} ({1})", exeName, info.KeyName), ToolTip = info.Description, HeaderIconExtractor = ModelIconExtractor <ICommandModel> .FromTaskFunc(t => _profile.GetIconExtractSequence(exeModel) .Last().GetIconBytesForModelAsync(exeModel, CancellationToken.None)), IsEnabled = true } } ; } } } yield return(new CommandModel(new OpenWithScriptCommand(OpenWithInfo.OpenAs)) { Header = "Open with...", IsEnabled = true }); } } }
public override IEnumerable <CommandModel> GetSubActions() { string ext = PathEx.GetExtension(_appliedEntryModel.Name); foreach (OpenWithInfo info in FileTypeInfoProvider.GetFileTypeInfo(ext).OpenWithList) { if (info.OpenCommand != null && File.Exists(OpenWithInfo.GetExecutablePath(info.OpenCommand))) { yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, info)); } } QueryOpenWithInfoEventArgs <FI, DI, FSI> openInfoArgs = new QueryOpenWithInfoEventArgs <FI, DI, FSI>(_appliedEntryModel); OnQueryOpenWithInfo(this, openInfoArgs); foreach (OpenWithInfo info in openInfoArgs.ReturnList) { yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, info)); } yield return(new OpenWithItemCommandModel <FI, DI, FSI>(_profile, _appliedEntryModel, OpenWithInfo.OpenAs)); }
public void GetMimeType_InvokesDelegate_ReturnsResult_WhenTrue() { const string expected = "result"; var mockDelegate = new Mock <FileTypeInfoProvider.TryGetMimeDelegate>(); mockDelegate.Setup(c => c.Invoke("dummy.txt", out It.Ref <string> .IsAny)) .Callback(new OutWrapperDelegate((string name, out string type) => { type = expected; })) .Returns(true) .Verifiable(); var provider = new FileTypeInfoProvider(mockDelegate.Object); var result = provider.GetMimeType("dummy.txt"); Assert.Equal(expected, result); mockDelegate.Verify(c => c("dummy.txt", out It.Ref <string> .IsAny), Times.Once); }
protected ExModel(FileSystemInfoEx entry) { Name = entry.Name; Label = entry.Label; FullName = entry.FullName; //0.2 LastAccessTime = entry.LastAccessTime; LastWriteTime = entry.LastWriteTime; CreationTime = entry.CreationTime; EntryType = entry.IsFolder ? entry.FullName.EndsWith(":\\") ? "Drive" : "Directory" : FileTypeInfoProvider.GetFileTypeInfo(PathEx.GetExtension(Name)).FileType; //if (FullName.StartsWith("\\\\") || //Network directory // (FullName.IndexOf('\\') == -1 && !FullName.StartsWith("::")) //Directory without path and not guid. // || entry.IsVirtual) //Virtual directory _embeddedEntry = entry; IsEditable = (entry.Attributes | System.IO.FileAttributes.ReadOnly) != 0; }