Skip to content

Commit 24ee53b

Browse files
chore: migrate test assertions from Shouldly to AwesomeAssertions v9.2.1 (#2)
* Initial plan * Migrate from Shouldly to AwesomeAssertions v9.2.1 Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> * chore: fix nullable errors * Fix exception tests to use synchronous Throw pattern Changed async exception tests to use synchronous pattern as requested: - Removed async keyword from test method signatures - Changed await ThrowAsync pattern to synchronous act.Should().Throw() - Replaced await calls with direct object instantiation where needed - Fixed duplicate variable names in tests with multiple assertions Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> * Add return Task.CompletedTask to exception test methods Fixed compilation errors where Task methods were not returning a value. All exception test methods now properly return Task.CompletedTask. Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> * Convert exception tests to use async ThrowAsync pattern Changed all exception tests to use async lambdas with await and ThrowAsync: - Method signatures changed from 'public Task' to 'public async Task' - Lambdas changed from synchronous to async with await - Changed .Throw() to .ThrowAsync() - Added await before assertions - Removed return Task.CompletedTask statements Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> * fix warning on configureawait --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> Co-authored-by: John Campion Jr <john@brightshore.com>
1 parent 8024f13 commit 24ee53b

31 files changed

+299
-270
lines changed

src/MongoFramework.AspNetCore.Identity/MongoIdentityClaims.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class MongoIdentityUserClaim<TKey> where TKey : IEquatable<TKey>
2121
/// <summary>
2222
/// Gets or sets the claim type for this claim.
2323
/// </summary>
24-
public virtual string? ClaimType { get; set; }
24+
public virtual string ClaimType { get; set; }
2525

2626
/// <summary>
2727
/// Gets or sets the claim value for this claim.
2828
/// </summary>
29-
public virtual string? ClaimValue { get; set; }
29+
public virtual string ClaimValue { get; set; }
3030

3131
/// <summary>
3232
/// Converts the entity into a Claim instance.
@@ -63,12 +63,12 @@ public class MongoIdentityRoleClaim<TKey> where TKey : IEquatable<TKey>
6363
/// <summary>
6464
/// Gets or sets the claim type for this claim.
6565
/// </summary>
66-
public virtual string? ClaimType { get; set; }
66+
public virtual string ClaimType { get; set; }
6767

6868
/// <summary>
6969
/// Gets or sets the claim value for this claim.
7070
/// </summary>
71-
public virtual string? ClaimValue { get; set; }
71+
public virtual string ClaimValue { get; set; }
7272

7373
/// <summary>
7474
/// Constructs a new claim with the type and value.
@@ -83,7 +83,7 @@ public virtual Claim ToClaim()
8383
/// Initializes by copying ClaimType and ClaimValue from the other claim.
8484
/// </summary>
8585
/// <param name="other">The claim to initialize from.</param>
86-
public virtual void InitializeFromClaim(Claim? other)
86+
public virtual void InitializeFromClaim(Claim other)
8787
{
8888
ClaimType = other?.Type;
8989
ClaimValue = other?.Value;

tests/MongoFramework.AspNetCore.Identity.Tests/MongoEntityFramework.AspNetCore.Identity.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
19-
<PackageReference Include="Shouldly" Version="4.3.0" />
19+
<PackageReference Include="AwesomeAssertions" Version="9.2.1" />
2020
<PackageReference Include="xunit" Version="2.9.3" />
2121
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2222
<PrivateAssets>all</PrivateAssets>

tests/MongoFramework.AspNetCore.Identity.Tests/MongoFrameworkServiceCollectionExtensionsTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Microsoft.AspNetCore.Identity;
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
7-
using Shouldly;
7+
using AwesomeAssertions;
88
using Xunit;
99

1010
namespace MongoFramework.AspNetCore.Identity.Tests
@@ -32,9 +32,9 @@ public void RegistersContextWithNoParameters()
3232
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
3333
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
3434
{
35-
db.ShouldBeOfType<MongoIdentityDbContext>();
36-
db.Connection.ShouldNotBeNull();
37-
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.ShouldBe("identity-test");
35+
db.Should().BeOfType<MongoIdentityDbContext>();
36+
db.Connection.Should().NotBeNull();
37+
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.Should().Be("identity-test");
3838
}
3939

4040
}
@@ -54,9 +54,9 @@ public void RegistersConnectionWithValidConnectionString()
5454
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
5555
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
5656
{
57-
db.ShouldBeOfType<MongoIdentityDbContext>();
58-
db.Connection.ShouldNotBeNull();
59-
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.ShouldBe("identity-test");
57+
db.Should().BeOfType<MongoIdentityDbContext>();
58+
db.Connection.Should().NotBeNull();
59+
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.Should().Be("identity-test");
6060
}
6161
}
6262

