Skip to content

Commit

Permalink
Fix an error when creating a Mock.Project from a GitLabProject wi…
Browse files Browse the repository at this point in the history
…th a null `Path`
  • Loading branch information
belcher-rok committed Apr 9, 2024
1 parent b91dea7 commit d636305
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions NGitLab.Mock.Tests/ProjectsMockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ namespace NGitLab.Mock.Tests;

public class ProjectsMockTests
{
[Test]
public void WithProjectHelper_WhenPathNotSpecified_ItAutogeneratesPathFromName()
{
// Arrange
var config = new GitLabConfig()
.WithUser("Foo", isDefault: true);

// Act
using var server = config
.WithProject("TEST", configure: p => p.@Namespace = "Foo")
.BuildServer();

// Assert
var client = server.CreateClient();
var project = client.Projects["Foo/Test"];

Assert.That(project.Path, Is.EqualTo("test"));
}

[Test]
public void Test_projects_created_can_be_found()
{
Expand Down
4 changes: 2 additions & 2 deletions NGitLab.Mock/Config/GitLabHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,10 +1250,10 @@ private static void CreateGroup(GitLabServer server, GitLabGroup group)

private static void CreateProject(GitLabServer server, GitLabProject project)
{
var prj = new Project(project.Name ?? project.Path ?? Guid.NewGuid().ToString("D"))
var projectName = project.Name ?? project.Path ?? Guid.NewGuid().ToString("D");
var prj = new Project(projectName, project.Path)
{
Id = project.Id,
Path = project.Path,
Description = project.Description,
DefaultBranch = project.DefaultBranch ?? server.DefaultBranchName,
Visibility = project.Visibility ?? project.Parent.DefaultVisibility,
Expand Down
2 changes: 1 addition & 1 deletion NGitLab.Mock/Config/GitLabProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public GitLabProject()
public string Name { get; set; }

/// <summary>
/// Path/slug. Defaults to <see cref="Slug.Create(Name)"/>.
/// Path/slug.
/// </summary>
public string Path { get; set; }

Expand Down

0 comments on commit d636305

Please sign in to comment.