using System; using System.Threading.Tasks; using Centron.Common.TextCoding; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.CryptoControls; public class CryptoControlTests : CentronTest { public CryptoControlTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } [Theory] [InlineData(0, "Irgendein Text den ich verschlüsseln will, zB ein Connection-String!")] [InlineData(1, "")] [InlineData(2, " ")] [InlineData(3, "\t")] [InlineData(4, "\r\n")] [InlineData(5, null)] [InlineData(6, "245050016053193207141108203017074108161195181234")] public void Encrypt_Decrypt_Text(int counter, string input) { var encryptedText = CryptoControl.EncryptToString(input); this.Verifier.Verify($"EncryptedText_{counter}", encryptedText); var decryptedText = CryptoControl.DecryptString(encryptedText); var expectedText = input is null ? "" // The Encrypt-Decrypt-Dance will return "" for NULL input instead : input; Assert.Equal(expectedText, decryptedText); } [Fact] public void Decrypt_Text_InvalidDataReturnsEmptyString() { var ex = Assert.Throws(() => CryptoControl.DecryptString("Haha")); Assert.Equal("The input string 'Hah' was not in a correct format.", ex.Message); } [Fact] public void Multi_Threading_Test() { Parallel.For(0, 10000, i => { var input = "Hallo"; var encrypted = CryptoControl.EncryptToString(input); var decrypted = CryptoControl.DecryptString(encrypted); Assert.Equal(input, decrypted); }); } }