I cannot get the below test to pass:
[Isolated]
[TestMethod]
public void UseSymCryptographyToSetAKey()
{
_symCrypt = new SymCryptography();
Isolate.WhenCalled(() => _symCrypt.Encrypt("Test")).WillReturn("jljljl");
Isolate.WhenCalled(() => _symCrypt.Key = "key").CallOriginal();
Isolate.WhenCalled(() => _symCrypt.Key).CallOriginal();
_adapter = new CryptographyAdapter(_symCrypt);
_adapter.SetKey("key");
var encrypted = _adapter.Encrypt("Test");
try
{
Assert.IsFalse(encrypted == "Test");
Isolate.Verify.WasCalledWithAnyArguments(() => _symCrypt.Key);
}
catch (System.Exception e)
{
Assert.Fail(e.ToString());
}
}
In the method call _adapter.Encrypt I have the following code:
public override string Encrypt(string value)
{
_symCrypt.Key = Key;
return _symCrypt.Encrypt(value);
}
Whatever I do, (also tried mocking up the SymCryptography) I get the error:
Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException was unhandled by user code
Message=Assert.Fail failed. TypeMock.VerifyException:
TypeMock Verification: Method Informedica.SecureSettings.Cryptographers.SymCryptography.Key was expected but was not called
at em.a(ji A_0, d2 A_1, ho A_2, Predicate`1 A_3)
at b7.b(Delegate A_0)
at b7.WasCalledWithAnyArguments[T](Func`1 func)
at Informedica.SecureSettings.Tests.CryptographyAdapterShould.UseSymCryptographyToSetAKey() in C:DevelopmentSecureSettingsInformedica.SecureSettings.TestsCryptographyAdapterShould.cs:line 29
Source=Microsoft.VisualStudio.QualityTools.UnitTestFramework
StackTrace:
at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.HandleFail(String assertionName, String message, Object[] parameters)
at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail(String message, Object[] parameters)
at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail(String message)
at Informedica.SecureSettings.Tests.CryptographyAdapterShould.UseSymCryptographyToSetAKey() in C:DevelopmentSecureSettingsInformedica.SecureSettings.TestsCryptographyAdapterShould.cs:line 33
InnerException:
But I do call SymCryptography.Key, I checked that in the debugger. However when I add Key = _symCrypt.Key to th Encrypt method, the test passes!!??
So, why can I not just check the property set method?