Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Perform maintenance on the unit tests project #576

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/IdentityModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
</PropertyGroup>

<!--Conditional compilation-->
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net462;net472;netstandard2.0;net6.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<TargetFrameworks>net462;net472;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="minver" Version="4.3.0" PrivateAssets="All" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task Additional_request_parameters_should_be_handled_correctly()
}

[Fact]
public void Pushed_authorization_without_response_type_should_fail()
public async Task Pushed_authorization_without_response_type_should_fail()
{
var document = File.ReadAllText(FileName.Create("success_par_response.json"));
var handler = new NetworkHandler(document, HttpStatusCode.OK);
Expand All @@ -198,11 +198,11 @@ public void Pushed_authorization_without_response_type_should_fail()

Func<Task> act = async () => await client.PushAuthorizationAsync(Request);

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("response_type");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("response_type");
}

[Fact]
public void Pushed_authorization_with_request_uri_should_fail()
public async Task Pushed_authorization_with_request_uri_should_fail()
{
var document = File.ReadAllText(FileName.Create("success_par_response.json"));
var handler = new NetworkHandler(document, HttpStatusCode.OK);
Expand All @@ -213,7 +213,7 @@ public void Pushed_authorization_with_request_uri_should_fail()

Func<Task> act = async () => await client.PushAuthorizationAsync(Request);

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("request_uri");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("request_uri");
}
}
}
241 changes: 102 additions & 139 deletions test/UnitTests/HttpClientExtensions/TokenIntrospectionTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ public async Task dpop_nonce_should_be_returned()


[Fact]
public void Explicit_null_parameters_should_not_fail_()
public async Task Explicit_null_parameters_should_not_fail_()
{
Func<Task> act = async () =>
await _client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{ ClientId = "client", Parameters = null });

act.Should().NotThrow();
await act.Should().NotThrowAsync();
}

[Fact]
Expand All @@ -250,12 +250,12 @@ public async Task Device_request_should_have_correct_format()
}

[Fact]
public void Device_request_without_device_code_should_fail()
public async Task Device_request_without_device_code_should_fail()
{
Func<Task> act = async () =>
await _client.RequestDeviceTokenAsync(new DeviceTokenRequest { ClientId = "device" });

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("device_code");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("device_code");
}

[Fact]
Expand Down Expand Up @@ -314,11 +314,11 @@ public async Task Password_request_without_password_should_have_correct_format()
}

[Fact]
public void Password_request_without_username_should_fail()
public async Task Password_request_without_username_should_fail()
{
Func<Task> act = async () => await _client.RequestPasswordTokenAsync(new PasswordTokenRequest());

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("username");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("username");
}

[Fact]
Expand Down Expand Up @@ -355,27 +355,27 @@ public async Task Code_request_should_have_correct_format()
}

[Fact]
public void Code_request_without_code_should_fail()
public async Task Code_request_without_code_should_fail()
{
Func<Task> act = async () => await _client.RequestAuthorizationCodeTokenAsync(
new AuthorizationCodeTokenRequest
{
RedirectUri = "uri"
});

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("code");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("code");
}

[Fact]
public void Code_request_without_redirect_uri_should_fail()
public async Task Code_request_without_redirect_uri_should_fail()
{
Func<Task> act = async () => await _client.RequestAuthorizationCodeTokenAsync(
new AuthorizationCodeTokenRequest
{
Code = "code"
});

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("redirect_uri");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("redirect_uri");
}

[Fact]
Expand Down Expand Up @@ -408,11 +408,11 @@ public async Task Refresh_request_should_have_correct_format()
}

[Fact]
public void Refresh_request_without_refresh_token_should_fail()
public async Task Refresh_request_without_refresh_token_should_fail()
{
Func<Task> act = async () => await _client.RequestRefreshTokenAsync(new RefreshTokenRequest());

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("refresh_token");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("refresh_token");
}

[Fact]
Expand Down Expand Up @@ -492,11 +492,11 @@ public async Task Backchannel_authentication_request_should_have_correct_format(
}

