Search The Blog
About this site

@RoyOsherove

Subscribe!

This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

from 5whys.com
Twitter: @RoyOsherove
My Book: The Art of Unit Testing
Latest Posts
« OK - back for an evening, leaving tomorrow for a week | Main | See you in three weeks »
Tuesday
Oct192004

Osherove.Interception 1.04 - Change return values and incoming parameter values at runtime easily

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 GetEncryptedValue(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 encryption example is just a simple string concatenation - for demo purposes.

            [Test]

            public void TestEncrypt()

            {

               CryptTestedClass myClass = new CryptTestedClass();

               string output  = myClass.GetEncryptedValue("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);

            }
 

If you want to be able to create such a feature, you'll need to download the latest version of my interception framework, version 1.0.4 from here.

PrintView Printer Friendly Version

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>