public void TestEncryptText_EncryptionSuccessful_ReturnsExpectedResult()
        {
            const string input = "ABC";
            var key = new byte[] { 8, 9, 10 };

            var bytesInput = Encoding.UTF8.GetBytes(input);
            var keyBase64 = Convert.ToBase64String(key);

            var encryptedData = new byte[] { 1, 2, 3 };
            var iv = new byte[] { 8, 9, 10 };

            var mockedAesWrapper = new Mock<IAesManagedWrapper>();
            mockedAesWrapper.Setup(aes => aes.Encrypt(bytesInput, key, out iv))
                .Returns(encryptedData);

            var target = new NfieldEncryptionUtility(mockedAesWrapper.Object);

            var result = target.EncryptText(input, keyBase64);

            Assert.Equal(Convert.ToBase64String(encryptedData), result.Data);
            Assert.Equal(Convert.ToBase64String(iv), result.InitializationVector);
        }
        public void TestEncryptText_KeyIsNull_Throws()
        {
            var target = new NfieldEncryptionUtility(new AesManagedWrapper());

            Assert.Throws <ArgumentNullException>(() => target.EncryptText("data", null));
        }
        public void TestEncryptText_EncryptionSuccessful_ReturnsExpectedResult()
        {
            const string input = "ABC";
            var key = new byte[] { 8, 9, 10 };

            var bytesInput = Encoding.UTF8.GetBytes(input);
            var keyBase64 = Convert.ToBase64String(key);

            var encryptedData = new byte[] {1, 2, 3};
            var iv = new byte[] { 8, 9, 10 };

            var mockedAesWrapper = new Mock<IAesManagedWrapper>();
            mockedAesWrapper.Setup(aes => aes.Encrypt(bytesInput, key, out iv))
                .Returns(encryptedData);

            var target = new NfieldEncryptionUtility(mockedAesWrapper.Object);

            var result = target.EncryptText(input, keyBase64);

            Assert.Equal(Convert.ToBase64String(encryptedData), result.Data);
            Assert.Equal(Convert.ToBase64String(iv), result.InitializationVector);
        }
 public void TestEncryptText_KeyIsNull_Throws()
 {
     var target = new NfieldEncryptionUtility(new AesManagedWrapper());
     Assert.Throws<ArgumentNullException>(() => target.EncryptText("data", null));
 }