static async Task RunTestAsync(IDoujinClient client) { var tester = new ClientTester(); if (!await tester.TestAsync(client)) { tester.ThrowExceptions(); } }
public async Task <bool> TestAsync(IDoujinClient client, CancellationToken cancellationToken = default) { try { // no test cases found for this client if (!_testCases.TryGetValue(client.GetType(), out var testCases)) { return(true); } var tasks = testCases.Select(async testCase => { // retrieve doujin var x = testCase.KnownValue; var y = await client.GetAsync(testCase.DoujinId, cancellationToken); if (x == y) { return; } if (x == null || y == null) { throw new ClientTesterException( $"Expected value was {(x == null ? "null" : "not null")}, " + $"but actual value was {(y == null ? "null" : "not null")}."); } // compare the retrieved doujin with the known value Compare(x.PrettyName, y.PrettyName, nameof(DoujinInfo.PrettyName)); Compare(x.OriginalName, y.OriginalName, nameof(DoujinInfo.OriginalName)); Compare(x.UploadTime, y.UploadTime, nameof(DoujinInfo.UploadTime)); Compare(x.SourceId, y.SourceId, nameof(DoujinInfo.SourceId)); Compare(x.Artist, y.Artist, nameof(DoujinInfo.Artist)); Compare(x.Group, y.Group, nameof(DoujinInfo.Group)); Compare(x.Scanlator, y.Scanlator, nameof(DoujinInfo.Scanlator)); Compare(x.Language, y.Language, nameof(DoujinInfo.Language)); Compare(x.Characters, y.Characters, nameof(DoujinInfo.Characters)); Compare(x.Categories, y.Categories, nameof(DoujinInfo.Categories)); Compare(x.Tags, y.Tags, nameof(DoujinInfo.Tags)); Compare(x.PageCount, y.PageCount, nameof(DoujinInfo.PageCount)); }); if (ConcurrentTest) { await Task.WhenAll(tasks); } else { foreach (var task in tasks) { await task; } } return(true); } catch (TaskCanceledException) { // don't catch cancellation exceptions throw; } catch (Exception e) { Exceptions.Enqueue(e); return(false); } }