public void ValueIsCorrectlyDecrypted() { // Arrange var newCardNo = RandomNumbers(14); var credit = new CreditCard { CardNumber = newCardNo, CardType = "TestCard", ExpMonth = byte.Parse(RandomNumbers(1)), ExpYear = short.Parse("20" + RandomNumbers(2)), ModifiedDate = DateTime.UtcNow }; // Act while (_adventureWorksContext.CreditCards.Any(c => c.CardNumber == newCardNo)) { newCardNo = RandomNumbers(14); credit.CardNumber = newCardNo; } _adventureWorksContext.CreditCards.Add(credit); _adventureWorksContext.SaveChanges(); RefreshContext(_adventureWorksContext.CreditCards); var encryptedValue = DbContextOperations <AdventureWorks2017Entities> .EncryptValue(newCardNo, 19273); var decryptedValue = DbContextOperations <AdventureWorks2017Entities> .DecryptValue(encryptedValue, 19273); // Assert Assert.Equal(newCardNo, decryptedValue); // Reverse _adventureWorksContext.CreditCards.Remove(_adventureWorksContext.CreditCards.FirstOrDefault(c => c.CardNumber == newCardNo)); _adventureWorksContext.SaveChanges(); }
public void ValueIsCorrectlyEncrypted() { // Arrange var authHash = int.Parse(RandomNumbers(5)); var newCardNo = RandomNumbers(14); var encryptedValue = DbContextOperations <AdventureWorks2017Entities> .EncryptValue(newCardNo, authHash); var decryptedValue = DbContextOperations <AdventureWorks2017Entities> .DecryptValue(encryptedValue, authHash); // Assert Assert.Equal(newCardNo, decryptedValue); }