Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Codout.Framework.Common/Codout.Framework.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MimeTypesMap" Version="1.0.8" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

Expand Down
18 changes: 16 additions & 2 deletions Codout.Framework.Common/Extensions/IO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using HeyRed.Mime;
using System.IO;
using System.Net;

namespace Codout.Framework.Common.Extensions
Expand Down Expand Up @@ -73,7 +74,7 @@ public static string ReadWebPage(string url)
var request = WebRequest.Create(url);
// ReSharper disable PossibleNullReferenceException
using (Stream stream = request.GetResponse().GetResponseStream())
// ReSharper restore PossibleNullReferenceException
// ReSharper restore PossibleNullReferenceException
{
if (stream != null)
{
Expand Down Expand Up @@ -550,6 +551,19 @@ public static string MimeType(this string strFileName)
}
return retval;
}

public static string GetMimeType(this string fileName)
{
if (string.IsNullOrWhiteSpace(fileName) || !Path.HasExtension(fileName))
return null;

switch (Path.GetExtension(fileName).ToLower())
{
case ".ogg": return "video/ogg";
}

return MimeTypesMap.GetMimeType(fileName);
}
#endregion
}
}
10 changes: 9 additions & 1 deletion Codout.Framework.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
Expand Down Expand Up @@ -29,6 +28,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codout.Multitenancy", "Codo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codout.Mailer.AWS", "Codout.Mailer.AWS\Codout.Mailer.AWS.csproj", "{A51B2EDB-B261-41B2-B86F-BBA84AE46288}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codout.Framework.Common.Test", "tests\Codout.Framework.Common.Test\Codout.Framework.Common.Test.csproj", "{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{4AB797AD-1525-46E7-B738-6B2400602CA4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{2834E4EA-7AD3-4D09-B62D-430CA4C2289B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DAL", "DAL", "{DA5D055F-6C44-466A-BE23-82DF4395EF36}"
Expand Down Expand Up @@ -97,6 +100,10 @@ Global
{A51B2EDB-B261-41B2-B86F-BBA84AE46288}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51B2EDB-B261-41B2-B86F-BBA84AE46288}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51B2EDB-B261-41B2-B86F-BBA84AE46288}.Release|Any CPU.Build.0 = Release|Any CPU
{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451}.Release|Any CPU.Build.0 = Release|Any CPU
{DE657A9A-7AEE-4592-B199-EE0FAE47414D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE657A9A-7AEE-4592-B199-EE0FAE47414D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE657A9A-7AEE-4592-B199-EE0FAE47414D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -106,6 +113,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6BDCEA2D-905D-4D64-AEB2-ECDFFA1D1451} = {4AB797AD-1525-46E7-B738-6B2400602CA4}
{281F92E8-F224-4036-858E-F04203D9107B} = {B6832CA4-604B-4DC8-908B-06405133B6B6}
{C1B0EF6F-49FD-4199-8BA3-7FD7BA3DD4BA} = {B6832CA4-604B-4DC8-908B-06405133B6B6}
{9F190AFF-FADE-4E54-96D8-FFD6F14ECBEA} = {2834E4EA-7AD3-4D09-B62D-430CA4C2289B}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Codout.Framework.Common\Codout.Framework.Common.csproj" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions tests/Codout.Framework.Common.Test/Extensions/IOTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Codout.Framework.Common.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Codout.Framework.Common.Test.Extensions
{
[TestClass]
public class IOTest
{
[TestMethod]
[DataRow(".JPG", "image/jpeg")]
[DataRow(".ogg", "video/ogg")]
[DataRow(".webm", "video/webm")]
[DataRow(null, null)]
[DataRow("", null)]
[DataRow("noFileExtension", null)]
[DataRow(".invalidExtension", "application/octet-stream")]
public void GetMimeTypeTest(string fileName, string expectedMimeType)
{
Assert.AreEqual(expectedMimeType, IO.GetMimeType(fileName));
}
}
}