public void Checking_for_encryption_should_work()
        {
            /* Arrange */
            string source = "SomePlainValue";
            var crypto = new AesCryptoProvider();

            /* Act */
            bool isEncrypted = crypto.IsEncrypted(source);

            /* Assert */
            isEncrypted.Should().BeFalse();
        }
        public void Decrypting_data_that_could_not_possibly_be_encrypted_should_return_null()
        {
            /* Arrange */
            byte[] sourceTooSmall = new byte[4];
            var crypto = new AesCryptoProvider();

            /* Act */
            bool isEncrypted = crypto.IsEncrypted(sourceTooSmall);

            var decryptedVale = crypto.Decrypt(sourceTooSmall);

            /* Assert */
            decryptedVale.Should().BeNull();
            isEncrypted.Should().BeFalse();
        }
        public void Encrypting_and_decrypting_a_string_with_aes_should_work()
        {
            /* Arrange */
            string source = "SomeValue";
            var crypto = new AesCryptoProvider();

            /* Act */
            string encryptedValue = crypto.Encrypt(source);

            bool isEncrypted = crypto.IsEncrypted(encryptedValue);

            string decryptedVale = crypto.Decrypt(encryptedValue);

            /* Assert */
            encryptedValue.Should().NotBe(source);
            decryptedVale.Should().Be(source);
            isEncrypted.Should().BeTrue();
        }
        public void Setting_and_getting_encoding_on_crypto_should_work()
        {
            /* Arrange */
            var crypto1 = new AesCryptoProvider();
            var crypto2 = new AesCryptoProvider();

            /* Act */
            crypto1.Encoding = Encoding.Unicode;
            crypto2.Encoding = null;

            /* Assert */
            crypto1.Encoding.Should().Be(Encoding.Unicode);
            crypto2.Encoding.Should().Be(Encoding.UTF8);
        }
        public void Encrypting_with_one_provider_and_decrypting_with_another_should_not_work()
        {
            /* Arrange */
            string source = "SomeValue";
            var crypto1 = new AesCryptoProvider();
            var crypto2 = new TestCryptoProvider();

            /* Act */
            string encryptedValue = crypto1.Encrypt(source);

            bool isEncrypted = crypto2.IsEncrypted(encryptedValue);

            string decryptedVale = crypto2.Decrypt(encryptedValue);

            /* Assert */
            decryptedVale.Should().NotBe(source);
            isEncrypted.Should().BeFalse();
        }
        public void Encrypting_and_decrypting_null_or_empty_string_should_work()
        {
            /* Arrange */
            var crypto = new AesCryptoProvider();

            /* Act */
            string nullStringEncrypt = crypto.Encrypt((string)null);
            string emptyStringEncrypt = crypto.Encrypt(string.Empty);
            byte[] nullByteEncrypt = crypto.Encrypt((byte[])null);

            bool isEncryptedNullString = crypto.IsEncrypted((string)null);
            bool isEncryptedEmptyString = crypto.IsEncrypted(string.Empty);
            bool isEncryptedNullByte = crypto.IsEncrypted((byte[])null);

            string nullStringDecrypt = crypto.Decrypt((string)null);
            string emptyStringDecrypt = crypto.Decrypt(string.Empty);
            byte[] nullByteDecrypt = crypto.Decrypt((byte[])null);

            /* Assert */
            nullStringEncrypt.Should().BeNull();
            emptyStringEncrypt.Should().BeEmpty();
            nullByteEncrypt.Should().BeNull();

            isEncryptedNullString.Should().BeFalse();
            isEncryptedEmptyString.Should().BeFalse();
            isEncryptedNullByte.Should().BeFalse();

            nullStringDecrypt.Should().BeNull();
            emptyStringDecrypt.Should().BeEmpty();
            nullByteDecrypt.Should().BeNull();
        }