Skip to content

Commit

Permalink
Replaces FluentAssertions with Shouldly (#1768)
Browse files Browse the repository at this point in the history
* Replace FluentAssertions with Shouldly

---------

Co-authored-by: Brett Hazen <[email protected]>
  • Loading branch information
damianh and bhazen authored Feb 11, 2025
1 parent f2e3734 commit 1274511
Show file tree
Hide file tree
Showing 180 changed files with 4,648 additions and 4,560 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# MacOs
.DS_Store

# Rider
.idea

Expand Down
2 changes: 0 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
<PackageVersion Include="Duende.IdentityModel" Version="7.0.0" />
<PackageVersion Include="Duende.IdentityModel.OidcClient" Version="6.0.0-rc.1" />
<PackageVersion Include="Duende.IdentityServer" Version="$(IdentityServerVersion)" />
<PackageVersion Include="FluentAssertions" Version="6.5.1" />
<PackageVersion Include="FluentAssertions.Web" Version="1.5.0" />
<PackageVersion Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Certificate" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(AspNetCoreVersion)" />
Expand Down
3 changes: 2 additions & 1 deletion identity-server/identity-server.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"identity-server\\test\\EntityFramework.Storage.IntegrationTests\\EntityFramework.Storage.IntegrationTests.csproj",
"identity-server\\test\\EntityFramework.Storage.UnitTests\\EntityFramework.Storage.UnitTests.csproj",
"identity-server\\test\\IdentityServer.IntegrationTests\\IdentityServer.IntegrationTests.csproj",
"identity-server\\test\\IdentityServer.UnitTests\\IdentityServer.UnitTests.csproj"
"identity-server\\test\\IdentityServer.UnitTests\\IdentityServer.UnitTests.csproj",
"shared\\ShouldlyExtensions\\ShouldlyExtensions.csproj"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageReference Include="FluentAssertions" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE in the project root for license information.


using FluentAssertions;
using Shouldly;
using IntegrationTests.TestHosts;
using Xunit;
using Duende.IdentityServer.Configuration.Models.DynamicClientRegistration;
Expand Down Expand Up @@ -30,15 +30,15 @@ public async Task valid_request_creates_new_client()
var httpResponse = await ConfigurationHost.HttpClient!.PostAsJsonAsync("/connect/dcr", request);

var response = await httpResponse.Content.ReadFromJsonAsync<DynamicClientRegistrationResponse>();
response.Should().NotBeNull();
response.ShouldNotBeNull();
var newClient = await IdentityServerHost.GetClientAsync(response!.ClientId); // Not null already asserted
newClient.Should().NotBeNull();
newClient.ClientId.Should().Be(response.ClientId);
newClient.AllowedGrantTypes.Should().BeEquivalentTo(request.GrantTypes);
newClient.ClientName.Should().Be(request.ClientName);
newClient.ClientUri.Should().Be(request.ClientUri.ToString());
newClient.UserSsoLifetime.Should().Be(request.DefaultMaxAge);
newClient.ClientSecrets.Count.Should().Be(1);
newClient.ClientSecrets.Single().Value.Should().Be(response.ClientSecret.Sha256());
newClient.ShouldNotBeNull();
newClient.ClientId.ShouldBe(response.ClientId);
newClient.AllowedGrantTypes.ShouldBe(request.GrantTypes);
newClient.ClientName.ShouldBe(request.ClientName);
newClient.ClientUri.ShouldBe(request.ClientUri.ToString());
newClient.UserSsoLifetime.ShouldBe(request.DefaultMaxAge);
newClient.ClientSecrets.Count.ShouldBe(1);
newClient.ClientSecrets.Single().Value.ShouldBe(response.ClientSecret.Sha256());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


using System.Net;
using FluentAssertions;
using Shouldly;
using IntegrationTests.TestHosts;
using Xunit;
using Duende.IdentityServer.Configuration.Models.DynamicClientRegistration;
Expand All @@ -18,7 +18,7 @@ public class DynamicClientRegistrationValidationTests : ConfigurationIntegration
public async Task http_get_method_should_fail()
{
var response = await ConfigurationHost.HttpClient!.GetAsync("/connect/dcr");
response.StatusCode.Should().Be(HttpStatusCode.MethodNotAllowed);
response.StatusCode.ShouldBe(HttpStatusCode.MethodNotAllowed);
}

[Fact]
Expand All @@ -29,7 +29,7 @@ public async Task incorrect_content_type_should_fail()
{ "grant_types", "authorization_code" }
});
var response = await ConfigurationHost.HttpClient!.PostAsync("/connect/dcr", content);
response.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType);
response.StatusCode.ShouldBe(HttpStatusCode.UnsupportedMediaType);
}

[Fact]
Expand All @@ -39,10 +39,10 @@ public async Task missing_grant_type_should_fail()
{
redirect_uris = new[] { "https://example.com/callback" }
});
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_client_metadata");
error?.Error.ShouldBe("invalid_client_metadata");
}

[Fact]
Expand All @@ -53,10 +53,10 @@ public async Task unsupported_grant_type_should_fail()
redirect_uris = new[] { "https://example.com/callback" },
grant_types = new[] { "password" }
});
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_client_metadata");
error?.Error.ShouldBe("invalid_client_metadata");
}

