void _matchAndReplaceWhereAppropriate(string matchingString, string nonMatchingString, string pieceToReplace) { //------------Setup for test-------------------------- var upgrader = new EncryptionResourceUpgrader(); //------------Execute Test--------------------------- //------------Assert Results------------------------- string output = upgrader.EncryptPasswordsAndConnectionStrings(matchingString); output.Should().NotBeNullOrEmpty(); output.Should().NotBe(matchingString); output.Should().NotContain(pieceToReplace); output = upgrader.EncryptPasswordsAndConnectionStrings(nonMatchingString); output.Should().NotBeNullOrEmpty(); output.Should().Be(nonMatchingString); output.Should().Contain(pieceToReplace); }
// ReSharper disable InconsistentNaming public void EncryptionResourceUpgrader_Upgrade_CanDecrypt() { //------------Setup for test-------------------------- var upgrader = new EncryptionResourceUpgrader(); Regex cs = new Regex(@"ConnectionString=""([^""]+)"""); //------------Execute Test--------------------------- //------------Assert Results------------------------- string output = upgrader.EncryptSourceConnectionStrings(_beforeContainingSource); output.Should().NotBeNullOrEmpty(); output.Should().NotBe(_beforeContainingSource); output.Should().NotContain(_connectionString); Match m = cs.Match(output); m.Success.Should().BeTrue(); m.Groups.Count.Should().BeGreaterOrEqualTo(1); m.Groups[1].Success.Should().BeTrue(); string x = m.Groups[1].Value; DpapiWrapper.Decrypt(x).Should().Be(_connectionString); }
// ReSharper disable InconsistentNaming public void EncryptionResourceUpgrader_TwiceUpgrade_DoesNotEncrypt() { //------------Setup for test-------------------------- var upgrader = new EncryptionResourceUpgrader(); Regex cs = new Regex(@"ConnectionString=""([^""]+)"""); //------------Execute Test--------------------------- //------------Assert Results------------------------- string output = upgrader.EncryptSourceConnectionStrings(_beforeContainingSource); output.Should().NotBeNullOrEmpty(); output.Should().NotBe(_beforeContainingSource); output.Should().NotContain(_connectionString); string output2 = upgrader.EncryptSourceConnectionStrings(output); output.Should().NotBeNullOrEmpty(); output2.Should().Be(output); }