-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6144c36
commit 29b9baf
Showing
3 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
26 changes: 13 additions & 13 deletions
26
test/Serilog.Sinks.HttpTests/Support/Fixtures/GitHubWikiFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Serilog.Support.Fixtures | ||
{ | ||
public class GitHubWikiFixture | ||
{ | ||
private string[] rows; | ||
private const string WikiUrl = "https://raw.githubusercontent.com/wiki/FantasticFiasco/serilog-sinks-http/{0}"; | ||
private const string DescriptionRegexFormat = "- `{0}` - (?<description>.*)$"; | ||
|
||
public void Load(string wikiPage) | ||
private string pageContent; | ||
|
||
public async Task LoadAsync(string wikiPage) | ||
{ | ||
using (var client = new HttpClient()) | ||
{ | ||
rows = client | ||
.GetStringAsync($"https://raw.githubusercontent.com/wiki/FantasticFiasco/serilog-sinks-http/{wikiPage}") | ||
.Result | ||
.Split('\n'); | ||
pageContent = await client.GetStringAsync(string.Format(WikiUrl, wikiPage)); | ||
} | ||
} | ||
|
||
public string GetDescription(string parameterName) | ||
{ | ||
var pattern = $"- `{parameterName}` - "; | ||
var descriptionRegex = new Regex(string.Format(DescriptionRegexFormat, parameterName), RegexOptions.Multiline); | ||
|
||
var matchingRow = rows.SingleOrDefault(row => row.StartsWith(pattern)); | ||
if (matchingRow == null) throw new Exception($"GitHub wiki does not contain a description of parameter \"{parameterName}\""); | ||
var match = descriptionRegex.Match(pageContent); | ||
if (!match.Success) throw new Exception($"GitHub wiki does not contain a description of parameter \"{parameterName}\""); | ||
|
||
return matchingRow | ||
.Substring(pattern.Length) | ||
.Replace("`", string.Empty); // Remove code annotation | ||
return match.Groups["description"].Value | ||
.Replace("`", string.Empty); // Remove code indicator | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters