Latest Replies
Friday
Jan092009

How to Count Methods With NotImplementedException?

Unit test like this will fail if more than 10 methods create NotImplementedException. On failing it will report all methods that create this exception.

var throwingMethods = codebase.Methods
  .Where(m => m
         .GetInstructions()
         .Exists(i => i.Creates<NotImplementedException>()))
  .ToArray();

if (throwingMethods.Length > 10)
  CollectionAssert.IsEmpty(throwingMethods);

Where codebase is created like this:

var codebase = new Codebase("Assembly1.dll","Assembly2.dll");

Snippet uses Lokad.Quality.dll from the Lokad Shared Libraries.

« How to Find Extension Methods Targeting Object? | Main | Strategy Pattern in .NET NeuroEvolution Algorithms »