Skip to content

Commit

Permalink
Update invalid URLs test
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 18, 2024
1 parent 3efbeb6 commit f1e99f5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Tests/Core/Net/NetAsyncDownloaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using NUnit.Framework;

using CKAN;
#if NETFRAMEWORK || NETSTANDARD
using CKAN.Extensions;
#endif

using Tests.Data;

Expand Down Expand Up @@ -189,11 +192,13 @@ public void DownloadAndWait_WithSomeInvalidUrls_ThrowsDownloadErrorsKraken(
var targets = fromPaths.Select(p => new NetAsyncDownloader.DownloadTargetFile(new Uri(p),
Path.GetTempFileName()))
.ToArray();
var badIndices = fromPaths.Select((p, i) => new Tuple<int, bool>(i, File.Exists(p)))
.Where(tuple => !tuple.Item2)
.Select(tuple => tuple.Item1)
.ToArray();
var validTargets = targets.Where((t, i) => !badIndices.Contains(i));
var badTargets = targets.Zip(fromPaths)
#pragma warning disable IDE0033
.Where(tuple => !File.Exists(tuple.Item2))
.Select(tuple => tuple.Item1)
#pragma warning restore IDE0033
.ToArray();
var validTargets = targets.Except(badTargets);

// Act / Assert
var exception = Assert.Throws<DownloadErrorsKraken>(() =>
Expand All @@ -202,7 +207,8 @@ public void DownloadAndWait_WithSomeInvalidUrls_ThrowsDownloadErrorsKraken(
});
Assert.Multiple(() =>
{
CollectionAssert.AreEquivalent(badIndices, exception?.Exceptions.Select(kvp => kvp.Key).ToArray());
CollectionAssert.AreEquivalent(badTargets,
exception?.Exceptions.Select(kvp => kvp.Key).ToArray());
foreach (var kvp in exception?.Exceptions!)
{
var baseExc = kvp.Value.GetBaseException() as FileNotFoundException;
Expand Down

0 comments on commit f1e99f5

Please sign in to comment.