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

Commit bfeab0b

Browse files
authored
Merge pull request #576 from 0xced/UpdateUnitTests
Perform maintenance on the unit tests project
2 parents eacbc51 + ad5abeb commit bfeab0b

7 files changed

+148
-205
lines changed

src/IdentityModel.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
</PropertyGroup>
3737

3838
<!--Conditional compilation-->
39-
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
40-
<TargetFrameworks>net462;net472;netstandard2.0;net6.0</TargetFrameworks>
41-
</PropertyGroup>
42-
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
39+
<PropertyGroup>
4340
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
4441
</PropertyGroup>
42+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
43+
<TargetFrameworks>net462;net472;$(TargetFrameworks)</TargetFrameworks>
44+
</PropertyGroup>
4545

4646
<ItemGroup>
4747
<PackageReference Include="minver" Version="5.0.0" PrivateAssets="All" />

test/UnitTests/HttpClientExtensions/PushedAuthorizationTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public async Task Additional_request_parameters_should_be_handled_correctly()
188188
}
189189

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

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

201-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("response_type");
201+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("response_type");
202202
}
203203

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

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

216-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("request_uri");
216+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("request_uri");
217217
}
218218
}
219219
}

test/UnitTests/HttpClientExtensions/TokenIntrospectionTests.cs

+102-139
Large diffs are not rendered by default.

test/UnitTests/HttpClientExtensions/TokenRequestExtensionsRequestTests.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ public async Task dpop_nonce_should_be_returned()
221221

222222

223223
[Fact]
224-
public void Explicit_null_parameters_should_not_fail_()
224+
public async Task Explicit_null_parameters_should_not_fail_()
225225
{
226226
Func<Task> act = async () =>
227227
await _client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
228228
{ ClientId = "client", Parameters = null });
229229

230-
act.Should().NotThrow();
230+
await act.Should().NotThrowAsync();
231231
}
232232

233233
[Fact]
@@ -250,12 +250,12 @@ public async Task Device_request_should_have_correct_format()
250250
}
251251

252252
[Fact]
253-
public void Device_request_without_device_code_should_fail()
253+
public async Task Device_request_without_device_code_should_fail()
254254
{
255255
Func<Task> act = async () =>
256256
await _client.RequestDeviceTokenAsync(new DeviceTokenRequest { ClientId = "device" });
257257

258-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("device_code");
258+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("device_code");
259259
}
260260

261261
[Fact]
@@ -314,11 +314,11 @@ public async Task Password_request_without_password_should_have_correct_format()
314314
}
315315

316316
[Fact]
317-
public void Password_request_without_username_should_fail()
317+
public async Task Password_request_without_username_should_fail()
318318
{
319319
Func<Task> act = async () => await _client.RequestPasswordTokenAsync(new PasswordTokenRequest());
320320

321-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("username");
321+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("username");
322322
}
323323

324324
[Fact]
@@ -355,27 +355,27 @@ public async Task Code_request_should_have_correct_format()
355355
}
356356

357357
[Fact]
358-
public void Code_request_without_code_should_fail()
358+
public async Task Code_request_without_code_should_fail()
359359
{
360360
Func<Task> act = async () => await _client.RequestAuthorizationCodeTokenAsync(
361361
new AuthorizationCodeTokenRequest
362362
{
363363
RedirectUri = "uri"
364364
});
365365

366-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("code");
366+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("code");
367367
}
368368

369369
[Fact]
370-
public void Code_request_without_redirect_uri_should_fail()
370+
public async Task Code_request_without_redirect_uri_should_fail()
371371
{
372372
Func<Task> act = async () => await _client.RequestAuthorizationCodeTokenAsync(
373373
new AuthorizationCodeTokenRequest
374374
{
375375
Code = "code"
376376
});
377377

378-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("redirect_uri");
378+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("redirect_uri");
379379
}
380380

381381
[Fact]
@@ -408,11 +408,11 @@ public async Task Refresh_request_should_have_correct_format()
408408
}
409409

410410
[Fact]
411-
public void Refresh_request_without_refresh_token_should_fail()
411+
public async Task Refresh_request_without_refresh_token_should_fail()
412412
{
413413
Func<Task> act = async () => await _client.RequestRefreshTokenAsync(new RefreshTokenRequest());
414414

415-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("refresh_token");
415+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("refresh_token");
416416
}
417417

418418
[Fact]
@@ -492,11 +492,11 @@ public async Task Backchannel_authentication_request_should_have_correct_format(
492492
}
493493

494494
[Fact]
495-
public void Setting_no_grant_type_should_fail()
495+
public async Task Setting_no_grant_type_should_fail()
496496
{
497497
Func<Task> act = async () => await _client.RequestTokenAsync(new TokenRequest());
498498

499-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("grant_type");
499+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("grant_type");
500500
}
501501

502502
[Fact]

test/UnitTests/Infrastructure/FileName.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44
using System.IO;
5+
using System.Runtime.CompilerServices;
56