[Fact]
public void Setting_no_grant_type_should_fail()
public async Task Setting_no_grant_type_should_fail()
{
Func<Task> act = async () => await _client.RequestTokenAsync(new TokenRequest());

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("grant_type");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("grant_type");
}

[Fact]
Expand Down
12 changes: 3 additions & 9 deletions test/UnitTests/Infrastructure/FileName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System.IO;
using System.Runtime.CompilerServices;

namespace IdentityModel.UnitTests
{
internal static class FileName
{
public static string Create(string name)
{
#if NETCOREAPP2_1 || NETCOREAPP3_1 || NET5_0 || NET6_0 || NET7_0 || NET8_0
var fullName = Path.Combine(System.AppContext.BaseDirectory, "documents", name);
#else
var fullName = Path.Combine(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath, "documents", name);
#endif
public static string Create(string name) => Path.Combine(UnitTestsPath(), "documents", name);

return fullName;
}
private static string UnitTestsPath([CallerFilePath] string path = "") => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), ".."));
}
}
24 changes: 12 additions & 12 deletions test/UnitTests/TokenClientRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public async Task Device_request_should_have_correct_format()
}

[Fact]
public void Device_request_without_device_code_should_fail()
public async Task Device_request_without_device_code_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions { ClientId = "device" });

Func<Task> act = async () => await tokenClient.RequestDeviceTokenAsync(null);

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("device_code");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("device_code");
}

[Fact]
Expand Down Expand Up @@ -131,13 +131,13 @@ public async Task Password_request_without_password_should_have_correct_format()
}

[Fact]
public void Password_request_without_username_should_fail()
public async Task Password_request_without_username_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions());

Func<Task> act = async () => await tokenClient.RequestPasswordTokenAsync(userName: null);

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("username");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("username");
}

[Fact]
Expand All @@ -164,23 +164,23 @@ public async Task Code_request_should_have_correct_format()
}

[Fact]
public void Code_request_without_code_should_fail()
public async Task Code_request_without_code_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions());

Func<Task> act = async () => await tokenClient.RequestAuthorizationCodeTokenAsync(code: null, redirectUri: "uri", codeVerifier: "verifier");

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("code");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("code");
}

[Fact]
public void Code_request_without_redirect_uri_should_fail()
public async Task Code_request_without_redirect_uri_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions());

Func<Task> act = async () => await tokenClient.RequestAuthorizationCodeTokenAsync(code: "code", redirectUri: null, codeVerifier: "verifier");

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("redirect_uri");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("redirect_uri");
}

[Fact]
Expand All @@ -204,23 +204,23 @@ public async Task Refresh_request_should_have_correct_format()
}

[Fact]
public void Refresh_request_without_refresh_token_should_fail()
public async Task Refresh_request_without_refresh_token_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions());

Func<Task> act = async () => await tokenClient.RequestRefreshTokenAsync(refreshToken: null, scope: "scope");

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("refresh_token");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("refresh_token");
}

[Fact]
public void Setting_no_grant_type_should_fail()
public async Task Setting_no_grant_type_should_fail()
{
var tokenClient = new TokenClient(_client, new TokenClientOptions());

Func<Task> act = async () => await tokenClient.RequestTokenAsync(grantType: null);

act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("grant_type");
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("grant_type");
}

[Fact]
Expand Down
32 changes: 9 additions & 23 deletions test/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,30 @@
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
</PropertyGroup>

<!--Conditional compilation-->
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net462;net472;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' and '$(NETCoreSdkPortableRuntimeIdentifier)' != 'osx-arm64' ">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition=" '$(NETCoreSdkPortableRuntimeIdentifier)' == 'osx-arm64' ">
<TargetFrameworks>net6.0</TargetFrameworks>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<TargetFrameworks>net462;net472;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<None Update="documents\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\IdentityModel.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' or $(TargetFramework) == 'net7.0' or $(TargetFramework) == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="All" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or $(TargetFramework) == 'net472'">
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
Loading