单元测试和PostSharp

Ale*_*lex 14 aop nunit unit-testing postsharp

我想知道最好的方法是什么...我有兴趣将PostSharp引入我的一个项目中,但我不确定如何正确地测试标记有属性的类.

例如:

public class hello {

    [MyAspectThatDoesSomethingToTheDatabaseWhenThisMethodGetsCalled]
    public int omg(string lol) {
        //fancy logic in here
    }
}
Run Code Online (Sandbox Code Playgroud)

我想测试omg()方法中的逻辑,但是在单元测试中我需要确保不会调用方面,因为实际上没有数据库.

思考?

Tom*_*ana 0

也许您可以使用依赖项注入并为方面类引入一个静态属性,您可以在其中决定将使用哪种数据库访问提供程序(例如使用工厂),并在测试范围内设置假数据库访问提供程序。