@@ -76,7 +76,7 @@ public void RegistersConnectionWithListener()
7676
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
7777
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
7878
{
79-
db.Connection.DiagnosticListener.ShouldBeOfType<NoOpDiagnosticListener>();
79+
db.Connection.DiagnosticListener.Should().BeOfType<NoOpDiagnosticListener>();
8080
}
8181
}
8282
}

tests/MongoFramework.AspNetCore.Identity.Tests/MongoIdentityBuilderExtensionsTests.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Microsoft.AspNetCore.Identity;
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
7-
using Shouldly;
7+
using AwesomeAssertions;
88
using Xunit;
99

1010
namespace MongoFramework.AspNetCore.Identity.Tests
@@ -36,8 +36,8 @@ public void RegistersFullyTypedUserStoreWithMongoIdentityContext()
3636
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
3737
using (var db = scoped.ServiceProvider.GetRequiredService<IUserStore<MongoIdentityUser>>())
3838
{
39-
db.GetType().GenericTypeArguments.Length.ShouldBe(9);
40-
db.ShouldBeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoIdentityDbContext, string, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>, IdentityUserToken<string>, IdentityRoleClaim<string>>>();
39+
db.GetType().GenericTypeArguments.Length.Should().Be(9);
40+
db.Should().BeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoIdentityDbContext, string, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>, IdentityUserToken<string>, IdentityRoleClaim<string>>>();
4141
}
4242

4343
}
@@ -64,8 +64,8 @@ public void RegistersFullyTypedUserOnlyStoreWithMongoIdentityContext()
6464
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
6565
using (var db = scoped.ServiceProvider.GetRequiredService<IUserStore<MongoIdentityUser>>())
6666
{
67-
db.GetType().GenericTypeArguments.Length.ShouldBe(6);
68-
db.ShouldBeOfType<MongoUserOnlyStore<MongoIdentityUser, MongoIdentityDbContext, string, IdentityUserClaim<string>, IdentityUserLogin<string>, IdentityUserToken<string>>>();
67+
db.GetType().GenericTypeArguments.Length.Should().Be(6);
68+
db.Should().BeOfType<MongoUserOnlyStore<MongoIdentityUser, MongoIdentityDbContext, string, IdentityUserClaim<string>, IdentityUserLogin<string>, IdentityUserToken<string>>>();
6969
}
7070

7171
}
@@ -94,8 +94,8 @@ public void RegistersLimitedTypedUserStoreWithMongoContext()
9494
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
9595
using (var db = scoped.ServiceProvider.GetRequiredService<IUserStore<MongoIdentityUser>>())
9696
{
97-
db.GetType().GenericTypeArguments.Length.ShouldBe(4);
98-
db.ShouldBeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoDbContext, string>>();
97+
db.GetType().GenericTypeArguments.Length.Should().Be(4);
98+
db.Should().BeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoDbContext, string>>();
9999
}
100100

101101
}
@@ -122,8 +122,8 @@ public void RegistersLimitedTypedUserOnlyStoreWithMongoContext()
122122
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
123123
using (var db = scoped.ServiceProvider.GetRequiredService<IUserStore<MongoIdentityUser>>())
124124
{
125-
db.GetType().GenericTypeArguments.Length.ShouldBe(3);
126-
db.ShouldBeOfType<MongoUserOnlyStore<MongoIdentityUser, MongoDbContext, string>>();
125+
db.GetType().GenericTypeArguments.Length.Should().Be(3);
126+
db.Should().BeOfType<MongoUserOnlyStore<MongoIdentityUser, MongoDbContext, string>>();
127127
}
128128

129129
}
@@ -141,12 +141,13 @@ public void ExtensionThrowsExceptionWithoutMongoIdentityRole()
141141
services.AddTransient<MongoIdentityDbContext, MongoIdentityDbContext>();
142142

