public void GetMimeType_WhenFileHasContentTypeAndMimeTypeProviderHasnt()
        {
            var expectedContentType = "application/test";
            var mimeTypeProvider = new MimeTypeProvider(new Dictionary<string, string>());
            var mimeType = mimeTypeProvider.GetMimeType(new MockFile(string.Empty, expectedContentType, ".test"));

            Assert.AreEqual(expectedContentType, mimeType);
        }
        public void GetMimeType_WhenBothFileAndMimeTypeProviderHaveGotContentType()
        {
            var expectedContentType = "application/test";
            var mimeTypeProvider = new MimeTypeProvider(new Dictionary<string, string> { { ".test", expectedContentType } });
            var mimeType = mimeTypeProvider.GetMimeType(new MockFile(string.Empty, "application/testing", ".test"));

            Assert.AreEqual(expectedContentType, mimeType);
        }
        public void GetMimeType_WhenFileDoesNotHaveContentTypeAndExtensionDoesNotHaveSameCasing()
        {
            var expectedContentType = "application/test";
            var mimeTypeProvider = new MimeTypeProvider(new Dictionary<string, string> { { ".test", expectedContentType } });
            var mimeType = mimeTypeProvider.GetMimeType(new MockFile(string.Empty, null, ".tEsT"));

            Assert.AreEqual(expectedContentType, mimeType);
        }
Esempio n. 4
0
        public StaticFileRouteHandler(string basePath, IReadOnlyDictionary <string, string> extensionsToMimeTypes, IFileSystem fileSystem)
        {
            _basePath         = basePath.GetAbsoluteBasePathUri();
            _fileSystem       = fileSystem ?? new PhysicalFileSystem();
            _mimeTypeProvider = new MimeTypeProvider(extensionsToMimeTypes ?? MimeTypeProvider.DefaultMimeTypesByExtension);

            if (!_fileSystem.Exists(_basePath))
            {
                throw new Exception($"Path at {_basePath} could not be found.");
            }
        }
        public StaticFileRouteHandler(string basePath, IReadOnlyDictionary<string, string> extensionsToMimeTypes, IFileSystem fileSystem)
        {
            _basePath = basePath.GetAbsoluteBasePathUri();
            _fileSystem = fileSystem ?? new PhysicalFileSystem();
            _mimeTypeProvider = new MimeTypeProvider(extensionsToMimeTypes ?? MimeTypeProvider.DefaultMimeTypesByExtension);

            if (!_fileSystem.Exists(_basePath))
            {
                throw new Exception($"Path at {_basePath} could not be found.");
            }
        }