Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 17, 2024
1 parent a3ec049 commit 3db6870
Showing 3 changed files with 143 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Testing/Acceptance/Engine/RoutingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using GenHTTP.Api.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Engine;

[TestClass]
public class RoutingTests
{

[TestMethod]
public void TestComparers()
{
var path = new WebPathPart("%C3%A4%2F");

Assert.IsTrue(path == "ä/");
Assert.IsTrue(path == "%C3%A4%2F");

Assert.IsTrue(path != "ö/");
}

[TestMethod]
public void TestEquality()
{
var one = new WebPathPart("%C3%A4%2F");
var two = new WebPathPart("%C3%A4%2F");

Assert.IsTrue(one.Equals(two));
Assert.IsTrue(two.Equals(one));

var three = new WebPathPart("ä/");

Assert.IsFalse(one.Equals(three));
Assert.IsFalse(one.Equals(new List<int>()));
Assert.IsFalse(one.Equals(null));
}

}
33 changes: 33 additions & 0 deletions Testing/Acceptance/Modules/Functional/IntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Net;
using GenHTTP.Modules.Conversion;
using GenHTTP.Modules.Conversion.Formatters;
using GenHTTP.Modules.Functional;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.Functional;

[TestClass]
public class IntegrationTest
{

[TestMethod]
[MultiEngineTest]
public async Task TestFormatters(TestEngine engine)
{
var formatting = Formatting.Empty()
.Add<BoolFormatter>();

var api = Inline.Create()
.Any("get-bool", (bool value) => value)
.Formatters(formatting);

await using var host = await TestHost.RunAsync(api, engine: engine);

using var response = await host.GetResponseAsync("/get-bool?value=1");

await response.AssertStatusAsync(HttpStatusCode.OK);

Assert.AreEqual("1", await response.GetContentAsync());
}

}
73 changes: 73 additions & 0 deletions Testing/Acceptance/Modules/Functional/MethodTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Net;
using System.Net.Http.Headers;
using GenHTTP.Modules.Functional;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.Functional;

[TestClass]
public class MethodTest
{

[TestMethod]
[MultiEngineTest]
public async Task TestAnyMethod(TestEngine engine)
{
var app = Inline.Create()
.Any((List<int> data) => data.Count);

await using var host = await TestHost.RunAsync(app, engine: engine);

foreach (var method in new[]
{
HttpMethod.Post, HttpMethod.Put
})
{
var request = host.GetRequest(method: method);

request.Content = new StringContent("[ 1, 2 ]");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

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

await response.AssertStatusAsync(HttpStatusCode.OK);

Assert.AreEqual("2", await response.GetContentAsync());
}
}

[TestMethod]
[MultiEngineTest]
public async Task TestDelete(TestEngine engine)
{
var app = Inline.Create()
.Delete(() => { });

await using var host = await TestHost.RunAsync(app, engine: engine);

var request = host.GetRequest(method: HttpMethod.Delete);

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

await response.AssertStatusAsync(HttpStatusCode.NoContent);
}

[TestMethod]
[MultiEngineTest]
public async Task TestHead(TestEngine engine)
{
var app = Inline.Create()
.Head(() => "42");

await using var host = await TestHost.RunAsync(app, engine: engine);

var request = host.GetRequest(method: HttpMethod.Head);

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

await response.AssertStatusAsync(HttpStatusCode.OK);

Assert.AreEqual("2", response.GetContentHeader("Content-Length"));
}

}

0 comments on commit 3db6870

Please sign in to comment.