Skip to content

Commit

Permalink
Add overload for MimeTypes.GetMimeType(string)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Barratt committed Nov 8, 2012
1 parent af3aa4c commit b5f0af1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/XeroApi.Tests/MimeTypesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using NUnit.Framework;

namespace XeroApi.Tests
{
public class MimeTypesTests
{
[Test]
public void it_can_return_the_mime_type_for_a_filename()
{
string mimeType = MimeTypes.GetMimeType("anyFilename.pdf");

Assert.AreEqual("application/pdf", mimeType);
}

[Test]
public void it_can_return_the_mime_type_for_a_filepath()
{
string mimeType = MimeTypes.GetMimeType(@"c:\any\dir\anyFilename.jpeg");

Assert.AreEqual("image/jpeg", mimeType);
}

[Test]
public void it_can_return_the_mime_type_for_a_fileinfo()
{
var mimeType = MimeTypes.GetMimeType(new FileInfo("anyFilename.docx"));

Assert.AreEqual("application/vnd.openxmlformats-officedocument.wordprocessingml.document", mimeType);
}
}
}
1 change: 1 addition & 0 deletions source/XeroApi.Tests/XeroApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="ApiQueryTests.cs" />
<Compile Include="EventTimelineTests.cs" />
<Compile Include="IntegrationProxyHelperTests.cs" />
<Compile Include="MimeTypesTests.cs" />
<Compile Include="ModelSerializationTests.cs" />
<Compile Include="OAuth\Consumer\ConsumerRequestTests.cs" />
<Compile Include="PauseTimeTests.cs" />
Expand Down
5 changes: 5 additions & 0 deletions source/XeroApi/MimeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public static string GetMimeType(FileInfo fileInfo)

return mimeType;
}

public static string GetMimeType(string fileName)
{
return GetMimeType(new FileInfo(fileName));
}
}
}

0 comments on commit b5f0af1

Please sign in to comment.