From 06d222286593dd53c03698e9c8bb20c0aa132be0 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 5 Sep 2021 16:38:06 -0500 Subject: [PATCH] build: upgrade fluent assertions to v6 Also fix unit tests and compile issues --- src/Directory.Build.targets | 4 ++-- .../FluentAssertions/JsonEquivalencyStep.cs | 20 ++++++++++--------- .../GuideSteps/CustomFormatStepTest.cs | 9 +++++---- .../GuideSteps/QualityProfileStepTest.cs | 6 +++--- .../QualityProfileApiPersistenceStepTest.cs | 4 ++-- .../ReleaseProfileParserTest.cs | 15 +++++++------- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index 41bde9f5..95d03722 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -5,8 +5,8 @@ - - + + diff --git a/src/TestLibrary/FluentAssertions/JsonEquivalencyStep.cs b/src/TestLibrary/FluentAssertions/JsonEquivalencyStep.cs index fa02d044..99dab8e4 100644 --- a/src/TestLibrary/FluentAssertions/JsonEquivalencyStep.cs +++ b/src/TestLibrary/FluentAssertions/JsonEquivalencyStep.cs @@ -6,17 +6,19 @@ namespace TestLibrary.FluentAssertions { public class JsonEquivalencyStep : IEquivalencyStep { - public bool CanHandle(IEquivalencyValidationContext context, IEquivalencyAssertionOptions config) + public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, + IEquivalencyValidator nestedValidator) { - return context.Subject?.GetType().IsAssignableTo(typeof(JToken)) ?? false; - } + var canHandle = comparands.Subject?.GetType().IsAssignableTo(typeof(JToken)) ?? false; + if (!canHandle) + { + return EquivalencyResult.ContinueWithNext; + } - public bool Handle(IEquivalencyValidationContext context, IEquivalencyValidator parent, - IEquivalencyAssertionOptions config) - { - ((JToken) context.Subject).Should() - .BeEquivalentTo((JToken) context.Expectation, context.Because, context.BecauseArgs); - return true; + ((JToken) comparands.Subject!).Should().BeEquivalentTo( + (JToken) comparands.Expectation, context.Reason.FormattedMessage, context.Reason.Arguments); + + return EquivalencyResult.AssertionCompleted; } } } diff --git a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs index bd5e2c3a..4a76b69c 100644 --- a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs +++ b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs @@ -192,7 +192,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.DuplicatedCustomFormats.Should().BeEmpty(); processor.CustomFormatsWithOutdatedNames.Should().BeEmpty(); processor.DeletedCustomFormatsInCache.Should() - .BeEquivalentTo(new TrashIdMapping("id1000", "name1")); + .BeEquivalentTo(new[] {new TrashIdMapping("id1000", "name1")}); processor.ProcessedCustomFormats.Should().BeEquivalentTo(new List { new("name1", "id1", JObject.Parse(@"{'name': 'name1'}")) @@ -218,7 +218,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.DuplicatedCustomFormats.Should().BeEmpty(); processor.CustomFormatsWithOutdatedNames.Should().BeEmpty(); - processor.DeletedCustomFormatsInCache.Should().BeEquivalentTo(cache.TrashIdMappings[0]); + processor.DeletedCustomFormatsInCache.Should().BeEquivalentTo(new[] {cache.TrashIdMappings[0]}); processor.ProcessedCustomFormats.Should().BeEmpty(); } @@ -269,8 +269,9 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.Process(guideData, testConfig, null); //Dictionary> - processor.DuplicatedCustomFormats.Should().ContainKey("name1") - .WhichValue.Should().BeEquivalentTo(new List + processor.DuplicatedCustomFormats.Should() + .ContainKey("name1").WhoseValue.Should() + .BeEquivalentTo(new List { new("name1", "id1", JObject.Parse(@"{'name': 'name1'}")), new("name1", "id2", JObject.Parse(@"{'name': 'name1'}")) diff --git a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs index a927348c..7c34f5de 100644 --- a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs +++ b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs @@ -35,7 +35,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.Process(testConfigData); processor.ProfileScores.Should().BeEmpty(); - processor.CustomFormatsWithoutScore.Should().Equal(new List {("name1", "id1", "profile1")}); + processor.CustomFormatsWithoutScore.Should().Equal(("name1", "id1", "profile1")); } [Test] @@ -60,7 +60,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.Process(testConfigData); processor.ProfileScores.Should() - .ContainKey("profile1").WhichValue.Should() + .ContainKey("profile1").WhoseValue.Should() .BeEquivalentTo(CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats[0], 50))); processor.CustomFormatsWithoutScore.Should().BeEmpty(); @@ -123,7 +123,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps processor.Process(testConfigData); processor.ProfileScores.Should() - .ContainKey("profile1").WhichValue.Should() + .ContainKey("profile1").WhoseValue.Should() .BeEquivalentTo(CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats[0], 0))); processor.CustomFormatsWithoutScore.Should().BeEmpty(); diff --git a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/PersistenceSteps/QualityProfileApiPersistenceStepTest.cs b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/PersistenceSteps/QualityProfileApiPersistenceStepTest.cs index 11df5eb6..2d2fa5fc 100644 --- a/src/TrashLib.Tests/Radarr/CustomFormat/Processors/PersistenceSteps/QualityProfileApiPersistenceStepTest.cs +++ b/src/TrashLib.Tests/Radarr/CustomFormat/Processors/PersistenceSteps/QualityProfileApiPersistenceStepTest.cs @@ -125,7 +125,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps processor.InvalidProfileNames.Should().BeEmpty(); processor.UpdatedScores.Should() - .ContainKey("profile1").WhichValue.Should() + .ContainKey("profile1").WhoseValue.Should() .BeEquivalentTo(new List { new("cf1", 0, FormatScoreUpdateReason.Reset), @@ -255,7 +255,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps .UpdateQualityProfile(Verify.That(a => a.Should().BeEquivalentTo(expectedProfileJson)), 1); processor.InvalidProfileNames.Should().BeEmpty(); processor.UpdatedScores.Should() - .ContainKey("profile1").WhichValue.Should() + .ContainKey("profile1").WhoseValue.Should() .BeEquivalentTo(new List { new("3D", 100, FormatScoreUpdateReason.Updated), diff --git a/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileParserTest.cs b/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileParserTest.cs index a2a70d88..29c2cd20 100644 --- a/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileParserTest.cs +++ b/src/TrashLib.Tests/Sonarr/ReleaseProfile/ReleaseProfileParserTest.cs @@ -70,7 +70,7 @@ xyz var results = context.ParseWithDefaults(markdown); results.Should().ContainKey("Test Release Profile") - .WhichValue.Should().BeEquivalentTo(new + .WhoseValue.Should().BeEquivalentTo(new { Ignored = new List {"abc"}, Required = new List {"xyz"} @@ -107,7 +107,7 @@ One more var results = context.ParseWithDefaults(markdown); results.Should().ContainKey("Test Release Profile") - .WhichValue.Should().BeEquivalentTo(new + .WhoseValue.Should().BeEquivalentTo(new { Ignored = new List {"abc"}, Required = new List {"xyz", "123"} @@ -127,7 +127,7 @@ One more profile.Ignored.Should().BeEquivalentTo("term2", "term3"); profile.Required.Should().BeEquivalentTo("term4"); - profile.Preferred.Should().ContainKey(100).WhichValue.Should().BeEquivalentTo(new List {"term1"}); + profile.Preferred.Should().ContainKey(100).WhoseValue.Should().BeEquivalentTo(new List {"term1"}); } [Test] @@ -139,10 +139,10 @@ One more results.Should() .ContainKey("First Release Profile") - .WhichValue.IncludePreferredWhenRenaming.Should().Be(true); + .WhoseValue.IncludePreferredWhenRenaming.Should().Be(true); results.Should() .ContainKey("Second Release Profile") - .WhichValue.IncludePreferredWhenRenaming.Should().Be(false); + .WhoseValue.IncludePreferredWhenRenaming.Should().Be(false); } [Test] @@ -307,7 +307,7 @@ abc results.Should() .ContainKey("Test Release Profile") - .WhichValue.Preferred.Should() + .WhoseValue.Preferred.Should() .BeEquivalentTo(new Dictionary> { {100, new List {"abc"}} @@ -356,8 +356,7 @@ abc var results = context.ParseWithDefaults(markdown); results.Should() - .ContainKey("Test Release Profile") - .WhichValue.Should() + .ContainKey("Test Release Profile").WhoseValue.Should() .BeEquivalentTo(new { Required = new { },