c# - How do I ensure that all controllers in an asp.net web-api service are configured correctly _in a single test class_? -
dipping toes asp.net , mvc, more web-api (2.0) part of mvc 5, idea of using attributes , creating own attribute classes control how requests handled , responses returned api end-points.
the "how test "only roles should have access controller in mvc" article describes how unit test single controller ensure keeps correct attributes , doesn't undesired attributes added.
that valid way of unit testing individual controllers. however, prefer have tests of api configuration in single place instead of spread around unit tests of individual controllers. as, using attribute routing, controller can replaced different controller may not have correct attributes , test companion doesn't test them.
what envision single test class aspects of api configuration can secured against undesired effects of (inadvertent) changes. struggling how set up. bryan avery's article (mentioned above) shows how list of custom attributes of controller class, but:
how hands on list of controllers present in test project?
reflection ought here:
var mycontrollers = assembly.load(yourassemblyname) .gettypes() .where(t => typeof(t).isassignablefrom(apicontroller)) .tolist();
Comments
Post a Comment