-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMongoIdentityContextsTests.cs
More file actions
68 lines (53 loc) · 2.45 KB
/
MongoIdentityContextsTests.cs
File metadata and controls
68 lines (53 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoEntityFramework.AspNetCore.Identity.Tests.TestClasses;
using AwesomeAssertions;
using Xunit;
namespace MongoEntityFramework.AspNetCore.Identity.Tests
{
public static class TestIds
{
public static readonly string RoleId1 = ObjectId.GenerateNewId().ToString();
public static readonly string RoleId2 = ObjectId.GenerateNewId().ToString();
public static readonly string RoleId3 = ObjectId.GenerateNewId().ToString();
public static readonly string UserId1 = ObjectId.GenerateNewId().ToString();
public static readonly string UserId2 = ObjectId.GenerateNewId().ToString();
public static readonly string UserId3 = ObjectId.GenerateNewId().ToString();
}
public class MongoIdentityContextsTests : TestBase, IAsyncLifetime
{
public MongoIdentityContextsTests() : base("MongoIdentityContexts") { }
public async Task InitializeAsync()
{
var context = new MongoIdentityDbContext(GetConnection());
var store = new MongoUserStore<MongoIdentityUser>(context);
context.Roles.Add(new MongoIdentityRole { Id = TestIds.RoleId1, Name = "Role 1" });
context.Roles.Add(new MongoIdentityRole { Id = TestIds.RoleId2, Name = "Role 2" });
context.Roles.Add(new MongoIdentityRole { Id = TestIds.RoleId3, Name = "Role 3" });
await context.SaveChangesAsync();
var user = TestUser.First;
user.Roles.Add(TestIds.RoleId1);
user.Roles.Add(TestIds.RoleId2);
await store.CreateAsync(user);
}
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
public void ContextWithRolesLoadsRoles()
{
var context = new MongoIdentityDbContext(GetConnection());
var store = new MongoRoleStore<MongoIdentityRole, MongoIdentityDbContext>(context);
store.Context.Should().BeOfType<MongoIdentityDbContext>();
store.Roles.Count().Should().Be(3);
}
[Fact]
public void ContextWithUsersLoadsUsers()
{
var context = new MongoIdentityUserContext(GetConnection());
var store = new MongoUserOnlyStore<MongoIdentityUser, MongoIdentityUserContext>(context);
store.Context.Should().BeOfType<MongoIdentityUserContext>();
store.Users.Count().Should().Be(1);
}
}
}