Disclaimer: the unit test class is not considered reasonable
(author)
I think with the help of unit testing you mean "unit level tests of the class", where the unit is the class. If you want to test the IoCModule , you should use component / library level testing, where you test the entire library to see if it works correctly. This (should) include IoCModule - and all other things in the library. It is usually impractical to achieve 100% coverage of branches using tests at this level, but a combination of tests at this level + unit-level tests of a class level provide very good reliability of the test. I would also say that it is better to achieve coverage of 80%, and not just unit tests at the class level. Although each class may work exactly according to the test, everything may not work as intended. This is why you should perform component level tests.
How to check if a type is registered:
Now, if you are still not sure about the tests, look no further, you can do it as follows:
public class MyModuleTest { private IContainer container; [TestFixtureSetUp] public void TestFixtureSetUp() { var containerBuilder = new ContainerBuilder();
This gives a test result, for example: 
therefore, each type is reported separately.
Wow, that was easy - so what's the problem again?
Now in the example above, you can see that the test passes for single (= float ). Now look at the module:
public class MyModule : Module { protected override void Load(ContainerBuilder builder) { builder.RegisterType<float>(); } }
when we are actually trying to resolve float :
container.Resolve<float>();
here's what happens:
Autofac.Core.DependencyResolutionException: constructors of type "System.Single" cannot be found by searching for the constructor "Autofac.Core.Activators.Reflection.DefaultConstructorFinder".
Of course, we could just adapt the test to execute Resolve(Type t) instead of using IsRegistered(Type t) - however, there are many other ways to make a test pass, but the implementation failed. For instance:
- type binding to using
builder.RegisterInstance<IFoo>(null) - change the service life / scope so that it does not work properly.