67
namespace IdentityModel.UnitTests
78
{
89
internal static class FileName
910
{
10-
public static string Create(string name)
11-
{
12-
#if NETCOREAPP2_1 || NETCOREAPP3_1 || NET5_0 || NET6_0 || NET7_0 || NET8_0
13-
var fullName = Path.Combine(System.AppContext.BaseDirectory, "documents", name);
14-
#else
15-
var fullName = Path.Combine(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath, "documents", name);
16-
#endif
11+
public static string Create(string name) => Path.Combine(UnitTestsPath(), "documents", name);
1712

18-
return fullName;
19-
}
13+
private static string UnitTestsPath([CallerFilePath] string path = "") => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), ".."));
2014
}
2115
}

test/UnitTests/TokenClientRequestTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public async Task Device_request_should_have_correct_format()
7878
}
7979

8080
[Fact]
81-
public void Device_request_without_device_code_should_fail()
81+
public async Task Device_request_without_device_code_should_fail()
8282
{
8383
var tokenClient = new TokenClient(_client, new TokenClientOptions { ClientId = "device" });
8484

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

87-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("device_code");
87+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("device_code");
8888
}
8989

9090
[Fact]
@@ -131,13 +131,13 @@ public async Task Password_request_without_password_should_have_correct_format()
131131
}
132132

133133
[Fact]
134-
public void Password_request_without_username_should_fail()
134+
public async Task Password_request_without_username_should_fail()
135135
{
136136
var tokenClient = new TokenClient(_client, new TokenClientOptions());
137137

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

140-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("username");
140+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("username");
141141
}
142142

143143
[Fact]
@@ -164,23 +164,23 @@ public async Task Code_request_should_have_correct_format()
164164
}
165165

166166
[Fact]
167-
public void Code_request_without_code_should_fail()
167+
public async Task Code_request_without_code_should_fail()
168168
{
169169
var tokenClient = new TokenClient(_client, new TokenClientOptions());
170170

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

173-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("code");
173+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("code");
174174
}
175175

176176
[Fact]
177-
public void Code_request_without_redirect_uri_should_fail()
177+
public async Task Code_request_without_redirect_uri_should_fail()
178178
{
179179
var tokenClient = new TokenClient(_client, new TokenClientOptions());
180180

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

183-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("redirect_uri");
183+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("redirect_uri");
184184
}
185185

186186
[Fact]
@@ -204,23 +204,23 @@ public async Task Refresh_request_should_have_correct_format()
204204
}
205205

206206
[Fact]
207-
public void Refresh_request_without_refresh_token_should_fail()
207+
public async Task Refresh_request_without_refresh_token_should_fail()
208208
{
209209
var tokenClient = new TokenClient(_client, new TokenClientOptions());
210210

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

213-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("refresh_token");
213+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("refresh_token");
214214
}
215215

216216
[Fact]
217-
public void Setting_no_grant_type_should_fail()
217+
public async Task Setting_no_grant_type_should_fail()
218218
{
219219
var tokenClient = new TokenClient(_client, new TokenClientOptions());
220220

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

223-
act.Should().Throw<ArgumentException>().And.ParamName.Should().Be("grant_type");
223+
(await act.Should().ThrowAsync<ArgumentException>()).WithParameterName("grant_type");
224224
}
225225

226226
[Fact]

test/UnitTests/UnitTests.csproj

+9-23
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,30 @@
33
<IsPackable>false</IsPackable>
44
<AssemblyOriginatorKeyFile>../../key.snk</AssemblyOriginatorKeyFile>
55
<SignAssembly>true</SignAssembly>
6+
<DeterministicSourcePaths>false</DeterministicSourcePaths>
67
</PropertyGroup>
78

89
<!--Conditional compilation-->
9-
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
10-
<TargetFrameworks>net462;net472;net6.0;net7.0;net8.0</TargetFrameworks>
11-
</PropertyGroup>
12-
13-
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' and '$(NETCoreSdkPortableRuntimeIdentifier)' != 'osx-arm64' ">
10+
<PropertyGroup>
1411
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
1512
</PropertyGroup>
16-
17-
<PropertyGroup Condition=" '$(NETCoreSdkPortableRuntimeIdentifier)' == 'osx-arm64' ">
18-
<TargetFrameworks>net6.0</TargetFrameworks>
13+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
14+
<TargetFrameworks>net462;net472;$(TargetFrameworks)</TargetFrameworks>
1915
</PropertyGroup>
2016

21-
<ItemGroup>
22-
<None Update="documents\*">
23-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24-
</None>
25-
</ItemGroup>
26-
2717
<ItemGroup>
2818
<ProjectReference Include="..\..\src\IdentityModel.csproj" />
2919
</ItemGroup>
3020

3121
<ItemGroup>
32-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
33-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
34-
<PackageReference Include="xunit" Version="2.7.0" />
35-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
36-
</ItemGroup>
37-
38-
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' or $(TargetFramework) == 'net7.0' or $(TargetFramework) == 'net8.0'">
3922
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
24+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="All" />
25+
<PackageReference Include="xunit" Version="2.8.1" />
26+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
4027
</ItemGroup>
4128

4229
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or $(TargetFramework) == 'net472'">
43-
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
44-
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
30+
<Reference Include="System.Net.Http" />
4531
</ItemGroup>
4632
</Project>

0 commit comments

Comments
 (0)