I just love the idea of interception. It lets you do stuff like this:
using Osherove.Interception.Framework;
namespace Osherove.Interception.Samples.AutoEncryption
{
public class CryptTestedClass:InterceptableObject
{
[EncryptOutput]
public string GetEncprytedValue(string someValue)
{
//after this line someValue will be automatically
//encrypted and returned to the called in its new form
return someValue;
}
[DecryptInput("encrypted")]
public string ReturnUnEncryptedString (string noChangeableValue,
string encrypted)
{
//'encrypted' should already be in its unencrypted form in this stage
//so we just return it.
return encrypted;
}
}
}
and here are the tests(notice the the ecryption example is just a simple string concatenation - for demo purposes.
[Test]
public void TestEncrypt()
{
CryptTestedClass myClass = new CryptTestedClass();
string output = myClass.GetEncprytedValue("SomeValue");
Assert.AreEqual("SomeValue*SomeEncryptStuffHere*",output);
}
[Test]
public void TestDecrypt()
{
string encrypted = "SomeValue*SomeEncryptStuffHere";
string decryptedOutput =
new CryptTestedClass().
ReturnUnEncryptedString("some string",encrypted);
Assert.AreEqual("SomeValue",decryptedOutput);
}