Skip to content
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
10 changes: 5 additions & 5 deletions src/MongoFramework.AspNetCore.Identity/MongoIdentityClaims.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class MongoIdentityUserClaim<TKey> where TKey : IEquatable<TKey>
/// <summary>
/// Gets or sets the claim type for this claim.
/// </summary>
public virtual string? ClaimType { get; set; }
public virtual string ClaimType { get; set; }

/// <summary>
/// Gets or sets the claim value for this claim.
/// </summary>
public virtual string? ClaimValue { get; set; }
public virtual string ClaimValue { get; set; }

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

/// <summary>
/// Gets or sets the claim value for this claim.
/// </summary>
public virtual string? ClaimValue { get; set; }
public virtual string ClaimValue { get; set; }

/// <summary>
/// Constructs a new claim with the type and value.
Expand All @@ -83,7 +83,7 @@ public virtual Claim ToClaim()
/// Initializes by copying ClaimType and ClaimValue from the other claim.
/// </summary>
/// <param name="other">The claim to initialize from.</param>
public virtual void InitializeFromClaim(Claim? other)
public virtual void InitializeFromClaim(Claim other)
{
ClaimType = other?.Type;
ClaimValue = other?.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="AwesomeAssertions" Version="9.2.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using AwesomeAssertions;
using Xunit;

namespace MongoFramework.AspNetCore.Identity.Tests
Expand Down Expand Up @@ -32,9 +32,9 @@ public void RegistersContextWithNoParameters()
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
{
db.ShouldBeOfType<MongoIdentityDbContext>();
db.Connection.ShouldNotBeNull();
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.ShouldBe("identity-test");
db.Should().BeOfType<MongoIdentityDbContext>();
db.Connection.Should().NotBeNull();
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.Should().Be("identity-test");
}

}
Expand All @@ -54,9 +54,9 @@ public void RegistersConnectionWithValidConnectionString()
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
{
db.ShouldBeOfType<MongoIdentityDbContext>();
db.Connection.ShouldNotBeNull();
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.ShouldBe("identity-test");
db.Should().BeOfType<MongoIdentityDbContext>();
db.Connection.Should().NotBeNull();
db.Connection.GetDatabase().DatabaseNamespace.DatabaseName.Should().Be("identity-test");
}
}

Expand All @@ -76,7 +76,7 @@ public void RegistersConnectionWithListener()
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var db = scoped.ServiceProvider.GetRequiredService<MongoIdentityDbContext>())
{
db.Connection.DiagnosticListener.ShouldBeOfType<NoOpDiagnosticListener>();
db.Connection.DiagnosticListener.Should().BeOfType<NoOpDiagnosticListener>();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using AwesomeAssertions;
using Xunit;

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

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

}
Expand Down Expand Up @@ -94,8 +94,8 @@ public void RegistersLimitedTypedUserStoreWithMongoContext()
using (var scoped = provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var db = scoped.ServiceProvider.GetRequiredService<IUserStore<MongoIdentityUser>>())
{
db.GetType().GenericTypeArguments.Length.ShouldBe(4);
db.ShouldBeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoDbContext, string>>();
db.GetType().GenericTypeArguments.Length.Should().Be(4);
db.Should().BeOfType<MongoUserStore<MongoIdentityUser, MongoIdentityRole, MongoDbContext, string>>();
}

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

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


Should.Throw<InvalidOperationException>(() =>
Action action = () =>
{
services
.AddIdentity<MongoIdentityUser, IdentityRole>()
.AddMongoFrameworkStores<MongoIdentityDbContext>();
});
};
action.Should().Throw<InvalidOperationException>();
}

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


Should.Throw<InvalidOperationException>(() =>
Action action = () =>
{
services
.AddIdentity<IdentityUser, MongoIdentityRole>()
.AddMongoFrameworkStores<MongoIdentityDbContext>();
});
};
action.Should().Throw<InvalidOperationException>();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoEntityFramework.AspNetCore.Identity.Tests.TestClasses;
using Shouldly;
using AwesomeAssertions;
using Xunit;

namespace MongoEntityFramework.AspNetCore.Identity.Tests
Expand Down Expand Up @@ -49,8 +49,8 @@ public void ContextWithRolesLoadsRoles()

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

store.Context.ShouldBeOfType<MongoIdentityDbContext>();
store.Roles.Count().ShouldBe(3);
store.Context.Should().BeOfType<MongoIdentityDbContext>();
store.Roles.Count().Should().Be(3);
}

[Fact]
Expand All @@ -60,8 +60,8 @@ public void ContextWithUsersLoadsUsers()

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

