From 469cfc2cfa6dd42f0640093a7ca9c5a9ff559414 Mon Sep 17 00:00:00 2001 From: "piotr.a.michalewicz@gmail.com" Date: Sun, 7 Dec 2025 19:04:51 +0100 Subject: [PATCH] Migrate to shouldly --- .csharpierignore | 2 ++ ...ncryptedConfigValue.AspNetCore.Test.csproj | 2 +- .../SubstitutingConfigurationFactoryTest.cs | 30 +++++++++---------- .../VariableSubstitutionTest.cs | 20 ++++++------- .../EncryptConfigValueCommandTest.cs | 6 ++-- .../EncryptedConfigValue.Cli.Test.csproj | 4 +-- .../GenerateKeyCommandTest.cs | 8 ++--- .../DecryptingVariableSubstitutorTest.cs | 20 ++++++------- .../EncryptedConfigValue.Module.Test.csproj | 4 +-- EncryptedConfigValue.Test/Aes/AesKeyTest.cs | 4 +-- EncryptedConfigValue.Test/AlgorithmTest.cs | 16 +++++----- .../EncryptedConfigValue.Test.csproj | 2 +- .../EncryptedValueCompatTest.cs | 10 +++---- .../EncryptedValueTest.cs | 23 +++++++------- EncryptedConfigValue.Test/KeyWithTypeTest.cs | 6 ++-- .../Rsa/RsaPrivateKeyTest.cs | 4 +-- .../Rsa/RsaPublicKeyTest.cs | 4 +-- .../Util/StringSubstitutionExceptionTest.cs | 8 ++--- 18 files changed, 88 insertions(+), 85 deletions(-) create mode 100644 .csharpierignore diff --git a/.csharpierignore b/.csharpierignore new file mode 100644 index 0000000..457dbe4 --- /dev/null +++ b/.csharpierignore @@ -0,0 +1,2 @@ +# .csharpierignore +!**/*.cs \ No newline at end of file diff --git a/EncryptedConfigValue.AspNetCore.Test/EncryptedConfigValue.AspNetCore.Test.csproj b/EncryptedConfigValue.AspNetCore.Test/EncryptedConfigValue.AspNetCore.Test.csproj index 57920db..e481b51 100644 --- a/EncryptedConfigValue.AspNetCore.Test/EncryptedConfigValue.AspNetCore.Test.csproj +++ b/EncryptedConfigValue.AspNetCore.Test/EncryptedConfigValue.AspNetCore.Test.csproj @@ -7,7 +7,7 @@ - + diff --git a/EncryptedConfigValue.AspNetCore.Test/SubstitutingConfigurationFactoryTest.cs b/EncryptedConfigValue.AspNetCore.Test/SubstitutingConfigurationFactoryTest.cs index 847f54e..51299b0 100644 --- a/EncryptedConfigValue.AspNetCore.Test/SubstitutingConfigurationFactoryTest.cs +++ b/EncryptedConfigValue.AspNetCore.Test/SubstitutingConfigurationFactoryTest.cs @@ -1,12 +1,13 @@ using EncryptedConfigValue.AspNetCore.Test.Util; using EncryptedConfigValue.Crypto; using EncryptedConfigValue.Crypto.Util; -using FluentAssertions; using Microsoft.Extensions.Configuration; using System.Collections.Generic; using System.IO; using System.Linq; using Xunit; +using Shouldly; +using System.Text.RegularExpressions; namespace EncryptedConfigValue.AspNetCore.Test { @@ -25,25 +26,25 @@ public void TestDecryptionSucceeds() .AddEncryptedConfigValueProvider() .Build(); - configuration["Unencrypted"].Should().Be("value"); - configuration["Encrypted"].Should().Be("value"); - configuration["EncryptedWithSingleQuote"].Should().Be("don't use quotes"); - configuration["EncryptedWithDoubleQuote"].Should().Be("double quote is \""); - configuration["EncryptedMalformedYaml"].Should().Be("[oh dear"); + configuration["Unencrypted"].ShouldBe("value"); + configuration["Encrypted"].ShouldBe("value"); + configuration["EncryptedWithSingleQuote"].ShouldBe("don't use quotes"); + configuration["EncryptedWithDoubleQuote"].ShouldBe("double quote is \""); + configuration["EncryptedMalformedYaml"].ShouldBe("[oh dear"); configuration .GetSection("ArrayWithSomeEncryptedValues") .GetChildren() .Select(x => x.Value) - .Should() - .BeEquivalentTo(new List { "value", "value", "other value", "[oh dear" }); + .ToList() + .ShouldBeEquivalentTo(new List { "value", "value", "other value", "[oh dear" }); var person = new Person(); configuration .GetSection("PocoWithEncryptedValues") .Bind(person); - person.Username.Should().BeEquivalentTo("some-user"); - person.Password.Should().BeEquivalentTo("value"); + person.Username.ShouldBeEquivalentTo("some-user"); + person.Password.ShouldBeEquivalentTo("value"); } [Fact] @@ -53,11 +54,10 @@ public void TestDecryptionFailsWithNiceMessage() .AddJsonFile(Path.Combine("Resources", "testConfigWithError.json"), optional: false, reloadOnChange: false) .AddEncryptedConfigValueProvider() .Build(); - act.Should() - .Throw() - .WithMessage($"Configuration decryption error at {Path.Combine("Resources", "testConfigWithError.json")} (*)") - .WithInnerExceptionExactly() - .WithMessage("The value 'enc:ERROR' for field 'arrayWithSomeEncryptedValues:3' could not be replaced"); + var ex = Should.Throw(act); + ex.Message.ShouldMatch($@"Configuration decryption error at {Regex.Escape(Path.Combine("Resources", "testConfigWithError.json"))} \(.*\)"); + ex.InnerException.ShouldBeOfType(); + ex.InnerException.Message.ShouldBe("The value 'enc:ERROR' for field 'ArrayWithSomeEncryptedValues:3' could not be replaced"); } } } diff --git a/EncryptedConfigValue.AspNetCore.Test/VariableSubstitutionTest.cs b/EncryptedConfigValue.AspNetCore.Test/VariableSubstitutionTest.cs index fac60b9..c41333f 100644 --- a/EncryptedConfigValue.AspNetCore.Test/VariableSubstitutionTest.cs +++ b/EncryptedConfigValue.AspNetCore.Test/VariableSubstitutionTest.cs @@ -1,6 +1,6 @@ using EncryptedConfigValue.AspNetCore.Test.Util; using EncryptedConfigValue.Crypto; -using FluentAssertions; +using Shouldly; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using System; @@ -31,25 +31,25 @@ private static WebApplication CreateWebApplication() [Fact] public void TestCanDecryptValueInConfig() { - aspnet.Configuration["Unencrypted"].Should().Be("value"); - aspnet.Configuration["Encrypted"].Should().Be("value"); - aspnet.Configuration["EncryptedWithSingleQuote"].Should().Be("don't use quotes"); - aspnet.Configuration["EncryptedWithDoubleQuote"].Should().Be("double quote is \""); - aspnet.Configuration["EncryptedMalformedYaml"].Should().Be("[oh dear"); + aspnet.Configuration["Unencrypted"].ShouldBe("value"); + aspnet.Configuration["Encrypted"].ShouldBe("value"); + aspnet.Configuration["EncryptedWithSingleQuote"].ShouldBe("don't use quotes"); + aspnet.Configuration["EncryptedWithDoubleQuote"].ShouldBe("double quote is \""); + aspnet.Configuration["EncryptedMalformedYaml"].ShouldBe("[oh dear"); aspnet.Configuration .GetSection("ArrayWithSomeEncryptedValues") .GetChildren() .Select(x => x.Value) - .Should() - .BeEquivalentTo(new List { "value", "value", "other value", "[oh dear" }); + .ToList() + .ShouldBeEquivalentTo(new List { "value", "value", "other value", "[oh dear" }); var person = new Person(); aspnet.Configuration .GetSection("PocoWithEncryptedValues") .Bind(person); - person.Username.Should().BeEquivalentTo("some-user"); - person.Password.Should().BeEquivalentTo("value"); + person.Username.ShouldBeEquivalentTo("some-user"); + person.Password.ShouldBeEquivalentTo("value"); } } } diff --git a/EncryptedConfigValue.Cli.Test/EncryptConfigValueCommandTest.cs b/EncryptedConfigValue.Cli.Test/EncryptConfigValueCommandTest.cs index 7fab6d7..5622f55 100644 --- a/EncryptedConfigValue.Cli.Test/EncryptConfigValueCommandTest.cs +++ b/EncryptedConfigValue.Cli.Test/EncryptConfigValueCommandTest.cs @@ -1,6 +1,6 @@ using EncryptedConfigValue.Crypto; using EncryptedConfigValue.Crypto.Algorithm; -using FluentAssertions; +using Shouldly; using System; using System.Collections.Generic; using System.IO; @@ -69,7 +69,7 @@ internal void WeEncryptAndPrintAValue(Algorithm algorithm) var decryptionKey = keyPair.DecryptionKey; var decryptedValue = configValue.Decrypt(decryptionKey); - decryptedValue.Should().BeEquivalentTo(plaintext); + decryptedValue.ShouldBeEquivalentTo(plaintext); } [Fact] @@ -100,7 +100,7 @@ internal void WeFailIfTheKeyfileDoesNotExist() command.Execute("--keyfile", tempFilePath, "--value", plaintext); }; - act.Should().Throw(); + act.ShouldThrow(); } public static IEnumerable Data() => diff --git a/EncryptedConfigValue.Cli.Test/EncryptedConfigValue.Cli.Test.csproj b/EncryptedConfigValue.Cli.Test/EncryptedConfigValue.Cli.Test.csproj index 6432450..dac96a2 100644 --- a/EncryptedConfigValue.Cli.Test/EncryptedConfigValue.Cli.Test.csproj +++ b/EncryptedConfigValue.Cli.Test/EncryptedConfigValue.Cli.Test.csproj @@ -15,8 +15,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/EncryptedConfigValue.Cli.Test/GenerateKeyCommandTest.cs b/EncryptedConfigValue.Cli.Test/GenerateKeyCommandTest.cs index d6c821d..2752a52 100644 --- a/EncryptedConfigValue.Cli.Test/GenerateKeyCommandTest.cs +++ b/EncryptedConfigValue.Cli.Test/GenerateKeyCommandTest.cs @@ -1,6 +1,6 @@ using EncryptedConfigValue.Crypto; using EncryptedConfigValue.Crypto.Algorithm; -using FluentAssertions; +using Shouldly; using System; using System.Collections.Generic; using System.IO; @@ -42,7 +42,7 @@ public void WeGenerateAValidKey(Algorithm algorithm) command.Execute("--algorithm", algorithm.ToString(), "--file", tempFilePath); var keyPair = KeyFileUtils.KeyPairFromPath(tempFilePath); - keyPair.EncryptionKey.Type.Algorithm.Should().BeEquivalentTo(algorithm); + keyPair.EncryptionKey.Type.Algorithm.ShouldBeEquivalentTo(algorithm); } [Fact] @@ -62,8 +62,8 @@ public void WeDoNotOverwriteAnExistingKeyfile() { command.Execute("--algorithm", algorithm.ToString(), "--file", tempFilePath); }; - - act.Should().Throw().WithMessage("*already exists*"); + var ex = Should.Throw(act); + ex.Message.ShouldMatch("(.*)already exists*"); } public static IEnumerable Data() => diff --git a/EncryptedConfigValue.Module.Test/DecryptingVariableSubstitutorTest.cs b/EncryptedConfigValue.Module.Test/DecryptingVariableSubstitutorTest.cs index 36e85b3..844f13a 100644 --- a/EncryptedConfigValue.Module.Test/DecryptingVariableSubstitutorTest.cs +++ b/EncryptedConfigValue.Module.Test/DecryptingVariableSubstitutorTest.cs @@ -2,7 +2,7 @@ using EncryptedConfigValue.Crypto.Algorithm; using EncryptedConfigValue.Crypto.Util; using EncryptedConfigValue.Module; -using FluentAssertions; +using Shouldly; using System; using System.Collections.Generic; using System.IO; @@ -63,7 +63,7 @@ public void Dispose() public void ConstantsAreNotModified() { substitutor.TryReplace("abc", out var output); - output.Should().BeEquivalentTo("abc"); + output.ShouldBeEquivalentTo("abc"); } [Fact] @@ -76,8 +76,8 @@ public void InvalidEncryptedVariablesThrowStringSubstitutionException() } catch (StringSubstitutionException e) { - e.Value.Should().BeEquivalentTo("enc:invalid-contents"); - e.Field.Should().BeEmpty(); + e.Value.ShouldBeEquivalentTo("enc:invalid-contents"); + e.Field.ShouldBeEmpty(); } } @@ -85,21 +85,21 @@ public void InvalidEncryptedVariablesThrowStringSubstitutionException() public void NonEncryptedVariablesAreNotModified() { substitutor.TryReplace("${abc}", out var output); - output.Should().BeEquivalentTo("${abc}"); + output.ShouldBeEquivalentTo("${abc}"); } [Fact] public void VariableIsDecrypted() { substitutor.TryReplace("${" + Encrypt("abc") + "}", out var output); - output.Should().BeEquivalentTo("abc"); + output.ShouldBeEquivalentTo("abc"); } [Fact] public void VariableIsDecryptedWithRegex() { substitutor.TryReplace("${" + Encrypt("$5") + "}", out var output); - output.Should().Be("$5"); + output.ShouldBe("$5"); } [Fact] @@ -110,7 +110,7 @@ public void DecryptsMultiple() var hello = "${" + Encrypt("enc:hello") + "}"; var source = abc + ":" + def + '.' + hello; substitutor.TryReplace(source, out var output); - output.Should().Be("abc:def.enc:hello"); + output.ShouldBe("abc:def.enc:hello"); } [Fact] @@ -120,7 +120,7 @@ public void DecryptsWithPlaceholders() var def = "${" + Encrypt("${enc:test}") + "}"; var source = abc + ":" + def; substitutor.TryReplace(source, out var output); - output.Should().BeEquivalentTo("abc:${enc:test}"); + output.ShouldBeEquivalentTo("abc:${enc:test}"); } [SkippableTheory] @@ -131,7 +131,7 @@ public void PropertyTestValues(string plaintext) Skip.If(Encoding.UTF8.GetBytes(plaintext).Length > 190); EnsureTestKeysExist(); substitutor.TryReplace("${" + Encrypt(plaintext) + "}", out var output); - output.Should().BeEquivalentTo(plaintext); + output.ShouldBeEquivalentTo(plaintext); } public static IEnumerable PropertyTestData(int tries) diff --git a/EncryptedConfigValue.Module.Test/EncryptedConfigValue.Module.Test.csproj b/EncryptedConfigValue.Module.Test/EncryptedConfigValue.Module.Test.csproj index 5390dbb..f758bea 100644 --- a/EncryptedConfigValue.Module.Test/EncryptedConfigValue.Module.Test.csproj +++ b/EncryptedConfigValue.Module.Test/EncryptedConfigValue.Module.Test.csproj @@ -7,11 +7,11 @@ - + - + diff --git a/EncryptedConfigValue.Test/Aes/AesKeyTest.cs b/EncryptedConfigValue.Test/Aes/AesKeyTest.cs index 5488084..cbdae02 100644 --- a/EncryptedConfigValue.Test/Aes/AesKeyTest.cs +++ b/EncryptedConfigValue.Test/Aes/AesKeyTest.cs @@ -1,5 +1,5 @@ using EncryptedConfigValue.Crypto.Algorithm.Aes; -using FluentAssertions; +using Shouldly; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; using Xunit; @@ -19,7 +19,7 @@ public static byte[] NewSecretKey() public void TestEqualityFromSameSecretKey() { var secretKey = NewSecretKey(); - new AesKey(secretKey).Should().BeEquivalentTo(new AesKey(secretKey)); + new AesKey(secretKey).ShouldBeEquivalentTo(new AesKey(secretKey)); } } } diff --git a/EncryptedConfigValue.Test/AlgorithmTest.cs b/EncryptedConfigValue.Test/AlgorithmTest.cs index ec75bab..7fdd776 100644 --- a/EncryptedConfigValue.Test/AlgorithmTest.cs +++ b/EncryptedConfigValue.Test/AlgorithmTest.cs @@ -1,5 +1,5 @@ using EncryptedConfigValue.Crypto.Algorithm; -using FluentAssertions; +using Shouldly; using System.Collections.Generic; using Xunit; @@ -15,7 +15,8 @@ internal void WeGenerateRandomKeys(Algorithm algorithm) { var keyPair1 = algorithm.NewKeyPair(); var keyPair2 = algorithm.NewKeyPair(); - keyPair1.Should().NotBe(keyPair2).And.NotBeSameAs(keyPair2); + keyPair1.ShouldNotBe(keyPair2); + keyPair1.ShouldNotBeSameAs(keyPair2); } [Theory] @@ -26,7 +27,7 @@ internal void WeCanEncryptAndDecrypt(Algorithm algorithm) var encryptedValue = algorithm.NewEncrypter().Encrypt(keyPair.EncryptionKey, plaintext); var decryptionKey = keyPair.DecryptionKey; var decrypted = encryptedValue.Decrypt(decryptionKey); - decrypted.Should().Be(plaintext); + decrypted.ShouldBe(plaintext); } [Theory] @@ -38,17 +39,18 @@ internal void TheSameStringEncryptsToDifferentCiphertexts(Algorithm algorithm) var encrypted2 = algorithm.NewEncrypter().Encrypt(keyPair.EncryptionKey, plaintext); // we don't want to leak that certain values are the same - encrypted1.Should().NotBe(encrypted2).And.NotBeSameAs(encrypted2); + encrypted1.ShouldNotBe(encrypted2); + encrypted1.ShouldNotBeSameAs(encrypted2); // paranoia, let's say the equals method is badly behaved - encrypted1.GetHashCode().Should().NotBe(encrypted2.GetHashCode()); + encrypted1.GetHashCode().ShouldNotBe(encrypted2.GetHashCode()); // we should naturally decrypt back to the same thing - the plaintext var decryptionKey = keyPair.DecryptionKey; var decryptedString1 = encrypted1.Decrypt(decryptionKey); var decryptedString2 = encrypted2.Decrypt(decryptionKey); - decryptedString1.Should().Be(plaintext); - decryptedString2.Should().Be(plaintext); + decryptedString1.ShouldBe(plaintext); + decryptedString2.ShouldBe(plaintext); } public static IEnumerable Data() => new[] diff --git a/EncryptedConfigValue.Test/EncryptedConfigValue.Test.csproj b/EncryptedConfigValue.Test/EncryptedConfigValue.Test.csproj index 8ae7d88..50d8527 100644 --- a/EncryptedConfigValue.Test/EncryptedConfigValue.Test.csproj +++ b/EncryptedConfigValue.Test/EncryptedConfigValue.Test.csproj @@ -7,7 +7,7 @@ - + diff --git a/EncryptedConfigValue.Test/EncryptedValueCompatTest.cs b/EncryptedConfigValue.Test/EncryptedValueCompatTest.cs index e461a7c..9fcdabf 100644 --- a/EncryptedConfigValue.Test/EncryptedValueCompatTest.cs +++ b/EncryptedConfigValue.Test/EncryptedValueCompatTest.cs @@ -1,5 +1,5 @@ using EncryptedConfigValue.Crypto; -using FluentAssertions; +using Shouldly; using Xunit; namespace EncryptedConfigValue.Test @@ -13,7 +13,7 @@ public void TestAesLegacyValue() EncryptedValue ev = EncryptedValue.FromString( "enc:QjR4AHIYoIzvjEHf53XETM3QYnCl1mgFYC51Q7x4ebwM+h3PHVqSt/1un/+KvpJ2mZfMH0tifu+htRVxEPyXmt88lyKB83Npe" + "sNJEoLFLL+wBWCkppaLRuc/1w=="); - ev.Decrypt(kwa).Should().BeEquivalentTo("my secret. I don't want anyone to know this"); + ev.Decrypt(kwa).ShouldBeEquivalentTo("my secret. I don't want anyone to know this"); } [Fact] @@ -23,7 +23,7 @@ public void TestAesNewValue() EncryptedValue ev = EncryptedValue.FromString( "enc:eyJ0eXBlIjoiQUVTIiwibW9kZSI6IkdDTSIsImNpcGhlcnRleHQiOiJNOTRrSXlvYTUrMloiLCJpdiI6InVBR3FSbFA5d2l6c" + "GRCMHoiLCJ0YWciOiJBQ1N1ekR3VFVMb21zanhwRk1rWUtBPT0ifQ=="); - ev.Decrypt(kwa).Should().BeEquivalentTo("plaintext"); + ev.Decrypt(kwa).ShouldBeEquivalentTo("plaintext"); } [Fact] @@ -51,7 +51,7 @@ public void TestRsaLegacyValue() + "qrb08s46hodTPDLU76JNrtaxlCssXYxFN/Ni8k95pKauwPxRfvTP0SUf7o9rsZrY6LdV9+M3y6mNrEIKevAZQZtNmvX" + "riclQGV1CwRzV/0sNVuTfNqNw0lDsI4hcvC26DhLrXla8jCUiKEYDFAqVr2DaTwtV3htxtCB36Jk6Lg5abdcc9B/ZqV" + "7lfUIddGEuXFzhz8KIIGtwVVXqis15Dw1ECSNJhicHZp43vSYN9y9NJTnvTAhCQ=="); - ev.Decrypt(kwa).Should().BeEquivalentTo("my secret. I don't want anyone to know this"); + ev.Decrypt(kwa).ShouldBeEquivalentTo("my secret. I don't want anyone to know this"); } [Fact] @@ -83,7 +83,7 @@ public void TestRsaNewValue() + "xROEVMNUVBWjJoNytscVY5Rmp0emxBdWtxbUp4OEVwMGhJbGhPUjIzNndJcWQwZHpBVzZnODYybENLb1Nob0dvS04y" + "dHR5alU2TURRUWo0a0hBNFdCbTBOdm9XREZHN1p3T1ozbDIwVnY3R1ZRPT0iLCJvYWVwLWFsZyI6IlNIQS0yNTYiLC" + "JtZGYxLWFsZyI6IlNIQS0yNTYifQ=="); - ev.Decrypt(kwa).Should().BeEquivalentTo("plaintext"); + ev.Decrypt(kwa).ShouldBeEquivalentTo("plaintext"); } } } diff --git a/EncryptedConfigValue.Test/EncryptedValueTest.cs b/EncryptedConfigValue.Test/EncryptedValueTest.cs index e6aea7a..01cb2d2 100644 --- a/EncryptedConfigValue.Test/EncryptedValueTest.cs +++ b/EncryptedConfigValue.Test/EncryptedValueTest.cs @@ -1,6 +1,6 @@ using EncryptedConfigValue.Crypto; using EncryptedConfigValue.Crypto.Algorithm; -using FluentAssertions; +using Shouldly; using Org.BouncyCastle.Crypto; using System; using System.Collections.Generic; @@ -49,7 +49,7 @@ internal void WeCanConstructFromAValidLegacyAesString() + "1un/+KvpJ2mZfMH0tifu+htRVxEPyXmt88lyKB83NpesNJEoLFLL+wBWCkppaLRuc/1w=="; var encryptedValue = EncryptedValue.FromString(valid); - encryptedValue.Decrypt(aesKey).Should().Be(plaintext); + encryptedValue.Decrypt(aesKey).ShouldBe(plaintext); } [Fact] @@ -60,7 +60,7 @@ internal void WeCanConstructFromAValidString() + "K1RXSkZwckpHWGdUVXVRRmx4Nnd0a0lwNVFUcE1RPT0iLCJ0YWciOiJZTUNURlY2b2dsemxwV3FOVlp3YVp3PT0ifQ=="; EncryptedValue encryptedValue = EncryptedValue.FromString(valid); - encryptedValue.Decrypt(aesKey).Should().Be(plaintext); + encryptedValue.Decrypt(aesKey).ShouldBe(plaintext); } [Fact] @@ -73,7 +73,7 @@ public void WeCanConstructFromAValidRsaString() + "qVr2DaTwtV3htxtCB36Jk6Lg5abdcc9B/ZqV7lfUIddGEuXFzhz8KIIGtwVVXqi" + "s15Dw1ECSNJhicHZp43vSYN9y9NJTnvTAhCQ=="; EncryptedValue encryptedValue = EncryptedValue.FromString(valid); - encryptedValue.Decrypt(rsaPrivKey).Should().Be(plaintext); + encryptedValue.Decrypt(rsaPrivKey).ShouldBe(plaintext); } [Fact] @@ -82,7 +82,7 @@ internal void WeCanDecryptValueEncryptedUsingExistingRsaKey() EncryptedValue encryptedValue = Algorithm.RSA .NewEncrypter() .Encrypt(rsaPubKey, plaintext); - encryptedValue.Decrypt(rsaPrivKey).Should().Be(plaintext); + encryptedValue.Decrypt(rsaPrivKey).ShouldBe(plaintext); } [Fact] @@ -90,7 +90,7 @@ internal void WeFailToConstructWithInvalidPrefix() { var invalid = "anc:TCkE/OT7xsKWqP4SRNBEj54Pk7wDMQzMGJtX90toFuGeejM/LQBDTZ8hEaKQt/3i"; var act = () => EncryptedValue.FromString(invalid); - act.Should().Throw(); // throws + act.ShouldThrow(); // throws } [Fact] @@ -98,7 +98,7 @@ internal void WeFailToConstructWithAnInvalidEncryptedValue() { var invalid = "enc:verysecret^^"; var act = () => EncryptedValue.FromString(invalid); // throws if suffix is not a base64-encoded string - act.Should().Throw(); + act.ShouldThrow(); } [Theory] @@ -110,9 +110,8 @@ internal void WeCannotDecryptWithTheWrongKey(Algorithm algorithm) var encryptedValue = algorithm.NewEncrypter().Encrypt(keyPair.EncryptionKey, plaintext); var decryptionKey = otherKeyPair.DecryptionKey; var act = () => encryptedValue.Decrypt(decryptionKey); // throws - act.Should() - .Throw() - .Where(e => e is InvalidCipherTextException || e is DataLengthException); + var ex = Should.Throw(act); + (ex is InvalidCipherTextException || ex is DataLengthException).ShouldBeTrue(); } [Theory] @@ -123,7 +122,7 @@ internal void WeCanDecryptAValue(Algorithm algorithm) var encryptedValue = algorithm.NewEncrypter().Encrypt(keyPair.EncryptionKey, plaintext); var decryptionKey = keyPair.DecryptionKey; var decryptedValue = encryptedValue.Decrypt(decryptionKey); - decryptedValue.Should().Be(plaintext); + decryptedValue.ShouldBe(plaintext); } [Theory] @@ -155,7 +154,7 @@ internal void WeCanDecryptUsingAKeyFile(Algorithm algorithm) Environment.SetEnvironmentVariable(KeyFileUtils.KeyPathProperty, testKeyPath); var encryptedValue = algorithm.NewEncrypter().Encrypt(keyPair.EncryptionKey, plaintext); var decryptedValue = encryptedValue.Decrypt(keyPair.DecryptionKey); - decryptedValue.Should().Be(plaintext); + decryptedValue.ShouldBe(plaintext); } public static IEnumerable Data() => diff --git a/EncryptedConfigValue.Test/KeyWithTypeTest.cs b/EncryptedConfigValue.Test/KeyWithTypeTest.cs index 0eac840..f1879eb 100644 --- a/EncryptedConfigValue.Test/KeyWithTypeTest.cs +++ b/EncryptedConfigValue.Test/KeyWithTypeTest.cs @@ -1,5 +1,5 @@ using EncryptedConfigValue.Crypto; -using FluentAssertions; +using Shouldly; using System.Text.Json; using Xunit; @@ -18,10 +18,10 @@ public void TestSerialization() new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); var expectedSerialization = string.Format("\"{0}\"", kwtString); - serialized.Should().BeEquivalentTo(expectedSerialization); + serialized.ShouldBeEquivalentTo(expectedSerialization); var deserialized = JsonSerializer.Deserialize(serialized); - deserialized!.ToString().Should().BeEquivalentTo(kwt.ToString()); + deserialized!.ToString().ShouldBeEquivalentTo(kwt.ToString()); } } } diff --git a/EncryptedConfigValue.Test/Rsa/RsaPrivateKeyTest.cs b/EncryptedConfigValue.Test/Rsa/RsaPrivateKeyTest.cs index ec13731..111aa65 100644 --- a/EncryptedConfigValue.Test/Rsa/RsaPrivateKeyTest.cs +++ b/EncryptedConfigValue.Test/Rsa/RsaPrivateKeyTest.cs @@ -1,6 +1,6 @@ using EncryptedConfigValue.Crypto.Algorithm; using EncryptedConfigValue.Crypto.Algorithm.Rsa; -using FluentAssertions; +using Shouldly; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; @@ -21,7 +21,7 @@ public static AsymmetricCipherKeyPair GenerateKeyPair() public void TestEqualityFromSamePrivateKey() { var privateKey = (RsaKeyParameters)GenerateKeyPair().Private; - new RsaPrivateKey(privateKey).Should().BeEquivalentTo(new RsaPrivateKey(privateKey)); + new RsaPrivateKey(privateKey).ShouldBeEquivalentTo(new RsaPrivateKey(privateKey)); } } } diff --git a/EncryptedConfigValue.Test/Rsa/RsaPublicKeyTest.cs b/EncryptedConfigValue.Test/Rsa/RsaPublicKeyTest.cs index ec37a8a..5f695a6 100644 --- a/EncryptedConfigValue.Test/Rsa/RsaPublicKeyTest.cs +++ b/EncryptedConfigValue.Test/Rsa/RsaPublicKeyTest.cs @@ -3,7 +3,7 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Security; using Xunit; -using FluentAssertions; +using Shouldly; using EncryptedConfigValue.Crypto.Algorithm; namespace EncryptedConfigValue.Test.Rsa @@ -21,7 +21,7 @@ public static AsymmetricCipherKeyPair GenerateKeyPair() public void TestEqualityFromSamePublicKey() { var privateKey = (RsaKeyParameters)GenerateKeyPair().Public; - new RsaPublicKey(privateKey).Should().BeEquivalentTo(new RsaPublicKey(privateKey)); + new RsaPublicKey(privateKey).ShouldBeEquivalentTo(new RsaPublicKey(privateKey)); } } } diff --git a/EncryptedConfigValue.Test/Util/StringSubstitutionExceptionTest.cs b/EncryptedConfigValue.Test/Util/StringSubstitutionExceptionTest.cs index c71da1f..9aece9e 100644 --- a/EncryptedConfigValue.Test/Util/StringSubstitutionExceptionTest.cs +++ b/EncryptedConfigValue.Test/Util/StringSubstitutionExceptionTest.cs @@ -1,5 +1,5 @@ using EncryptedConfigValue.Crypto.Util; -using FluentAssertions; +using Shouldly; using NSubstitute; using System; using Xunit; @@ -70,9 +70,9 @@ public void TestSingleExtendArrayBetweenDoubleField() private void AssertException(StringSubstitutionException exception, String field) { - exception.Value.Should().BeEquivalentTo(VALUE); - exception.Field.Should().BeEquivalentTo(field); - exception.Cause.Should().BeEquivalentTo(cause); + exception.Value.ShouldBeEquivalentTo(VALUE); + exception.Field.ShouldBeEquivalentTo(field); + exception.Cause.ShouldBeEquivalentTo(cause); } } }