[Fact]
Expand All @@ -67,10 +67,10 @@ public async Task client_credentials_with_redirect_uri_should_fail()
redirect_uris = new[] { "https://example.com/callback" },
grant_types = new[] { "client_credentials" }
});
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_redirect_uri");
error?.Error.ShouldBe("invalid_redirect_uri");
}

[Fact]
Expand All @@ -80,10 +80,10 @@ public async Task auth_code_without_redirect_uri_should_fail()
{
grant_types = new[] { "authorization_code", "client_credentials" }
});
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_redirect_uri");
error?.Error.ShouldBe("invalid_redirect_uri");
}

[Fact]
Expand All @@ -93,10 +93,10 @@ public async Task client_credentials_and_refresh_token_should_fail()
{
grant_types = new[] { "client_credentials", "refresh_token" }
});
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_client_metadata");
error?.Error.ShouldBe("invalid_client_metadata");
}

[Fact]
Expand All @@ -110,9 +110,9 @@ public async Task jwks_and_jwks_uri_used_together_should_fail()
JwksUri = new Uri("https://example.com")
}
);
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);

var error = await response.Content.ReadFromJsonAsync<DynamicClientRegistrationError>();
error?.Error.Should().Be("invalid_client_metadata");
error?.Error.ShouldBe("invalid_client_metadata");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
Expand All @@ -28,6 +28,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\shared\ShouldlyExtensions\ShouldlyExtensions.csproj" />
<ProjectReference Include="..\..\src\EntityFramework.Storage\Duende.IdentityServer.EntityFramework.Storage.csproj" />
<ProjectReference Include="..\..\src\IdentityServer\Duende.IdentityServer.csproj" />
<ProjectReference Include="..\..\src\Storage\Duende.IdentityServer.Storage.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
// See LICENSE in the project root for license information.


using System;
using System.Linq;
using System.Threading.Tasks;
using Duende.IdentityServer.EntityFramework.DbContexts;
using Duende.IdentityServer.EntityFramework.Mappers;
using Duende.IdentityServer.EntityFramework.Options;
using Duende.IdentityServer.EntityFramework.Stores;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Xunit;
using Xunit.Sdk;

namespace EntityFramework.Storage.IntegrationTests.Stores;
Expand All @@ -35,7 +30,7 @@ public async Task FindClientByIdAsync_WhenClientDoesNotExist_ExpectNull(DbContex
using var context = new ConfigurationDbContext(options);
var store = new ClientStore(context, FakeLogger<ClientStore>.Create(), new NoneCancellationTokenProvider());
var client = await store.FindClientByIdAsync(Guid.NewGuid().ToString());
client.Should().BeNull();
client.ShouldBeNull();
}

[Theory, MemberData(nameof(TestDatabaseProviders))]
Expand All @@ -60,7 +55,7 @@ public async Task FindClientByIdAsync_WhenClientExists_ExpectClientReturned(DbCo
client = await store.FindClientByIdAsync(testClient.ClientId);
}

client.Should().NotBeNull();
client.ShouldNotBeNull();
}

[Theory, MemberData(nameof(TestDatabaseProviders))]
Expand Down Expand Up @@ -94,7 +89,20 @@ public async Task FindClientByIdAsync_WhenClientExistsWithCollections_ExpectClie
client = await store.FindClientByIdAsync(testClient.ClientId);
}

client.Should().BeEquivalentTo(testClient);
client.ShouldSatisfyAllConditions(c =>
{
c.ClientId.ShouldBe(testClient.ClientId);
c.ClientName.ShouldBe(testClient.ClientName);
c.AllowedCorsOrigins.ShouldBe(testClient.AllowedCorsOrigins);
c.AllowedGrantTypes.ShouldBe(testClient.AllowedGrantTypes, true);
c.AllowedScopes.ShouldBe(testClient.AllowedScopes, true);
c.Claims.ShouldBe(testClient.Claims);
c.ClientSecrets.ShouldBe(testClient.ClientSecrets, true);
c.IdentityProviderRestrictions.ShouldBe(testClient.IdentityProviderRestrictions);
c.PostLogoutRedirectUris.ShouldBe(testClient.PostLogoutRedirectUris);
c.Properties.ShouldBe(testClient.Properties);
c.RedirectUris.ShouldBe(testClient.RedirectUris);
});
}

[Theory, MemberData(nameof(TestDatabaseProviders))]
Expand Down Expand Up @@ -148,7 +156,13 @@ public async Task FindClientByIdAsync_WhenClientsExistWithManyCollections_Expect
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method, suppressed because the task must have completed to enter this block
var client = task.Result;
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
client.Should().BeEquivalentTo(testClient);
client.ShouldSatisfyAllConditions(c =>
{
c.ClientId.ShouldBe(testClient.ClientId);
c.ClientName.ShouldBe(testClient.ClientName);
c.AllowedScopes.ShouldBe(testClient.AllowedScopes, true);
c.AllowedGrantTypes.ShouldBe(testClient.AllowedGrantTypes);
});
}
else
{
Expand Down
Loading

0 comments on commit 1274511

Please sign in to comment.