-
-
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
64a303e
commit c148161
Showing
4 changed files
with
140 additions
and
25 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
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,99 @@ | ||
using System.Net; | ||
using GenHTTP.Api.Protocol; | ||
using GenHTTP.Modules.Functional; | ||
using GenHTTP.Modules.IO; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Engine.Kestrel; | ||
|
||
[TestClass] | ||
public class KestrelTests | ||
{ | ||
|
||
[TestMethod] | ||
public async Task TestLifecycle() | ||
{ | ||
var handler = Content.From(Resource.FromString("Hello Kestrel!")).Build(); | ||
|
||
await using var host = new TestHost(handler, engine: TestEngine.Kestrel); | ||
|
||
await host.StartAsync(); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestHeaders() | ||
{ | ||
var app = Inline.Create().Get((IRequest request) => | ||
{ | ||
var count = request.Headers.Count; | ||
|
||
Assert.AreEqual(count, request.Headers.Keys.Count()); | ||
Assert.AreEqual(count, request.Headers.Values.Count()); | ||
|
||
Assert.IsTrue(request.Headers.All(kv => kv.Value != string.Empty)); | ||
|
||
Assert.IsTrue(request.Headers.ContainsKey("Host")); | ||
|
||
Assert.IsNotNull(request.Headers["Host"]); | ||
|
||
return true; | ||
}); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: TestEngine.Kestrel); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestQuery() | ||
{ | ||
var app = Inline.Create().Get((IRequest request) => | ||
{ | ||
var count = request.Query.Count; | ||
|
||
Assert.AreEqual(count, request.Query.Keys.Count()); | ||
Assert.AreEqual(count, request.Query.Values.Count()); | ||
|
||
Assert.IsTrue(request.Query.All(kv => kv.Value != string.Empty)); | ||
|
||
Assert.IsTrue(request.Query.ContainsKey("a")); | ||
|
||
Assert.IsNotNull(request.Query["a"]); | ||
|
||
return true; | ||
}); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: TestEngine.Kestrel); | ||
|
||
using var response = await host.GetResponseAsync("/?a=1&b=2"); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestConnection() | ||
{ | ||
var app = Inline.Create().Get((IRequest request) => | ||
{ | ||
Assert.IsNotNull(request.Client.Host); | ||
|
||
Assert.AreEqual(ClientProtocol.Http, request.Client.Protocol); | ||
|
||
return true; | ||
}); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: TestEngine.Kestrel); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
using System.Net; | ||
using GenHTTP.Api.Protocol; | ||
using GenHTTP.Modules.Functional; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Engine; | ||
|
||
[TestClass] | ||
public class RequestPropertyTest | ||
{ | ||
|
||
[TestMethod] | ||
[MultiEngineTest] | ||
public async Task TestRequestProperties(TestEngine engine) | ||
{ | ||
var app = Inline.Create().Get((IRequest request) => | ||
{ | ||
request.Properties["my"] = "value"; | ||
|
||
Assert.IsTrue(request.Properties.TryGet<string>("my", out _)); | ||
|
||
request.Properties.Clear("my"); | ||
|
||
Assert.IsFalse(request.Properties.TryGet<string>("my", out _)); | ||
|
||
Assert.ThrowsException<KeyNotFoundException>(() => request.Properties["my"]); | ||
|
||
return true; | ||
}); | ||
|
||
await using var host = await TestHost.RunAsync(app, engine: engine); | ||
|
||
using var response = await host.GetResponseAsync(); | ||
|
||
await response.AssertStatusAsync(HttpStatusCode.OK); | ||
} | ||
|
||
} |