Skip to content

Commit

Permalink
Update unit tests that run on Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Aug 1, 2024
1 parent 5365da3 commit c998fba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static T IsAssignableFrom<T>(object actual)
return (T)actual;
}

public static void Contains(string expected, string actual)
=> NUnit.Framework.Assert.That(() => actual.Contains(expected));

public static T IsType<T>(object actual)
{
NUnit.Framework.Assert.True(actual.GetType() == typeof(T), $"Expected: {typeof(T)}\nActual: {actual.GetType()}");
Expand Down
17 changes: 17 additions & 0 deletions test/YetAnotherHttpHandler.Unity.Test/Assets/Tests/Http1Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ public async Task FailedToConnect()

// Assert
Assert.IsType<HttpRequestException>(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<TestServerForHttp1AndHttp2>(TestWebAppServerListenMode.InsecureHttp1Only);

// Act
var ex = await Record.ExceptionAsync(async () => (await httpClient.GetAsync($"{server.BaseUri}/")).EnsureSuccessStatusCode());

// Assert
Assert.IsType<HttpRequestException>(ex);
Assert.Contains("'HTTP_1_1_REQUIRED' (0xd)", ex.Message);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TestServerForHttp1AndHttp2>();

// Act
var ex = await Record.ExceptionAsync(async () => (await httpClient.GetAsync($"{server.BaseUri}/")).EnsureSuccessStatusCode());

// Assert
Assert.IsType<HttpRequestException>(ex);
}

[ConditionalFact]
public async Task Get_Ok()
{
Expand Down

0 comments on commit c998fba

Please sign in to comment.