diff --git a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Compat/Assert.cs b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Compat/Assert.cs index b410439..f5e5bf2 100644 --- a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Compat/Assert.cs +++ b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Compat/Assert.cs @@ -30,6 +30,9 @@ public static T IsAssignableFrom(object actual) return (T)actual; } + public static void Contains(string expected, string actual) + => NUnit.Framework.Assert.That(() => actual.Contains(expected)); + public static T IsType(object actual) { NUnit.Framework.Assert.True(actual.GetType() == typeof(T), $"Expected: {typeof(T)}\nActual: {actual.GetType()}"); diff --git a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http1Test.cs b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http1Test.cs index f591d8c..3c585c8 100644 --- a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http1Test.cs +++ b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http1Test.cs @@ -22,6 +22,23 @@ public async Task FailedToConnect() // Assert Assert.IsType(ex); + Assert.Contains("(Connect): dns error", ex.Message); + } + + [Fact] + public async Task FailedToConnect_VersionMismatch() + { + // Arrange + using var httpHandler = new Cysharp.Net.Http.YetAnotherHttpHandler() { Http2Only = true }; + var httpClient = new HttpClient(httpHandler); + await using var server = await LaunchServerAsync(TestWebAppServerListenMode.InsecureHttp1Only); + + // Act + var ex = await Record.ExceptionAsync(async () => (await httpClient.GetAsync($"{server.BaseUri}/")).EnsureSuccessStatusCode()); + + // Assert + Assert.IsType(ex); + Assert.Contains("'HTTP_1_1_REQUIRED' (0xd)", ex.Message); } [Fact] diff --git a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http2ClearTextTest.cs b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http2ClearTextTest.cs index fb624a8..375c0fd 100644 --- a/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http2ClearTextTest.cs +++ b/test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http2ClearTextTest.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Net.Http.Headers; +using Fact = NUnit.Framework.TestAttribute; using ConditionalFact = NUnit.Framework.TestAttribute; using Grpc.Core; using System.IO; @@ -17,6 +18,21 @@ public class Http2ClearTextTest : YahaUnityTestBase { + [Fact] + public async Task FailedToConnect_VersionMismatch() + { + // Arrange + using var httpHandler = new Cysharp.Net.Http.YetAnotherHttpHandler() { Http2Only = false }; + var httpClient = new HttpClient(httpHandler); + await using var server = await LaunchServerAsync(); + + // Act + var ex = await Record.ExceptionAsync(async () => (await httpClient.GetAsync($"{server.BaseUri}/")).EnsureSuccessStatusCode()); + + // Assert + Assert.IsType(ex); + } + [ConditionalFact] public async Task Get_Ok() {