store.Context.ShouldBeOfType<MongoIdentityUserContext>();
store.Users.Count().ShouldBe(1);
store.Context.Should().BeOfType<MongoIdentityUserContext>();
store.Users.Count().Should().Be(1);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity;
using Shouldly;
using AwesomeAssertions;
using Xunit;

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

role.Claims.ShouldNotBeNull();
role.Claims.Count.ShouldBe(0);
role.Claims.Should().NotBeNull();
role.Claims.Count.Should().Be(0);
}

[Fact]
public void ConstructorSucceedsWithValidUserName()
{
var role = new MongoIdentityRole("role-name");

role.Name.ShouldBe("role-name");
role.NormalizedName.ShouldBe("ROLE-NAME");
role.ToString().ShouldBe("role-name");
role.Name.Should().Be("role-name");
role.NormalizedName.Should().Be("ROLE-NAME");
role.ToString().Should().Be("role-name");
}

[Fact]
public void ConstructorThrowsExceptionWithNullUserName()
{
Should.Throw<ArgumentNullException>(() =>
Action action = () =>
{
_ = new MongoIdentityRole(null);
});
};
action.Should().Throw<ArgumentNullException>();
}

[Fact]
public void KeyTypeIsUsedInCollectionsWithInteger()
{
var role = new MongoIdentityRole<int>();

role.Claims.ShouldBeOfType<List<IdentityRoleClaim<int>>>();
role.Claims.Should().BeOfType<List<IdentityRoleClaim<int>>>();
}

[Fact]
public void KeyTypeIsUsedInCollectionsWithGuid()
{
var role = new MongoIdentityRole<Guid>();

role.Claims.ShouldBeOfType<List<IdentityRoleClaim<Guid>>>();
role.Claims.Should().BeOfType<List<IdentityRoleClaim<Guid>>>();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity;
using Shouldly;
using AwesomeAssertions;
using Xunit;

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

user.Claims.ShouldNotBeNull();
user.Roles.ShouldNotBeNull();
user.Tokens.ShouldNotBeNull();
user.Logins.ShouldNotBeNull();
user.Claims.Should().NotBeNull();
user.Roles.Should().NotBeNull();
user.Tokens.Should().NotBeNull();
user.Logins.Should().NotBeNull();

user.Claims.Count.ShouldBe(0);
user.Roles.Count.ShouldBe(0);
user.Tokens.Count.ShouldBe(0);
user.Logins.Count.ShouldBe(0);
user.Claims.Count.Should().Be(0);
user.Roles.Count.Should().Be(0);
user.Tokens.Count.Should().Be(0);
user.Logins.Count.Should().Be(0);
}

[Fact]
public void ConstructorSucceedsWithValidUserName()
{
var user = new MongoIdentityUser("username");

user.UserName.ShouldBe("username");
user.NormalizedUserName.ShouldBe("USERNAME");
user.UserName.Should().Be("username");
user.NormalizedUserName.Should().Be("USERNAME");
}

[Fact]
public void ConstructorThrowsExceptionWithNullUserName()
{
Should.Throw<ArgumentNullException>(() =>
Action action = () =>
{
_ = new MongoIdentityUser(null);
});
};
action.Should().Throw<ArgumentNullException>();
}

[Fact]
public void KeyTypeIsUsedInCollectionsWithInteger()
{
var user = new MongoIdentityUser<int>();

user.Claims.ShouldBeOfType<List<IdentityUserClaim<int>>>();
user.Tokens.ShouldBeOfType<List<IdentityUserToken<int>>>();
user.Logins.ShouldBeOfType<List<IdentityUserLogin<int>>>();
user.Claims.Should().BeOfType<List<IdentityUserClaim<int>>>();
user.Tokens.Should().BeOfType<List<IdentityUserToken<int>>>();
user.Logins.Should().BeOfType<List<IdentityUserLogin<int>>>();
}

[Fact]
public void KeyTypeIsUsedInCollectionsWithGuid()
{
var user = new MongoIdentityUser<Guid>();

user.Claims.ShouldBeOfType<List<IdentityUserClaim<Guid>>>();
user.Tokens.ShouldBeOfType<List<IdentityUserToken<Guid>>>();
user.Logins.ShouldBeOfType<List<IdentityUserLogin<Guid>>>();
user.Claims.Should().BeOfType<List<IdentityUserClaim<Guid>>>();
user.Tokens.Should().BeOfType<List<IdentityUserToken<Guid>>>();
user.Logins.Should().BeOfType<List<IdentityUserLogin<Guid>>>();
}


Expand Down
Loading
Loading