Click here to Skip to main content
15,886,258 members
Articles / DevOps / Testing

Mocking Methods and Properties Using PostSharp

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
14 Aug 2012CPOL4 min read 19K   97   7  
Mock test without interface, on static methods and properties, using PostSharp
using System.Reflection;
using PostSharp.Aspects;

namespace Framework
{
    /// <summary>
    /// Mocked method interface
    /// </summary>
    public interface IMockedMethod
    {
        /// <summary>
        /// Mocked value if satisfied
        /// </summary>
        object ReturnValue { get; }

        /// <summary>
        /// Check whether the method, arguments match the mock setup
        /// </summary>
        /// <param name="method">Method itself</param>
        /// <param name="instance">Object instance</param>
        /// <param name="arguments">Argument collection</param>
        /// <returns>True if intercepted</returns>
        bool HitTest(MethodBase method, object instance, Arguments arguments);

        /// <summary>
        /// Called to verify if access count meets the expectation
        /// </summary>
        void VerifyAccess();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) 3PLearning
Australia Australia
Lead Developer, MMO Game Company
Testor, Microsoft

Comments and Discussions