Search code examples
c#unit-testingstylecop

can stylecop prevent disk i/o in unit tests?


I'm hoping that I can use stylecop to prevent disk IO in unit tests, by preventing explicit method calls that I define.

Have very little experience with stylecop but from what I've gathered it should be able to do this kind of task (prevent given method calls). Searched stackoverflow and google without success.

Is this possible and if so, how?


Solution

  • Stylecop, not likely, but you could probably implement this partially using a Roslyn rule (if you're targeting Visual Studio 2015) or a FxCop rule (if you're targeting Visual Studio 2013 or older).

    What will be hard to validate are situations where a test calls a method, which calls a method, which raises an event, which causes IO. Simpler situations where a test calls a method which accesses System.IO is pretty easy.