143143

144-
Should.Throw<InvalidOperationException>(() =>
144+
Action action = () =>
145145
{
146146
services
147147
.AddIdentity<MongoIdentityUser, IdentityRole>()
148148
.AddMongoFrameworkStores<MongoIdentityDbContext>();
149-
});
149+
};
150+
action.Should().Throw<InvalidOperationException>();
150151
}
151152

152153
[Fact]
@@ -162,12 +163,13 @@ public void ExtensionThrowsExceptionWithoutMongoIdentityUser()
162163
services.AddTransient<MongoIdentityDbContext, MongoIdentityDbContext>();
163164

164165

165-
Should.Throw<InvalidOperationException>(() =>
166+
Action action = () =>
166167
{
167168
services
168169
.AddIdentity<IdentityUser, MongoIdentityRole>()
169170
.AddMongoFrameworkStores<MongoIdentityDbContext>();
170-
});
171+
};
172+
action.Should().Throw<InvalidOperationException>();
171173
}
172174

173175

tests/MongoFramework.AspNetCore.Identity.Tests/MongoIdentityContextsTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
44
using MongoDB.Bson;
55
using MongoEntityFramework.AspNetCore.Identity.Tests.TestClasses;
6-
using Shouldly;
6+
using AwesomeAssertions;
77
using Xunit;
88

99
namespace MongoEntityFramework.AspNetCore.Identity.Tests
@@ -49,8 +49,8 @@ public void ContextWithRolesLoadsRoles()
4949

5050
var store = new MongoRoleStore<MongoIdentityRole, MongoIdentityDbContext>(context);
5151

52-
store.Context.ShouldBeOfType<MongoIdentityDbContext>();
53-
store.Roles.Count().ShouldBe(3);
52+
store.Context.Should().BeOfType<MongoIdentityDbContext>();
53+
store.Roles.Count().Should().Be(3);
5454
}
5555

5656
[Fact]
@@ -60,8 +60,8 @@ public void ContextWithUsersLoadsUsers()
6060

6161
var store = new MongoUserOnlyStore<MongoIdentityUser, MongoIdentityUserContext>(context);
6262

63-
store.Context.ShouldBeOfType<MongoIdentityUserContext>();
64-
store.Users.Count().ShouldBe(1);
63+
store.Context.Should().BeOfType<MongoIdentityUserContext>();
64+
store.Users.Count().Should().Be(1);
6565
}
6666

6767
}

tests/MongoFramework.AspNetCore.Identity.Tests/MongoIdentityRoleTests.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Microsoft.AspNetCore.Identity;
4-
using Shouldly;
4+
using AwesomeAssertions;
55
using Xunit;
66

77
namespace MongoEntityFramework.AspNetCore.Identity.Tests
@@ -13,43 +13,44 @@ public void ConstructorCreatesEmptyLists()
1313
{
1414
var role = new MongoIdentityRole();
1515

16-
role.Claims.ShouldNotBeNull();
17-
role.Claims.Count.ShouldBe(0);
16+
role.Claims.Should().NotBeNull();
17+
role.Claims.Count.Should().Be(0);
1818
}
1919

2020
[Fact]
2121
public void ConstructorSucceedsWithValidUserName()
2222
{
2323
var role = new MongoIdentityRole("role-name");
2424

25-
role.Name.ShouldBe("role-name");
26-
role.NormalizedName.ShouldBe("ROLE-NAME");
27-
role.ToString().ShouldBe("role-name");
25+
role.Name.Should().Be("role-name");
26+
role.NormalizedName.Should().Be("ROLE-NAME");
27+
role.ToString().Should().Be("role-name");
2828
}
2929

3030
[Fact]
3131
public void ConstructorThrowsExceptionWithNullUserName()
3232
{
33-
Should.Throw<ArgumentNullException>(() =>
33+
Action action = () =>
3434
{
3535
_ = new MongoIdentityRole(null);
36-
});
36+
};
37+
action.Should().Throw<ArgumentNullException>();
3738
}
3839

3940
[Fact]
4041
public void KeyTypeIsUsedInCollectionsWithInteger()
4142
{
4243
var role = new MongoIdentityRole<int>();
4344

44-
role.Claims.ShouldBeOfType<List<IdentityRoleClaim<int>>>();
45+
role.Claims.Should().BeOfType<List<IdentityRoleClaim<int>>>();
4546
}
4647

