public void TestGuessDefaultFileExtension(string mimeType, string extension) { var sut = new MimeTypeByExtension(); var actual = sut.GuessDefaultExtensionFor(mimeType); actual.Should().Be(extension); }
public void TryFilesWhichWorkWithUrlmon(string filename, string mimetype) { var uri = filename.ToUri(); var actual = new MimeTypeByExtension().GetMimeTypeFor(uri); actual.Should().Be(mimetype); }
public void TestGetExtensions(string mimeType, string extensions) { var sut = new MimeTypeByExtension(); var actual = sut.GetExtensionsFor(mimeType); var expected = extensions.Split(','); actual.Should().Contain(expected); }
public void TestRegisterCustomExtension() { MimeTypeByExtension.IsRegistered("cs").Should().BeFalse(); try { MimeTypeByExtension.Register("cs", "text/plain"); MimeTypeByExtension.IsRegistered("cs").Should().BeTrue(); new MimeTypeByExtension().GetMimeTypeFor(@"test\code.cs".ToUri()).Should().Be("text/plain"); } finally { MimeTypeByExtension.UseDefaulMapping(); } }
public void TestOverrideMimeMapping() { // cf.: http://stackoverflow.com/questions/208056/what-are-the-mime-types-for-net-project-source-code-files MimeTypeByExtension.IsRegistered("cs").Should().BeFalse(); try { var myMapping = new Dictionary <string, string> { { "cs", "text/plain" } }; MimeTypeByExtension.UseMimeMapping(myMapping); new MimeTypeByExtension().GetMimeTypeFor(@"test\code.cs".ToUri()).Should().Be("text/plain"); } finally { MimeTypeByExtension.UseDefaulMapping(); } }