public void IdentifyFileType_FileInspector_WhenContentsNotAvailable_ReturnsTypeOnlyIfNoContentCriteriaAndRecognizerMatches( bool contentCriteria, bool recognizerResult, bool expectedMatch) { var inspector = new FakeFileInspector(); var recognizer = MockRepository.GenerateStub<IFileTypeRecognizer>(); recognizer.Stub(x => x.IsRecognizedFile(inspector)).Return(recognizerResult); var handles = CreateRecognizerHandles( new RecognizerInfo { Traits = new FileTypeRecognizerTraits("TypeA", "A") { ContentsRegex = contentCriteria ? ".*" : null }, Recognizer = recognizer }); var fileTypeManager = new FileTypeManager(handles); FileType fileType = fileTypeManager.IdentifyFileType(inspector); Assert.AreEqual(expectedMatch ? "TypeA" : "Unknown", fileType.Id); }
public void IdentifyFileType_FileInspectorWithCandidates_WhenMatchCriteriaAndCandidatesAreVaried_ReturnsTypeIfMatchedOrUnknownOtherwise( bool includeSupertypeAsCandidate, bool includeSubtypeAsCandidate, bool superRecognizerResult, bool subRecognizerResult, string expectedMatchType) { var inspector = new FakeFileInspector() { FileInfo = new FileInfo(@"C:\file.txt"), Contents = "contents" }; var superRecognizer = MockRepository.GenerateStub<IFileTypeRecognizer>(); superRecognizer.Stub(x => x.IsRecognizedFile(inspector)).Return(superRecognizerResult); var subRecognizer = MockRepository.GenerateStub<IFileTypeRecognizer>(); subRecognizer.Stub(x => x.IsRecognizedFile(inspector)).Return(subRecognizerResult); var handles = CreateRecognizerHandles( new RecognizerInfo { Traits = new FileTypeRecognizerTraits("SuperType", "Super"), Recognizer = superRecognizer }, new RecognizerInfo { Traits = new FileTypeRecognizerTraits("SubType", "Sub") { SuperTypeId = "SuperType" }, Recognizer = subRecognizer }); var fileTypeManager = new FileTypeManager(handles); var candidates = new List<FileType>(); if (includeSupertypeAsCandidate) candidates.Add(fileTypeManager.GetFileTypeById("SuperType")); if (includeSubtypeAsCandidate) candidates.Add(fileTypeManager.GetFileTypeById("SubType")); FileType fileType = fileTypeManager.IdentifyFileType(inspector, candidates); Assert.AreEqual(expectedMatchType, fileType.Id); }
public void IdentifyFileType_FileInspector_WhenMatchCriteriaAreVaried_ReturnsTypeIfMatchedOrUnknownOtherwise(string fileNameRegex, string contentsRegex, bool recognizerResult, bool expectedMatch) { var inspector = new FakeFileInspector() { FileInfo = new FileInfo(@"C:\file.txt"), Contents = "contents" }; var recognizer = MockRepository.GenerateStub<IFileTypeRecognizer>(); recognizer.Stub(x => x.IsRecognizedFile(inspector)).Return(recognizerResult); var handles = CreateRecognizerHandles( new RecognizerInfo { Traits = new FileTypeRecognizerTraits("TypeA", "A") { FileNameRegex = fileNameRegex, ContentsRegex = contentsRegex }, Recognizer = recognizer }); var fileTypeManager = new FileTypeManager(handles); FileType fileType = fileTypeManager.IdentifyFileType(inspector); Assert.AreEqual(expectedMatch ? "TypeA" : "Unknown", fileType.Id); }
public void IdentifyFileType_FileInspectorWithCandidates_WhenCandidatesIsNull_Throws() { var handles = CreateRecognizerHandles(); var fileTypeManager = new FileTypeManager(handles); Assert.Throws<ArgumentNullException>(() => fileTypeManager.IdentifyFileType(MockRepository.GenerateStub<IFileInspector>(), null)); }
public void IdentifyFileType_FileInfoWithCandidates_WhenCandidatesIsNull_Throws() { var handles = CreateRecognizerHandles(); var fileTypeManager = new FileTypeManager(handles); Assert.Throws<ArgumentNullException>(() => fileTypeManager.IdentifyFileType(new FileInfo(@"C:\"), null)); }
public void IdentifyFileType_FileInspectorWithCandidates_WhenFileInspectorIsNull_Throws() { var handles = CreateRecognizerHandles(); var fileTypeManager = new FileTypeManager(handles); Assert.Throws<ArgumentNullException>(() => fileTypeManager.IdentifyFileType((IFileInspector)null, new FileType[0])); }
public void IdentifyFileType_FileInfo_WhenFileInfoIsNull_Throws() { var handles = CreateRecognizerHandles(); var fileTypeManager = new FileTypeManager(handles); Assert.Throws<ArgumentNullException>(() => fileTypeManager.IdentifyFileType((FileInfo)null)); }