public void DecryptWhenGivenLotionClearTextValueExpectResult()
        {
            var mockBase64Converter = new Mock <IBase64Converter>(MockBehavior.Strict);

            mockBase64Converter.Setup(m => m.FromBase64String(It.IsAny <string>())).Returns((string input) =>
            {
                return(Convert.FromBase64String(input));
            }).Verifiable();

            var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict);

            mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) =>
            {
                return(UTF8Encoding.UTF8.GetBytes(input));
            }).Verifiable();
            mockByteConverter.Setup(m => m.ConvertToString(It.IsAny <IReadOnlyCollection <byte> >())).Returns((IReadOnlyCollection <byte> input) =>
            {
                return(UTF8Encoding.UTF8.GetString(input.ToArray()));
            }).Verifiable();

            ICryptDecryptProvider decrypt = Factory.AES256PlusHMACPump.NewInstance(
                base64Converter: mockBase64Converter.Object,
                byteConverter: mockByteConverter.Object,
                cryptKeyValue: MockCryptKeyValue,
                hmacSaltValue: MockHmacSaltValue
                );

            string actual = decrypt.Decrypt(cipherText: "5lA6sJloOSSLp1nlSERxucKHC0k2cagNe7FPk+YBBJhnyd0g1yFebxqZzPWsNI4v+PD0CaViHnUTROyWjgdGNA==");

            Assert.IsNotNull(actual);
            Assert.AreEqual(MockLotionClearTextValue, actual);

            mockByteConverter.Verify();
            mockBase64Converter.Verify();
        }
        public void DecryptWhenGivenLoroIpsumClearTextValueExpectResult()
        {
            var mockBase64Converter = new Mock <IBase64Converter>(MockBehavior.Strict);

            mockBase64Converter.Setup(m => m.FromBase64String(It.IsAny <string>())).Returns((string input) =>
            {
                return(Convert.FromBase64String(input));
            }).Verifiable();

            var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict);

            mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) =>
            {
                return(UTF8Encoding.UTF8.GetBytes(input));
            }).Verifiable();
            mockByteConverter.Setup(m => m.ConvertToString(It.IsAny <IReadOnlyCollection <byte> >())).Returns((IReadOnlyCollection <byte> input) =>
            {
                return(UTF8Encoding.UTF8.GetString(input.ToArray()));
            }).Verifiable();

            ICryptDecryptProvider decrypt = Factory.AES256PlusHMACPump.NewInstance(
                base64Converter: mockBase64Converter.Object,
                byteConverter: mockByteConverter.Object,
                cryptKeyValue: MockCryptKeyValue,
                hmacSaltValue: MockHmacSaltValue
                );

            string actual = decrypt.Decrypt(cipherText: "6sPrdQTiPsOTiSfVeHrC+A6i3HFqLzzfa/sUKHYSiNyoCbomQKVbu9eUucmI0Y63mW1E1A3aX/q2etkd37ssB7fbZ7ZzR/Upcg7qUIH0C0N/UufUQfTbbrpOXdAy9oFXJBxusXypoFZZxQ1lJW3b58vUbiWhNr09P/GWnkJBNbhLhGD+XUmvgBWxU7E12dsCEXw8A3CdfOnqwIcik8VUqjHqZtjhxryoIxFKJ7vtuwahqka1sXPQQ6+MaXPTIrcZwAex1gr47gH92SdwrSCtJv5vZwXtej0jQEOHPJKUnP34YPa55f+seT6lJBxtjmvyeRpNlts5dxqXRRrTeD+vGQRtnh3xqICHpJJJaHY8U6/ohumhvmCs6sRfqJApUewO");

            Assert.IsNotNull(actual);
            Assert.AreEqual(MockLoroIpsumClearTextValue, actual);

            mockByteConverter.Verify();
            mockBase64Converter.Verify();
        }
        public void DecryptWhenGivenAbcClearTextValueExpectResult()
        {
            var mockBase64Converter = new Mock <IBase64Converter>(MockBehavior.Strict);

            mockBase64Converter.Setup(m => m.FromBase64String(It.IsAny <string>())).Returns((string input) =>
            {
                return(Convert.FromBase64String(input));
            }).Verifiable();

            var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict);

            mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) =>
            {
                return(UTF8Encoding.UTF8.GetBytes(input));
            }).Verifiable();
            mockByteConverter.Setup(m => m.ConvertToString(It.IsAny <IReadOnlyCollection <byte> >())).Returns((IReadOnlyCollection <byte> input) =>
            {
                return(UTF8Encoding.UTF8.GetString(input.ToArray()));
            }).Verifiable();

            ICryptDecryptProvider decrypt = Factory.AES256PlusHMACPump.NewInstance(
                base64Converter: mockBase64Converter.Object,
                byteConverter: mockByteConverter.Object,
                cryptKeyValue: MockCryptKeyValue,
                hmacSaltValue: MockHmacSaltValue
                );

            string actual = decrypt.Decrypt(cipherText: "TTTuaZk5ehdGu34qzAmJoAQkjDQw2HfYE1bTlx7M4eOuMT6f0YpNbhG0o6sLWz04iLX+OwWMhGi/GFJBi7PdXw==");

            Assert.IsNotNull(actual);
            Assert.AreEqual(MockAbcClearTextValue, actual);

            mockByteConverter.Verify();
            mockBase64Converter.Verify();
        }
        public void DecryptWhenGivenNullExpectArgumentNullException()
        {
            //  arrange
            ICryptDecryptProvider crypt = Factory.EchoPump.NewInstance();

            //  act
            Assert.Throws <ArgumentNullException>(() => crypt.Decrypt(null));
        }
        public void DecryptWhenGivenSomeValueExpectSomeValue()
        {
            //  arrange
            ICryptDecryptProvider crypt = Factory.EchoPump.NewInstance();

            //  act
            string actual = crypt.Decrypt("echo");

            //  assert
            Assert.IsNotNull(actual);
            Assert.AreEqual("echo", actual);
        }
        public void CryptDecryptWhenGivenLotionClearTextValueExpectResult()
        {
            var mockBase64Converter = new Mock <IBase64Converter>(MockBehavior.Strict);

            mockBase64Converter.Setup(m => m.ToBase64String(It.IsAny <IReadOnlyCollection <byte> >())).Returns((IReadOnlyCollection <byte> input) =>
            {
                return(Convert.ToBase64String(input.ToArray()));
            }).Verifiable();
            mockBase64Converter.Setup(m => m.FromBase64String(It.IsAny <string>())).Returns((string input) =>
            {
                return(Convert.FromBase64String(input));
            }).Verifiable();

            var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict);

            mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) =>
            {
                return(UTF8Encoding.UTF8.GetBytes(input));
            }).Verifiable();
            mockByteConverter.Setup(m => m.ConvertToString(It.IsAny <IReadOnlyCollection <byte> >())).Returns((IReadOnlyCollection <byte> input) =>
            {
                return(UTF8Encoding.UTF8.GetString(input.ToArray()));
            }).Verifiable();

            ICryptProvider crypt = Factory.AES256PlusHMACPump.NewInstance(
                base64Converter: mockBase64Converter.Object,
                byteConverter: mockByteConverter.Object,
                cryptKeyValue: MockCryptKeyValue,
                hmacSaltValue: MockHmacSaltValue
                ) as ICryptProvider;

            string cipherText = crypt.Crypt(clearText: MockLotionClearTextValue);

            ICryptDecryptProvider decrypt = Factory.AES256PlusHMACPump.NewInstance(
                base64Converter: mockBase64Converter.Object,
                byteConverter: mockByteConverter.Object,
                cryptKeyValue: MockCryptKeyValue,
                hmacSaltValue: MockHmacSaltValue
                );

            string actual = decrypt.Decrypt(cipherText: cipherText);

            Assert.IsNotNull(actual);
            Assert.AreEqual(MockLotionClearTextValue, actual);

            mockByteConverter.Verify();
            mockBase64Converter.Verify();
        }