-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into support-sub-modules-in-mocks
- Loading branch information
Showing
63 changed files
with
1,183 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using NGitLab.Models; | ||
using NUnit.Framework; | ||
|
||
namespace NGitLab.Mock.Tests | ||
{ | ||
public sealed class BotUserTests | ||
{ | ||
[Test] | ||
public void Test_project_bot_user() | ||
{ | ||
using var server = new GitLabServer(); | ||
var group = new Group("test"); | ||
var project = new Project("test-project"); | ||
server.Groups.Add(group); | ||
group.Projects.Add(project); | ||
|
||
var bot = project.CreateBotUser("token_name", AccessLevel.Maintainer); | ||
|
||
Assert.That(bot.Bot, Is.True); | ||
Assert.That(bot.Name, Is.EqualTo("token_name")); | ||
var permissions = project.GetEffectivePermissions(); | ||
var botPermission = permissions.GetEffectivePermission(bot); | ||
Assert.That(botPermission.AccessLevel, Is.EqualTo(AccessLevel.Maintainer)); | ||
} | ||
|
||
[Test] | ||
public void Test_group_bot_user() | ||
{ | ||
using var server = new GitLabServer(); | ||
var group = new Group("test"); | ||
server.Groups.Add(group); | ||
|
||
var bot = group.CreateBotUser(AccessLevel.Maintainer); | ||
|
||
Assert.That(bot.Bot, Is.True); | ||
var permissions = group.GetEffectivePermissions(); | ||
var botPermission = permissions.GetEffectivePermission(bot); | ||
Assert.That(botPermission.AccessLevel, Is.EqualTo(AccessLevel.Maintainer)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Linq; | ||
using NGitLab.Mock.Config; | ||
using NUnit.Framework; | ||
|
||
namespace NGitLab.Mock.Tests | ||
{ | ||
public class MembersMockTests | ||
{ | ||
[Test] | ||
public void Test_members_group_all_direct([Values] bool isDefault) | ||
{ | ||
using var server = new GitLabConfig() | ||
.WithUser("user1", isDefault: true) | ||
.WithUser("user2") | ||
.WithGroup("G1", 1, addDefaultUserAsMaintainer: true) | ||
.WithGroup("G2", 2, @namespace: "G1", configure: g => g.WithUserPermission("user2", Models.AccessLevel.Maintainer)) | ||
.BuildServer(); | ||
|
||
var client = server.CreateClient("user1"); | ||
var members = isDefault | ||
? client.Members.OfGroup("2") | ||
: client.Members.OfGroup("2", includeInheritedMembers: false); | ||
|
||
Assert.AreEqual(1, members.Count(), "Membership found are invalid"); | ||
} | ||
|
||
[Test] | ||
public void Test_members_group_all_inherited() | ||
{ | ||
using var server = new GitLabConfig() | ||
.WithUser("user1", isDefault: true) | ||
.WithUser("user2") | ||
.WithProject("Test") | ||
.WithGroup("G1", 1, configure: g => g.WithUserPermission("user1", Models.AccessLevel.Maintainer)) | ||
.WithGroup("G2", 2, @namespace: "G1", configure: g => g.WithUserPermission("user2", Models.AccessLevel.Maintainer)) | ||
.BuildServer(); | ||
|
||
var client = server.CreateClient("user1"); | ||
var members = client.Members.OfGroup("2", includeInheritedMembers: true); | ||
|
||
Assert.AreEqual(2, members.Count(), "Membership found are invalid"); | ||
} | ||
|
||
[Test] | ||
public void Test_members_project_all_direct([Values] bool isDefault) | ||
{ | ||
using var server = new GitLabConfig() | ||
.WithUser("user1", isDefault: true) | ||
.WithUser("user2") | ||
.WithUser("user3") | ||
.WithGroup("G1", 1, addDefaultUserAsMaintainer: true) | ||
.WithGroup("G2", 2, @namespace: "G1", configure: g => g.WithUserPermission("user2", Models.AccessLevel.Maintainer)) | ||
.WithProject("Project", @namespace: "G1", configure: g => | ||
g.WithUserPermission("user3", Models.AccessLevel.Maintainer) | ||
.WithGroupPermission("G2", Models.AccessLevel.Developer)) | ||
.BuildServer(); | ||
|
||
var client = server.CreateClient("user1"); | ||
var members = isDefault | ||
? client.Members.OfProject("1") | ||
: client.Members.OfProject("1", includeInheritedMembers: false); | ||
|
||
Assert.AreEqual(1, members.Count(), "Membership found are invalid"); | ||
} | ||
|
||
[Test] | ||
public void Test_members_project_all_inherited() | ||
{ | ||
using var server = new GitLabConfig() | ||
.WithUser("user1", isDefault: true) | ||
.WithUser("user2") | ||
.WithUser("user3") | ||
.WithGroup("G1", addDefaultUserAsMaintainer: true) | ||
.WithGroup("G2", @namespace: "G1", configure: g => g.WithUserPermission("user2", Models.AccessLevel.Maintainer)) | ||
.WithProject("Project", 1, @namespace: "G1", configure: g => | ||
g.WithUserPermission("user3", Models.AccessLevel.Maintainer) | ||
.WithGroupPermission("G1/G2", Models.AccessLevel.Developer)) | ||
.BuildServer(); | ||
|
||
var client = server.CreateClient("user1"); | ||
var members = client.Members.OfProject("1", includeInheritedMembers: true); | ||
|
||
Assert.AreEqual(3, members.Count(), "Membership found are invalid"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.