-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathClientDbContextTests.cs
More file actions
121 lines (95 loc) · 3.79 KB
/
Copy pathClientDbContextTests.cs
File metadata and controls
121 lines (95 loc) · 3.79 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright (c) 2024 HigginsSoft, Alexander Higgins - https://github.com/alexhiggins732/
Copyright (c) 2018, Brock Allen & Dominick Baier. All rights reserved.
Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
Source code and license this software can be found
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
using IdentityServer8.EntityFramework.DbContexts;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using IdentityServer8.EntityFramework.Entities;
using IdentityServer8.EntityFramework.Options;
using Xunit;
namespace IdentityServer8.EntityFramework.IntegrationTests.DbContexts;
public class ClientDbContextTests : IntegrationTest<ClientDbContextTests, ConfigurationDbContext, ConfigurationStoreOptions>
{
public ClientDbContextTests(DatabaseProviderFixture<ConfigurationDbContext> fixture) : base(fixture)
{
foreach (var options in TestDatabaseProviders)
{
using (var context = new ConfigurationDbContext(options, StoreOptions))
context.Database.EnsureCreated();
}
}
[Theory, MemberData(nameof(TestDatabaseProviders))]
public void CanAddAndDeleteClientScopes(DbContextOptions<ConfigurationDbContext> options)
{
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
db.Clients.Add(new Client
{
ClientId = "test-client-scopes",
ClientName = "Test Client"
});
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
// explicit include due to lack of EF Core lazy loading
var client = db.Clients.Include(x => x.AllowedScopes).First();
client.AllowedScopes.Add(new ClientScope
{
Scope = "test"
});
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
var client = db.Clients.Include(x => x.AllowedScopes).First();
var scope = client.AllowedScopes.First();
client.AllowedScopes.Remove(scope);
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
var client = db.Clients.Include(x => x.AllowedScopes).First();
Assert.Empty(client.AllowedScopes);
}
}
[Theory, MemberData(nameof(TestDatabaseProviders))]
public void CanAddAndDeleteClientRedirectUri(DbContextOptions<ConfigurationDbContext> options)
{
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
db.Clients.Add(new Client
{
ClientId = "test-client",
ClientName = "Test Client"
});
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
var client = db.Clients.Include(x => x.RedirectUris).First();
client.RedirectUris.Add(new ClientRedirectUri
{
RedirectUri = "https://redirect-uri-1"
});
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
var client = db.Clients.Include(x => x.RedirectUris).First();
var redirectUri = client.RedirectUris.First();
client.RedirectUris.Remove(redirectUri);
db.SaveChanges();
}
using (var db = new ConfigurationDbContext(options, StoreOptions))
{
var client = db.Clients.Include(x => x.RedirectUris).First();
Assert.Empty(client.RedirectUris);
}
}
}