public void GetFileTypeById_WhenIdIsNull_Throws()
        {
            var handles = CreateRecognizerHandles();
            var fileTypeManager = new FileTypeManager(handles);

            Assert.Throws<ArgumentNullException>(() => fileTypeManager.GetFileTypeById(null));
        }
        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 GetFileTypeById_WhenIdIsKnown_ReturnsFileType()
        {
            var handles = CreateRecognizerHandles(
                new RecognizerInfo { Traits = new FileTypeRecognizerTraits("Type", "A file type.") });
            var fileTypeManager = new FileTypeManager(handles);

            FileType fileType = fileTypeManager.GetFileTypeById("Type");
            Assert.AreEqual("Type", fileType.Id);
            Assert.AreEqual("A file type.", fileType.Description);
        }
        public void GetFileTypeById_WhenIdIsNotKnown_ReturnsNull()
        {
            var handles = CreateRecognizerHandles();
            var fileTypeManager = new FileTypeManager(handles);

            Assert.IsNull(fileTypeManager.GetFileTypeById("Type"));
        }
        public void GetFileTypeById_WhenIdIsTheUnknownFileTypeId_ReturnsUnknownFileType()
        {
            var handles = CreateRecognizerHandles();
            var fileTypeManager = new FileTypeManager(handles);

            FileType fileType = fileTypeManager.GetFileTypeById("Unknown");
            Assert.AreSame(fileTypeManager.UnknownFileType, fileType);
        }