Skip to content

Commit

Permalink
More test tweaks to pass CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Jul 23, 2020
1 parent b7b9888 commit c526a47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/TurnerSoftware.SitemapTools/Parser/XmlSitemapParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public async Task<SitemapFile> ParseSitemapAsync(TextReader reader, Cancellation

foreach (var urlNode in topNode.Elements())
{
cancellationToken.ThrowIfCancellationRequested();
var sitemapEntry = ParseSitemapEntry(urlNode);
urls.Add(sitemapEntry);
}
Expand All @@ -57,6 +58,7 @@ public async Task<SitemapFile> ParseSitemapAsync(TextReader reader, Cancellation

foreach (var sitemapNode in topNode.Elements())
{
cancellationToken.ThrowIfCancellationRequested();
var indexedSitemap = ParseSitemapIndex(sitemapNode);
indexedSitemaps.Add(indexedSitemap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ public async Task ParseTextSitemapAsync()
}

[TestMethod]
public async Task ParseTextSitemapAsyncCancelation()
public async Task ParseTextSitemapAsync_Cancellation()
{
var cts = new CancellationTokenSource(0);
using (var reader = LoadResource("text-sitemap.txt"))
{
var parser = new TextSitemapParser();
SitemapFile sitemapFile = null;
await Assert.ThrowsExceptionAsync<OperationCanceledException>(async () => sitemapFile = await parser.ParseSitemapAsync(reader, cts.Token));
Assert.AreEqual(null, sitemapFile);
await Assert.ThrowsExceptionAsync<OperationCanceledException>(
async () => await parser.ParseSitemapAsync(reader, new CancellationToken(true))
);
}
}
}
Expand Down
18 changes: 6 additions & 12 deletions tests/TurnerSoftware.SitemapTools.Tests/XmlSitemapParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TurnerSoftware.SitemapTools.Tests
public class XmlSitemapParserTests : TestBase
{
[TestMethod]
public async Task ChangeFrequenciesAreSetCorrectlyAsync()
public async Task ChangeFrequenciesAreSetCorrectly()
{
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Expand Down Expand Up @@ -104,26 +104,20 @@ public async Task ParseSitemapFileAsync()
}

[TestMethod]
public async Task ParseSitemapFileAsyncCancelation()
public async Task ParseSitemapFileAsync_Cancellation()
{
var cts = new CancellationTokenSource(0);
using (var reader = LoadResource("basic-sitemap.xml"))
{
var parser = new XmlSitemapParser();
SitemapFile sitemapFile = null;
try
{
sitemapFile = await parser.ParseSitemapAsync(reader, cts.Token);
await parser.ParseSitemapAsync(reader, new CancellationToken(true));
}
catch (TaskCanceledException ex)
catch (Exception ex) when (ex is TaskCanceledException || ex is OperationCanceledException)
{
Assert.ThrowsException<TaskCanceledException>(() => throw ex);
return;
}
catch (OperationCanceledException ex)
{
Assert.ThrowsException<OperationCanceledException>(() => throw ex);
}
Assert.AreEqual(null, sitemapFile);
Assert.Fail("Expected exception not thrown");
}
}
}
Expand Down

0 comments on commit c526a47

Please sign in to comment.