public void CryptWhenGivenLotionClearTextValueExpectResult() { 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(); var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict); mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) => { return(UTF8Encoding.UTF8.GetBytes(input)); }).Verifiable(); ICryptProvider crypt = Factory.AES256PlusHMACPump.NewInstance( base64Converter: mockBase64Converter.Object, byteConverter: mockByteConverter.Object, cryptKeyValue: MockCryptKeyValue, hmacSaltValue: MockHmacSaltValue ) as ICryptProvider; string actual = crypt.Crypt(clearText: MockLotionClearTextValue); Assert.IsNotNull(actual); mockByteConverter.Verify(); mockBase64Converter.Verify(); }
public void CryptWhenGivenNullExpectArgumentNullException() { // arrange ICryptProvider crypt = Factory.EchoPump.NewInstance() as ICryptProvider; // act Assert.Throws <ArgumentNullException>(() => crypt.Crypt(null)); }
public void CryptWhenGivenNullClearTextExpectArgumentNullException() { ICryptProvider crypt = Factory.AES256PlusHMACPump.NewInstance( base64Converter: new Mock <IBase64Converter>(MockBehavior.Strict).Object, byteConverter: new Mock <IByteConverter>(MockBehavior.Strict).Object, cryptKeyValue: MockCryptKeyValue, hmacSaltValue: MockHmacSaltValue ) as ICryptProvider; Assert.Throws <ArgumentNullException>(() => crypt.Crypt(clearText: null)); }
public void CryptWhenGivenSomeValueExpectSomeValue() { // arrange ICryptProvider crypt = Factory.EchoPump.NewInstance() as ICryptProvider; // act string actual = crypt.Crypt("echo"); // assert Assert.IsNotNull(actual); Assert.AreEqual("echo", actual); }
public void CryptWhenGivenEmptyClearTextExpectArgumentException() { var mockByteConverter = new Mock <IByteConverter>(MockBehavior.Strict); mockByteConverter.Setup(m => m.ConvertToBytes(It.IsAny <string>())).Returns((string input) => { return(UTF8Encoding.UTF8.GetBytes(input)); }).Verifiable(); ICryptProvider crypt = Factory.AES256PlusHMACPump.NewInstance( base64Converter: new Mock <IBase64Converter>(MockBehavior.Strict).Object, byteConverter: mockByteConverter.Object, cryptKeyValue: MockCryptKeyValue, hmacSaltValue: MockHmacSaltValue ) as ICryptProvider; Assert.Throws <ArgumentException>(() => crypt.Crypt(clearText: string.Empty)); }
public AccountService(ICryptProvider cryptProvider, IDateProvider dateProvider, IAccountRepository accountRepository) { if (cryptProvider == null) { throw new ArgumentNullException("AccountService:cryptProvider"); } _cryptProvider = cryptProvider; if (dateProvider == null) { throw new ArgumentNullException("AccountService:dateProvider"); } _dateProvider = dateProvider; if (accountRepository == null) { throw new ArgumentNullException("AccountService:accountRepository"); } _accountRepository = accountRepository; }
public bool ValidatePassword(ICryptProvider cryptProvider, string password) { var compareHash = cryptProvider.Hash(password, Salt); return(Password == compareHash); }
protected FlexiWebClient(ICryptProvider crypt, IRequestProvider requestProvider, IJsonProvider jsonProvider) { _cryptProvider = crypt; _requestProvider = requestProvider; _jsonProvider = jsonProvider; }