Unit Test

This commit is contained in:
M-L-Ml 2025-04-21 19:39:16 +02:00
parent c9cdd4149b
commit 5e9dabb454

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Diagnostics;
namespace SourceGit.Models namespace SourceGit.Models
{ {
@ -99,8 +100,36 @@ namespace SourceGit.Models
return remotes return remotes
.Select(TryCreateCommitLink) .Select(TryCreateCommitLink)
.Where(cl => cl != null) .Where(cl => cl != null)
.Cast<CommitLink>()
.ToList(); .ToList();
} }
#if DEBUG
// Minimal stub for Remote for testing
public class DebugRemote : Remote
{
private readonly string _url;
public DebugRemote(string url) { _url = url; }
public new bool TryGetVisitURL(out string url) { url = _url; return true; }
}
static CommitLink()
{
//Unit tests , TODO: make normal UnitTests.
// Test Github
var githubRemote = new DebugRemote("https://github.com/user/repo.git");
var links = Get(new List<Remote> { githubRemote });
Debug.Assert(links.Count == 1, "Should find one CommitLink for Github");
Debug.Assert(links[0].Name.StartsWith("Github"), "Provider should be Github");
Debug.Assert(links[0].URLPrefix == "https://github.com/user/repo/commit/", "URLPrefix should be correct for Github");
// Test BitBucket
var bitbucketRemote = new DebugRemote("https://bitbucket.org/team/project");
links = Get(new List<Remote> { bitbucketRemote });
Debug.Assert(links.Count == 1, "Should find one CommitLink for BitBucket");
Debug.Assert(links[0].Name.StartsWith("BitBucket"), "Provider should be BitBucket");
Debug.Assert(links[0].URLPrefix == "https://bitbucket.org/team/project/commits/", "URLPrefix should be correct for BitBucket");
}
#endif
} }
} }