Skip to content

Commit

Permalink
Implement missing query filtering in NGitLab.Mock for merge requests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur authored Jul 7, 2021
1 parent acd327f commit 7e1cb7b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
26 changes: 26 additions & 0 deletions NGitLab.Mock.Tests/MergeRequestsMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,31 @@ public void Test_merge_requests_assigned_to_me_can_be_listed()
Assert.AreEqual(1, mergeRequests.Length, "Merge requests count is invalid");
Assert.AreEqual("Merge request 2", mergeRequests[0].Title, "Merge request found is invalid");
}

[Test]
public void Test_merge_requests_approvable_by_me_can_be_listed()
{
using var gitLabServer = new GitLabServer();
var user1 = new User("user1");
gitLabServer.Users.Add(user1);
var user2 = new User("user2");
gitLabServer.Users.Add(user2);
var group = new Group("TestGroup");
gitLabServer.Groups.Add(group);
var project = new Project("Test") { Visibility = VisibilityLevel.Internal };
group.Projects.Add(project);
var mergeRequest1 = new MergeRequest { Author = new UserRef(user1), Title = "Merge request 1", SourceProject = project };
mergeRequest1.Approvers.Add(new UserRef(user2));
project.MergeRequests.Add(mergeRequest1);
var mergeRequest2 = new MergeRequest { Author = new UserRef(user2), Title = "Merge request 2", SourceProject = project };
mergeRequest2.Approvers.Add(new UserRef(user1));
project.MergeRequests.Add(mergeRequest2);

var client = gitLabServer.CreateClient(user1);
var mergeRequests = client.MergeRequests.Get(new MergeRequestQuery { ApproverIds = new[] { user1.Id } }).ToArray();

Assert.AreEqual(1, mergeRequests.Length, "Merge requests count is invalid");
Assert.AreEqual("Merge request 2", mergeRequests[0].Title, "Merge request found is invalid");
}
}
}
10 changes: 7 additions & 3 deletions NGitLab.Mock/Clients/MergeRequestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ public void Delete(int mergeRequestIid)
{
if (query.ApproverIds != null)
{
throw new NotImplementedException();
var approverIds = query.ApproverIds;
mergeRequests = mergeRequests.Where(mr => mr.Approvers.Any(x => approverIds.Contains(x.Id)));
}

if (query.AssigneeId != null)
Expand All @@ -391,9 +392,12 @@ public void Delete(int mergeRequestIid)
mergeRequests = mergeRequests.Where(mr => mr.CreatedAt <= query.CreatedBefore.Value);
}

if (query.Labels != null)
if (!string.IsNullOrEmpty(query.Labels))
{
throw new NotImplementedException();
foreach (var label in query.Labels.Split(','))
{
mergeRequests = mergeRequests.Where(mr => mr.Labels.Contains(label, StringComparer.Ordinal));
}
}

if (query.Milestone != null)
Expand Down

0 comments on commit 7e1cb7b

Please sign in to comment.