From 833cc81f1c31fb015aa68d6ddcd7ccdc2a503ec4 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Sat, 15 Apr 2023 15:42:55 +0500 Subject: [PATCH] update tests with nunit analyzers suggestions --- Tests/FlagTests.cs | 11 ++-- Tests/IrdTests.cs | 6 +-- Tests/MemoryCacheExtensionTests.cs | 8 +-- Tests/RangeTests.cs | 84 ++++++++++++++++-------------- Tests/RegexTest.cs | 8 +-- Tests/StringUtilTests.cs | 20 ++++--- Tests/TimeParserTests.cs | 11 ++-- 7 files changed, 84 insertions(+), 64 deletions(-) diff --git a/Tests/FlagTests.cs b/Tests/FlagTests.cs index 4e065f61..00fedfba 100644 --- a/Tests/FlagTests.cs +++ b/Tests/FlagTests.cs @@ -10,9 +10,12 @@ public class FlagTests public void MultipleFlagTest() { var testVal = FilterAction.IssueWarning | FilterAction.MuteModQueue; - Assert.That(testVal.HasFlag(FilterAction.IssueWarning), Is.True); - Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue), Is.True); - Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue | FilterAction.RemoveContent), Is.False); - Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.SendMessage), Is.False); + Assert.Multiple(() => + { + Assert.That(testVal.HasFlag(FilterAction.IssueWarning), Is.True); + Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue), Is.True); + Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.MuteModQueue | FilterAction.RemoveContent), Is.False); + Assert.That(testVal.HasFlag(FilterAction.IssueWarning | FilterAction.SendMessage), Is.False); + }); } } \ No newline at end of file diff --git a/Tests/IrdTests.cs b/Tests/IrdTests.cs index 9277173f..8a5372ce 100644 --- a/Tests/IrdTests.cs +++ b/Tests/IrdTests.cs @@ -12,7 +12,7 @@ public class IrdTests { var baseDir = TestContext.CurrentContext.TestDirectory; var testFiles = Directory.GetFiles(baseDir, "*.ird", SearchOption.AllDirectories); - Assert.That(testFiles.Length, Is.GreaterThan(0)); + Assert.That(testFiles, Is.Not.Empty); foreach (var file in testFiles) { @@ -26,7 +26,7 @@ public class IrdTests { var baseDir = TestContext.CurrentContext.TestDirectory; var testFiles = Directory.GetFiles(baseDir, "*.ird", SearchOption.AllDirectories); - Assert.That(testFiles.Length, Is.GreaterThan(0)); + Assert.That(testFiles, Is.Not.Empty); foreach (var file in testFiles) { @@ -35,7 +35,7 @@ public class IrdTests Assert.That(ird.FileCount, Is.GreaterThan(0)); var fileList = ird.GetFilenames(); - Assert.That(fileList.Count, Is.EqualTo(ird.FileCount)); + Assert.That(fileList, Has.Count.EqualTo(ird.FileCount)); } } } \ No newline at end of file diff --git a/Tests/MemoryCacheExtensionTests.cs b/Tests/MemoryCacheExtensionTests.cs index 75d5f87a..0d8ea56e 100644 --- a/Tests/MemoryCacheExtensionTests.cs +++ b/Tests/MemoryCacheExtensionTests.cs @@ -12,19 +12,19 @@ public class MemoryCacheExtensionTests public void GetCacheKeysTest() { var cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromHours(1) }); - Assert.That(cache.GetCacheKeys().Count, Is.EqualTo(0)); + Assert.That(cache.GetCacheKeys(), Is.Empty); cache.Set(13, "val13"); - Assert.That(cache.GetCacheKeys().Count, Is.EqualTo(1)); + Assert.That(cache.GetCacheKeys(), Has.Count.EqualTo(1)); } [Test] public void GetCacheEntriesTest() { var cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromHours(1) }); - Assert.That(cache.GetCacheKeys().Count, Is.EqualTo(0)); + Assert.That(cache.GetCacheKeys(), Is.Empty); cache.Set(13, "val13"); - Assert.That(cache.GetCacheKeys().Count, Is.EqualTo(1)); + Assert.That(cache.GetCacheKeys(), Has.Count.EqualTo(1)); } } \ No newline at end of file diff --git a/Tests/RangeTests.cs b/Tests/RangeTests.cs index bf8cda4e..77dc1478 100644 --- a/Tests/RangeTests.cs +++ b/Tests/RangeTests.cs @@ -9,51 +9,57 @@ public class RangeTests { [Test] public void UniqueListRangeAccessorTest() - { - var testValue = new[] {0, 1, 2, 3, 4}; + { + var testValue = new[] {0, 1, 2, 3, 4}; var list = new UniqueList(testValue); - Assert.That(list, Is.EqualTo(testValue)); + Assert.Multiple(() => + { + Assert.That(list, Is.EqualTo(testValue)); - Assert.That(list[0..], Is.EqualTo(testValue[0..])); - Assert.That(list[1..], Is.EqualTo(testValue[1..])); - Assert.That(list[4..], Is.EqualTo(testValue[4..])); - Assert.That(list[5..], Is.EqualTo(testValue[5..])); + Assert.That(list[0..], Is.EqualTo(testValue[0..])); + Assert.That(list[1..], Is.EqualTo(testValue[1..])); + Assert.That(list[4..], Is.EqualTo(testValue[4..])); + Assert.That(list[5..], Is.EqualTo(testValue[5..])); - Assert.That(list[0..1], Is.EqualTo(testValue[0..1])); - Assert.That(list[0..4], Is.EqualTo(testValue[0..4])); - Assert.That(list[0..5], Is.EqualTo(testValue[0..5])); - Assert.That(list[1..4], Is.EqualTo(testValue[1..4])); - Assert.That(list[1..5], Is.EqualTo(testValue[1..5])); - - Assert.That(list[..0], Is.EqualTo(testValue[..0])); - Assert.That(list[..1], Is.EqualTo(testValue[..1])); - Assert.That(list[..4], Is.EqualTo(testValue[..4])); - Assert.That(list[..5], Is.EqualTo(testValue[..5])); + Assert.That(list[0..1], Is.EqualTo(testValue[0..1])); + Assert.That(list[0..4], Is.EqualTo(testValue[0..4])); + Assert.That(list[0..5], Is.EqualTo(testValue[0..5])); + Assert.That(list[1..4], Is.EqualTo(testValue[1..4])); + Assert.That(list[1..5], Is.EqualTo(testValue[1..5])); - Assert.That(list[^0..], Is.EqualTo(testValue[^0..])); - Assert.That(list[^1..], Is.EqualTo(testValue[^1..])); - Assert.That(list[^4..], Is.EqualTo(testValue[^4..])); - Assert.That(list[^5..], Is.EqualTo(testValue[^5..])); + Assert.That(list[..0], Is.EqualTo(testValue[..0])); + Assert.That(list[..1], Is.EqualTo(testValue[..1])); + Assert.That(list[..4], Is.EqualTo(testValue[..4])); + Assert.That(list[..5], Is.EqualTo(testValue[..5])); - Assert.That(list[^1..^0], Is.EqualTo(testValue[^1..^0])); - Assert.That(list[^4..^0], Is.EqualTo(testValue[^4..^0])); - Assert.That(list[^5..^0], Is.EqualTo(testValue[^5..^0])); - Assert.That(list[^4..^1], Is.EqualTo(testValue[^4..^1])); - Assert.That(list[^5..^1], Is.EqualTo(testValue[^5..^1])); + Assert.That(list[^0..], Is.EqualTo(testValue[^0..])); + Assert.That(list[^1..], Is.EqualTo(testValue[^1..])); + Assert.That(list[^4..], Is.EqualTo(testValue[^4..])); + Assert.That(list[^5..], Is.EqualTo(testValue[^5..])); - Assert.That(list[..^0], Is.EqualTo(testValue[..^0])); - Assert.That(list[..^1], Is.EqualTo(testValue[..^1])); - Assert.That(list[..^4], Is.EqualTo(testValue[..^4])); - Assert.That(list[..^5], Is.EqualTo(testValue[..^5])); - } + Assert.That(list[^1..^0], Is.EqualTo(testValue[^1..^0])); + Assert.That(list[^4..^0], Is.EqualTo(testValue[^4..^0])); + Assert.That(list[^5..^0], Is.EqualTo(testValue[^5..^0])); + Assert.That(list[^4..^1], Is.EqualTo(testValue[^4..^1])); + Assert.That(list[^5..^1], Is.EqualTo(testValue[^5..^1])); - [Test] + Assert.That(list[..^0], Is.EqualTo(testValue[..^0])); + Assert.That(list[..^1], Is.EqualTo(testValue[..^1])); + Assert.That(list[..^4], Is.EqualTo(testValue[..^4])); + Assert.That(list[..^5], Is.EqualTo(testValue[..^5])); + }); + } + + [Test] public void SubstringTests() - { - var str = "abc"; - Assert.That(str[1..], Is.EqualTo(str.Substring(1))); - Assert.That("a"[1..], Is.EqualTo("a".Substring(1))); - Assert.That(str[0], Is.EqualTo('a')); - Assert.That(str[^1], Is.EqualTo('c')); - } + { + var str = "abc"; + Assert.Multiple(() => + { + Assert.That(str[1..], Is.EqualTo(str.Substring(1))); + Assert.That("a"[1..], Is.EqualTo("a".Substring(1))); + Assert.That(str[0], Is.EqualTo('a')); + Assert.That(str[^1], Is.EqualTo('c')); + }); + } } \ No newline at end of file diff --git a/Tests/RegexTest.cs b/Tests/RegexTest.cs index d5a92f06..ac2f1128 100644 --- a/Tests/RegexTest.cs +++ b/Tests/RegexTest.cs @@ -16,8 +16,10 @@ public class RegexTest var latin = input.ToLatin8BitEncoding(); var match = Regex.Match(latin, @"Rap file not found: (\xE2\x80\x9C)?(?.*?)(\xE2\x80\x9D)?\r?$", DefaultOptions); - Assert.That(match.Success, Is.True); - Assert.That(match.Groups["rap_file"].Value, Is.EqualTo("/dev_hdd0/home/00000001/exdata/EP4062-NPEB02436_00-ADDCONTENT000001.rap")); + Assert.Multiple(() => + { + Assert.That(match.Success, Is.True); + Assert.That(match.Groups["rap_file"].Value, Is.EqualTo("/dev_hdd0/home/00000001/exdata/EP4062-NPEB02436_00-ADDCONTENT000001.rap")); + }); } - } \ No newline at end of file diff --git a/Tests/StringUtilTests.cs b/Tests/StringUtilTests.cs index dfe9af2d..07f9f471 100644 --- a/Tests/StringUtilTests.cs +++ b/Tests/StringUtilTests.cs @@ -23,9 +23,12 @@ public class StringUtilTests [Test] public void VisibleTrimTest() { - Assert.That("abc".TrimVisible(100), Is.EqualTo("abc")); - Assert.That("abc".TrimVisible(3), Is.EqualTo("abc")); - Assert.That("abc".TrimVisible(2), Is.EqualTo("a…")); + Assert.Multiple(() => + { + Assert.That("abc".TrimVisible(100), Is.EqualTo("abc")); + Assert.That("abc".TrimVisible(3), Is.EqualTo("abc")); + Assert.That("abc".TrimVisible(2), Is.EqualTo("a…")); + }); } [TestCase("cockatrice", "сockаtrice")] @@ -115,10 +118,13 @@ ignorance the hard way."" [TestCase("camelCaseString13", "c", "cCS", "c13", "cCS13")] public void AcronymGenerationTest(string input, string expectedDefault, string expectedWithUpper, string expectedWithDigits, string expectedWithUpperAndDigits) { - Assert.That(input.GetAcronym(), Is.EqualTo(expectedDefault)); - Assert.That(input.GetAcronym(includeAllCaps: true), Is.EqualTo(expectedWithUpper)); - Assert.That(input.GetAcronym(includeAllDigits: true), Is.EqualTo(expectedWithDigits)); - Assert.That(input.GetAcronym(includeAllCaps: true, includeAllDigits: true), Is.EqualTo(expectedWithUpperAndDigits)); + Assert.Multiple(() => + { + Assert.That(input.GetAcronym(), Is.EqualTo(expectedDefault)); + Assert.That(input.GetAcronym(includeAllCaps: true), Is.EqualTo(expectedWithUpper)); + Assert.That(input.GetAcronym(includeAllDigits: true), Is.EqualTo(expectedWithDigits)); + Assert.That(input.GetAcronym(includeAllCaps: true, includeAllDigits: true), Is.EqualTo(expectedWithUpperAndDigits)); + }); } public static double DiceCoefficient(string input, string comparedTo) diff --git a/Tests/TimeParserTests.cs b/Tests/TimeParserTests.cs index fbc94d21..d9a80f29 100644 --- a/Tests/TimeParserTests.cs +++ b/Tests/TimeParserTests.cs @@ -13,14 +13,17 @@ public class TimeParserTests public void TimeZoneConverterTest(string input, string utcInput) { var utc = DateTime.Parse(utcInput).Normalize(); - Assert.That(TimeParser.TryParse(input, out var result), Is.True, $"{input} failed to parse\nSupported time zones: {string.Join(", ", TimeParser.GetSupportedTimeZoneAbbreviations())}"); - Assert.That(result, Is.EqualTo(utc)); - Assert.That(result.Kind, Is.EqualTo(DateTimeKind.Utc)); + Assert.Multiple(() => + { + Assert.That(TimeParser.TryParse(input, out var result), Is.True, $"{input} failed to parse\nSupported time zones: {string.Join(", ", TimeParser.GetSupportedTimeZoneAbbreviations())}"); + Assert.That(result, Is.EqualTo(utc)); + Assert.That(result.Kind, Is.EqualTo(DateTimeKind.Utc)); + }); } [Test] public void TimeZoneInfoTest() { - Assert.That(TimeParser.TimeZoneMap.Count, Is.GreaterThan(0)); + Assert.That(TimeParser.TimeZoneMap, Is.Not.Empty); } } \ No newline at end of file