public static AndConstraint <TypeAssertions> NotHaveStaticFields(this TypeAssertions assertions) { Type type = assertions.Subject; var staticFields = new List <IAmField>(SmartType.For(type).GetAllStaticFields()); staticFields.Should() .BeEmpty("SmartType " + type + " should not contain static fields, but: " + Environment.NewLine + ReflectionElementsList.Format(staticFields)); return(new AndConstraint <TypeAssertions>(assertions)); }
public static AndConstraint <AssemblyAssertions> HaveOnlyTypesWithSingleConstructor(this AssemblyAssertions assertions) { Assembly assembly = assertions.Subject; var constructorLimitsExceeded = new List <Tuple <Type, int> >(); foreach (var type in assembly.GetTypes()) { var constructorCount = SmartType.For(type).GetAllPublicConstructors().Count(); if (constructorCount > 1) { constructorLimitsExceeded.Add(Tuple.Create(type, constructorCount)); } } constructorLimitsExceeded.Any().Should() .BeFalse("assembly " + assembly + " should not contain types with more than one constructor, but: " + Environment.NewLine + ReflectionElementsList.Format(constructorLimitsExceeded)); return(new AndConstraint <AssemblyAssertions>(assertions)); }
public static AndConstraint <AssemblyAssertions> NotHaveStaticFields(this AssemblyAssertions assertions) { Assembly assembly = assertions.Subject; var staticFields = new List <IAmField>(); foreach (var type in assembly.GetTypes()) { staticFields.AddRange(SmartType.For(type).GetAllStaticFields()); } staticFields.Should() .BeEmpty( "assembly " + assembly + " should not contain static fields, but: " + Environment.NewLine + ReflectionElementsList.Format(staticFields)); return(new AndConstraint <AssemblyAssertions>(assertions)); }
public static AndConstraint <AssemblyAssertions> NotHaveHiddenEvents(this AssemblyAssertions assertions) { Assembly assembly = assertions.Subject; var nonPublicEvents = new List <IAmEvent>(); foreach (var type in assembly.GetTypes().Select(SmartType.For)) { nonPublicEvents.AddRange(type.GetAllNonPublicEventsWithoutExplicitlyImplemented()); } nonPublicEvents.Should() .BeEmpty("assembly " + assembly + " should not contain non-public events, but: " + Environment.NewLine + ReflectionElementsList.NonPublicEventsFoundMessage(nonPublicEvents)); return(new AndConstraint <AssemblyAssertions>(assertions)); }