Add support for documents with and Id of type ObjectId.
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.7" />
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" />
|
||||
@@ -21,7 +21,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.6" />
|
||||
<PackageReference Include="Moq" Version="4.8.1" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
|
||||
private IQueryable<TUser> GetQueryable()
|
||||
{
|
||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
||||
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
|
||||
private IQueryable<TUser> GetQueryable()
|
||||
{
|
||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
||||
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using MongoDbGenericRepository;
|
||||
using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
public class ObjectIdUser : MongoIdentityUser<ObjectId>
|
||||
{
|
||||
public ObjectIdUser() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectIdRole : MongoIdentityRole<ObjectId>
|
||||
{
|
||||
public ObjectIdRole() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStoreObjectIdTest : MongoDbStoreTestBase<ObjectIdUser, ObjectIdRole, ObjectId>
|
||||
{
|
||||
public UserStoreObjectIdTest(MongoDatabaseFixture<ObjectIdUser, ObjectIdRole, ObjectId> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
||||
public class ApplicationUserStore : MongoUserStore<ObjectIdUser, ObjectIdRole, IMongoDbContext, ObjectId>
|
||||
{
|
||||
public ApplicationUserStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||
}
|
||||
|
||||
public class ApplicationRoleStore : MongoRoleStore<ObjectIdRole, IMongoDbContext, ObjectId>
|
||||
{
|
||||
public ApplicationRoleStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||
}
|
||||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddSingleton<IUserStore<ObjectIdUser>>(new ApplicationUserStore(Container.MongoRepository.Context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddSingleton<IRoleStore<ObjectIdRole>>(new ApplicationRoleStore(Container.MongoRepository.Context));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,7 +31,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||
if (userIds.Any())
|
||||
{
|
||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,12 +57,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||
if (userIds.Any())
|
||||
{
|
||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
}
|
||||
var roleIds = RolesToDelete.ToList().Select(e => e.Id);
|
||||
if (roleIds.Any())
|
||||
{
|
||||
Context.GetCollection<TRole>().DeleteMany(e => roleIds.Contains(e.Id));
|
||||
Context.GetCollection<TRole, TKey>().DeleteMany(e => roleIds.Contains(e.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user