-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathKcOrganizationMocks.cs
More file actions
50 lines (46 loc) · 1.83 KB
/
KcOrganizationMocks.cs
File metadata and controls
50 lines (46 loc) · 1.83 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
using Bogus;
using NETCore.Keycloak.Client.Models.Organizations;
namespace NETCore.Keycloak.Client.Tests.MockData;
/// <summary>
/// Provides mock data generation for Keycloak organization objects used in testing scenarios.
/// This class leverages the Faker library to generate realistic data for testing Keycloak organization configurations.
/// </summary>
public static class KcOrganizationMocks
{
/// <summary>
/// Generates a mock <see cref="KcOrganization"/> instance with randomized test data.
/// </summary>
/// <param name="faker">The <see cref="Faker"/> instance used to generate randomized data.</param>
/// <returns>A new <see cref="KcOrganization"/> instance populated with test data.</returns>
/// <exception cref="AssertFailedException">
/// Thrown if the provided <see cref="Faker"/> instance is null.
/// </exception>
public static KcOrganization Generate(Faker faker)
{
// Ensure the Faker instance is not null before generating data.
Assert.IsNotNull(faker);
// Generate a unique name for the organization.
var orgName = Guid.NewGuid().ToString().Replace("-", string.Empty, StringComparison.Ordinal);
// Create an organization with randomized details.
return new KcOrganization
{
Name = orgName,
Alias = orgName,
Enabled = true,
Description = faker.Lorem.Sentence(),
RedirectUrl = faker.Internet.Url(),
Attributes = new Dictionary<string, List<string>>
{
{ "test_attr", ["value1"] }
},
Domains =
[
new KcOrganizationDomain
{
Name = $"{orgName}.{faker.Internet.DomainSuffix()}",
Verified = false
}
]
};
}
}