test: Upgrade to FluentAssertions v8

pull/415/head
Robert Dailey 2 months ago
parent e4e4a5f1c6
commit ca8572b3a0

@ -50,7 +50,7 @@
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0012" PrivateAssets="all" />
<PackageVersion Include="AutoFixture.NUnit4" Version="5.0.0-preview0012" PrivateAssets="all" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" PrivateAssets="all" />
<PackageVersion Include="FluentAssertions" Version="7.1.0" PrivateAssets="all" />
<PackageVersion Include="FluentAssertions" Version="8.0.1" PrivateAssets="all" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.34.1" PrivateAssets="all" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" PrivateAssets="all" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" PrivateAssets="all" />
@ -75,4 +75,4 @@
<!-- Cannot use the official Jetbrains.Annotations package because it doesn't work with GlobalPackageReference -->
<GlobalPackageReference Include="Rocket.Surgery.MSBuild.JetBrains.Annotations" Version="1.2.1" />
</ItemGroup>
</Project>
</Project>

@ -59,7 +59,7 @@ public class RadarrMediaNamingConfigPhaseTest
StandardMovieFormat = "file_emby",
MovieFolderFormat = "folder_plex",
},
o => o.RespectingRuntimeTypes()
o => o.PreferringRuntimeMemberTypes()
);
}
}

@ -34,7 +34,7 @@ public class MediaNamingTransactionPhaseRadarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -55,7 +55,7 @@ public class MediaNamingTransactionPhaseRadarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ApiFetchOutput, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ApiFetchOutput, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -84,7 +84,7 @@ public class MediaNamingTransactionPhaseRadarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -120,7 +120,7 @@ public class MediaNamingTransactionPhaseRadarrTest
StandardMovieFormat = "file_format2",
MovieFolderFormat = "folder_format2",
},
o => o.RespectingRuntimeTypes()
o => o.PreferringRuntimeMemberTypes()
);
}
}

@ -33,7 +33,7 @@ public class MediaNamingTransactionPhaseSonarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -57,7 +57,7 @@ public class MediaNamingTransactionPhaseSonarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ApiFetchOutput, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ApiFetchOutput, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -92,7 +92,7 @@ public class MediaNamingTransactionPhaseSonarrTest
context
.TransactionOutput.Should()
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.RespectingRuntimeTypes());
.BeEquivalentTo(context.ConfigOutput.Dto, o => o.PreferringRuntimeMemberTypes());
}
[Test, AutoMockData]
@ -137,7 +137,7 @@ public class MediaNamingTransactionPhaseSonarrTest
DailyEpisodeFormat = "episodes_daily_default2",
AnimeEpisodeFormat = "episodes_anime_default2",
},
o => o.RespectingRuntimeTypes()
o => o.PreferringRuntimeMemberTypes()
);
}
}

@ -1,89 +0,0 @@
using FluentAssertions.Collections;
using FluentAssertions.Execution;
namespace Recyclarr.TestLibrary.FluentAssertions;
public static class FluentAssertionsExtensions
{
public static AndWhichConstraint<TAssertions, string> ContainRegexMatch<
TCollection,
TAssertions
>(
this StringCollectionAssertions<TCollection, TAssertions> assert,
string regexPattern,
string because = "",
params object[] becauseArgs
)
where TCollection : IEnumerable<string>
where TAssertions : StringCollectionAssertions<TCollection, TAssertions>
{
bool ContainsRegexMatch()
{
return assert.Subject.Any(item =>
{
using var scope = new AssertionScope();
item.Should().MatchRegex(regexPattern);
return scope.Discard().Length == 0;
});
}
Execute
.Assertion.BecauseOf(because, becauseArgs)
.ForCondition(ContainsRegexMatch())
.FailWith(
"Expected {context:collection} {0} to contain a regex match of {1}{reason}.",
assert.Subject,
regexPattern
);
var matched = assert.Subject.Where(item =>
{
using var scope = new AssertionScope();
item.Should().MatchRegex(regexPattern);
return scope.Discard().Length == 0;
});
return new AndWhichConstraint<TAssertions, string>((TAssertions)assert, matched);
}
public static AndWhichConstraint<TAssertions, string> NotContainRegexMatch<
TCollection,
TAssertions
>(
this StringCollectionAssertions<TCollection, TAssertions> assert,
string regexPattern,
string because = "",
params object[] becauseArgs
)
where TCollection : IEnumerable<string>
where TAssertions : StringCollectionAssertions<TCollection, TAssertions>
{
bool NotContainsRegexMatch()
{
return assert.Subject.Any(item =>
{
using var scope = new AssertionScope();
item.Should().NotMatchRegex(regexPattern);
return scope.Discard().Length == 0;
});
}
Execute
.Assertion.BecauseOf(because, becauseArgs)
.ForCondition(NotContainsRegexMatch())
.FailWith(
"Expected {context:collection} {0} to not contain a regex match of {1}{reason}.",
assert.Subject,
regexPattern
);
var matched = assert.Subject.Where(item =>
{
using var scope = new AssertionScope();
item.Should().NotMatchRegex(regexPattern);
return scope.Discard().Length == 0;
});
return new AndWhichConstraint<TAssertions, string>((TAssertions)assert, matched);
}
}

@ -117,7 +117,7 @@ public class FileSystemExtensionsTest
var result = fs.CurrentDirectory().YamlFile("test");
result.Should().NotBeNull();
result!.Name.Should().Be(yamlFilename);
result.Name.Should().Be(yamlFilename);
}
[Test]

Loading…
Cancel
Save