-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3ec049
commit 3db6870
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
} |