Code cleanup
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using System.Net.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenQA.Selenium;
|
||||
|
||||
namespace AOW4.SeleniumTests.Tests;
|
||||
@@ -25,19 +22,16 @@ public class BrokenLinksTest : BaseTest
|
||||
|
||||
foreach (var raw in anchors)
|
||||
{
|
||||
if (raw.StartsWith("javascript:", System.StringComparison.OrdinalIgnoreCase))
|
||||
if (raw.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
if (raw.StartsWith("mailto:", System.StringComparison.OrdinalIgnoreCase))
|
||||
if (raw.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
System.Uri uri;
|
||||
Uri uri;
|
||||
try
|
||||
{
|
||||
uri = new System.Uri(raw, System.UriKind.RelativeOrAbsolute);
|
||||
if (!uri.IsAbsoluteUri)
|
||||
{
|
||||
uri = new System.Uri(new System.Uri(BaseUrl), raw);
|
||||
}
|
||||
uri = new Uri(raw, UriKind.RelativeOrAbsolute);
|
||||
if (!uri.IsAbsoluteUri) uri = new Uri(new Uri(BaseUrl), raw);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -54,21 +48,15 @@ public class BrokenLinksTest : BaseTest
|
||||
// try GET as fallback
|
||||
using var greq = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||
var gresp = client.Send(greq);
|
||||
if (!gresp.IsSuccessStatusCode)
|
||||
{
|
||||
failures.Add($"{(int)gresp.StatusCode} {uri}");
|
||||
}
|
||||
if (!gresp.IsSuccessStatusCode) failures.Add($"{(int)gresp.StatusCode} {uri}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
failures.Add($"Error checking {uri}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (failures.Any())
|
||||
{
|
||||
Assert.Fail("Broken links found:\n" + string.Join("\n", failures));
|
||||
}
|
||||
if (failures.Any()) Assert.Fail("Broken links found:\n" + string.Join("\n", failures));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user