Skip to content

Commit

Permalink
Improve code coverage (#458)
Browse files Browse the repository at this point in the history
* Improve code coverage

* Pin culture of the size formatter
  • Loading branch information
Kaliumhexacyanoferrat authored Feb 20, 2024
1 parent 3e4a264 commit f336b9c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Modules/DirectoryBrowsing/Provider/FileSizeFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace GenHTTP.Modules.DirectoryBrowsing.Provider
{
Expand All @@ -22,19 +23,19 @@ public static string Format(ulong? bytes)

if (bytes > TERABYTES)
{
return Math.Round(b / TERABYTES, 2) + " TB";
return Math.Round(b / TERABYTES, 2).ToString(CultureInfo.InvariantCulture) + " TB";
}
if (bytes > GIGABYTES)
{
return Math.Round(b / GIGABYTES, 2) + " GB";
return Math.Round(b / GIGABYTES, 2).ToString(CultureInfo.InvariantCulture) + " GB";
}
else if (bytes > MEGABYTES)
{
return Math.Round(b / MEGABYTES, 2) + " MB";
return Math.Round(b / MEGABYTES, 2).ToString(CultureInfo.InvariantCulture) + " MB";
}
else if (bytes > KILOBYTES)
{
return Math.Round(b / KILOBYTES, 2) + " KB";
return Math.Round(b / KILOBYTES, 2).ToString(CultureInfo.InvariantCulture) + " KB";
}

return $"{bytes} Bytes";
Expand Down
32 changes: 32 additions & 0 deletions Testing/Acceptance/Engine/MethodTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

using GenHTTP.Modules.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Engine
{

[TestClass]
public sealed class MethodTests
{

[TestMethod]
public async Task TestCustomMethods()
{
var result = Content.From(Resource.FromString("OK"));

using var host = TestHost.Run(result);

var request = host.GetRequest(method: new HttpMethod("BREW"));

using var response = await host.GetResponseAsync(request);

await response.AssertStatusAsync(HttpStatusCode.OK);
}

}

}
27 changes: 27 additions & 0 deletions Testing/Acceptance/Engine/SimpleCertificateProviderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Security.Cryptography.X509Certificates;

using GenHTTP.Engine.Infrastructure.Endpoints;

using NSubstitute;

namespace GenHTTP.Testing.Acceptance.Engine
{

[TestClass]
public sealed class SimpleCertificateProviderTest
{

[TestMethod]
public void TestProvider()
{
using var cert = Substitute.For<X509Certificate2>();

var provider = new SimpleCertificateProvider(cert);

Assert.IsNotNull(provider.Provide("google.com"));
}

}

}
2 changes: 2 additions & 0 deletions Testing/Acceptance/GenHTTP.Testing.Acceptance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="NSubstitute" Version="5.1.0" />

</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions Testing/Acceptance/Modules/DirectoryBrowsing/FormatterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using GenHTTP.Modules.DirectoryBrowsing.Provider;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.DirectoryBrowsing
{

[TestClass]
public sealed class FormatterTest
{

[TestMethod]
public void TestFormatting()
{
Assert.AreEqual("512 Bytes", FileSizeFormatter.Format(512));

Assert.AreEqual("2.78 KB", FileSizeFormatter.Format(2842));

Assert.AreEqual("2.78 MB", FileSizeFormatter.Format(2842 * 1024));

Assert.AreEqual("2.78 GB", FileSizeFormatter.Format(2842L * 1024 * 1024));

Assert.AreEqual("2.78 TB", FileSizeFormatter.Format(2842L * 1024 * 1024 * 1024));
}

}

}

0 comments on commit f336b9c

Please sign in to comment.