4748
[Fact]
4849
public void KeyTypeIsUsedInCollectionsWithGuid()
4950
{
5051
var role = new MongoIdentityRole<Guid>();
5152

52-
role.Claims.ShouldBeOfType<List<IdentityRoleClaim<Guid>>>();
53+
role.Claims.Should().BeOfType<List<IdentityRoleClaim<Guid>>>();
5354
}
5455

5556
}

tests/MongoFramework.AspNetCore.Identity.Tests/MongoIdentityUserTests.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Microsoft.AspNetCore.Identity;
4-
using Shouldly;
4+
using AwesomeAssertions;
55
using Xunit;
66

77
namespace MongoEntityFramework.AspNetCore.Identity.Tests
@@ -13,53 +13,54 @@ public void ConstructorCreatesEmptyLists()
1313
{
1414
var user = new MongoIdentityUser();
1515

16-
user.Claims.ShouldNotBeNull();
17-
user.Roles.ShouldNotBeNull();
18-
user.Tokens.ShouldNotBeNull();
19-
user.Logins.ShouldNotBeNull();
16+
user.Claims.Should().NotBeNull();
17+
user.Roles.Should().NotBeNull();
18+
user.Tokens.Should().NotBeNull();
19+
user.Logins.Should().NotBeNull();
2020

21-
user.Claims.Count.ShouldBe(0);
22-
user.Roles.Count.ShouldBe(0);
23-
user.Tokens.Count.ShouldBe(0);
24-
user.Logins.Count.ShouldBe(0);
21+
user.Claims.Count.Should().Be(0);
22+
user.Roles.Count.Should().Be(0);
23+
user.Tokens.Count.Should().Be(0);
24+
user.Logins.Count.Should().Be(0);
2525
}
2626

2727
[Fact]
2828
public void ConstructorSucceedsWithValidUserName()
2929
{
3030
var user = new MongoIdentityUser("username");
3131

32-
user.UserName.ShouldBe("username");
33-
user.NormalizedUserName.ShouldBe("USERNAME");
32+
user.UserName.Should().Be("username");
33+
user.NormalizedUserName.Should().Be("USERNAME");
3434
}
3535

3636
[Fact]
3737
public void ConstructorThrowsExceptionWithNullUserName()
3838
{
39-
Should.Throw<ArgumentNullException>(() =>
39+
Action action = () =>
4040
{
4141
_ = new MongoIdentityUser(null);
42-
});
42+
};
43+
action.Should().Throw<ArgumentNullException>();
4344
}
4445

4546
[Fact]
4647
public void KeyTypeIsUsedInCollectionsWithInteger()
4748
{
4849
var user = new MongoIdentityUser<int>();
4950

50-
user.Claims.ShouldBeOfType<List<IdentityUserClaim<int>>>();
51-
user.Tokens.ShouldBeOfType<List<IdentityUserToken<int>>>();
52-
user.Logins.ShouldBeOfType<List<IdentityUserLogin<int>>>();
51+
user.Claims.Should().BeOfType<List<IdentityUserClaim<int>>>();
52+
user.Tokens.Should().BeOfType<List<IdentityUserToken<int>>>();
53+
user.Logins.Should().BeOfType<List<IdentityUserLogin<int>>>();
5354
}
5455

5556
[Fact]
5657
public void KeyTypeIsUsedInCollectionsWithGuid()
5758
{
5859
var user = new MongoIdentityUser<Guid>();
5960

60-
user.Claims.ShouldBeOfType<List<IdentityUserClaim<Guid>>>();
61-
user.Tokens.ShouldBeOfType<List<IdentityUserToken<Guid>>>();
62-
user.Logins.ShouldBeOfType<List<IdentityUserLogin<Guid>>>();
61+
user.Claims.Should().BeOfType<List<IdentityUserClaim<Guid>>>();
62+
user.Tokens.Should().BeOfType<List<IdentityUserToken<Guid>>>();
63+
user.Logins.Should().BeOfType<List<IdentityUserLogin<Guid>>>();
6364
}
6465

6566

0 commit comments

Comments
 (0)