public void CallsOtherConstructorTest() { // Default constructor. Assert.IsFalse(typeof(Empty).GetConstructors()[0].CallsOtherConstructor()); // Public and private constructors. Action <ConstructorInfo[]> checkConstructors = cs => { ConstructorInfo first = cs.Where(c => c.GetParameters().Count() == 0).First(); Assert.IsTrue(first.CallsOtherConstructor()); ConstructorInfo second = cs.Where(c => c.GetParameters().Count() == 1).First(); Assert.IsTrue(second.CallsOtherConstructor()); ConstructorInfo final = cs.Where(c => c.GetParameters().Count() == 2).First(); Assert.IsFalse(final.CallsOtherConstructor()); ConstructorInfo alternateFinal = cs.Where(c => c.GetParameters().Count() == 3).First(); Assert.IsFalse(alternateFinal.CallsOtherConstructor()); }; checkConstructors(typeof(PublicConstructors).GetConstructors()); checkConstructors(typeof(PrivateConstructors).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)); // Inheritance. Action <ConstructorInfo[]> checkBaseConstructors = cs => { ConstructorInfo noParameters = cs.Where(c => c.GetParameters().Count() == 0).First(); ConstructorInfo oneParameter = cs.Where(c => c.GetParameters().Count() == 1).First(); // Only interested in constructors specified on this type, not base constructors, // thus calling a base constructor shouldn't qualify as 'true'. Assert.IsFalse(noParameters.CallsOtherConstructor()); Assert.IsFalse(oneParameter.CallsOtherConstructor()); }; checkBaseConstructors(typeof(BaseConstructors).GetConstructors()); checkBaseConstructors(typeof(DoubleBaseConstructors).GetConstructors()); checkBaseConstructors(typeof(TripleBaseConstructors).GetConstructors()); // Constructor with content. foreach (var constructor in typeof(ContentConstructor).GetConstructors()) { Assert.IsFalse(constructor.CallsOtherConstructor()); } // Constructor of inner class. Assert.IsFalse(typeof(Outer.Inner).GetConstructors()[0].CallsOtherConstructor()); }