Add test for dead links in Views

This commit is contained in:
nicolas.dorier 2019-09-02 16:32:38 +09:00
parent 66064bd2eb
commit 0047a5388d
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 44 additions and 1 deletions

View file

@ -73,6 +73,49 @@ namespace BTCPayServer.Tests
Logs.LogProvider = new XUnitLogProvider(helper); Logs.LogProvider = new XUnitLogProvider(helper);
} }
[Fact]
[Trait("Fast", "Fast")]
public async Task CheckNoDeadLink()
{
var views = Path.Combine(LanguageService.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "Views");
var viewFiles = Directory.EnumerateFiles(views, "*.cshtml", SearchOption.AllDirectories).ToArray();
Assert.NotEmpty(viewFiles);
Regex regex = new Regex("href=\"(http.*?)\"");
var httpClient = new HttpClient();
List<Task> checkLinks = new List<Task>();
foreach (var file in viewFiles)
{
checkLinks.Add(CheckLinks(regex, httpClient, file));
}
await Task.WhenAll(checkLinks);
}
private static async Task CheckLinks(Regex regex, HttpClient httpClient, string file)
{
List<Task> checkLinks = new List<Task>();
var text = await File.ReadAllTextAsync(file);
foreach (var match in regex.Matches(text).OfType<Match>())
{
checkLinks.Add(AssertLinkNotDead(httpClient, match, file));
}
await Task.WhenAll(checkLinks);
}
private static async Task AssertLinkNotDead(HttpClient httpClient, Match match, string file)
{
var url = match.Groups[1].Value;
try
{
Assert.Equal(HttpStatusCode.OK, (await httpClient.GetAsync(url)).StatusCode);
Logs.Tester.LogInformation($"OK: {url} ({file})");
}
catch
{
Logs.Tester.LogInformation($"FAILED: {url} ({file})");
throw;
}
}
[Fact] [Fact]
[Trait("Fast", "Fast")] [Trait("Fast", "Fast")]
public void CanHandleUriValidation() public void CanHandleUriValidation()

View file

@ -114,7 +114,7 @@
<a href="https://slack.btcpayserver.org/" target="_blank"> <a href="https://slack.btcpayserver.org/" target="_blank">
<img src="~/img/slack.png" height="100" /> <img src="~/img/slack.png" height="100" />
</a> </a>
<p><a href="http://slack.forkbitpay.ninja/" target="_blank">On Slack</a></p> <p><a href="https://slack.btcpayserver.org/" target="_blank">On Slack</a></p>
</div> </div>
<div class="col-lg-3 mr-auto text-center"> <div class="col-lg-3 mr-auto text-center">
<a href="https://twitter.com/BtcpayServer" target="_blank"> <a href="https://twitter.com/BtcpayServer" target="_blank">