public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { string ignoreReason = Reflect.GetIgnoreReason( runtimeType ); if ( ignoreReason.Trim().Length == 0 ) { Resolution resolution = GetNamedResolution( "TestFixture", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public ); foreach( MethodInfo method in methods ) { string methodIgnoreReason = Reflect.GetIgnoreReason( method ); if ( methodIgnoreReason.Trim().Length == 0 ) { string[] parameters = new string[] { type.Name.Name, method.Name }; Resolution resolution = GetNamedResolution( "TestCase", parameters ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly ); // Note that if an method with an invalid signature is marked as a setup method, then // it will be considered as not marked and hence setupMethod will be null. // Same applies for tearDownMethod. System.Reflection.MethodInfo setupMethod = Reflect.GetSetUpMethod( runtimeType ); System.Reflection.MethodInfo tearDownMethod = Reflect.GetTearDownMethod( runtimeType ); System.Reflection.MethodInfo fixtureSetupMethod = Reflect.GetFixtureSetUpMethod( runtimeType ); System.Reflection.MethodInfo fixtureTearDownMethod = Reflect.GetFixtureTearDownMethod( runtimeType ); foreach( System.Reflection.MethodInfo methodInfo in methods ) { if ( !IsTestCaseMethod( methodInfo ) && ( methodInfo != setupMethod ) && ( methodInfo != tearDownMethod ) && ( methodInfo != fixtureSetupMethod ) && ( methodInfo != fixtureTearDownMethod ) ) { Resolution resolution = GetResolution( methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public ); foreach( MethodInfo method in methods ) { if ( !Reflect.HasTestAttribute( method ) && ( Reflect.HasExpectedExceptionAttribute( method ) || Reflect.HasIgnoreAttribute( method ) || Reflect.HasCategoryAttribute( method ) || Reflect.HasExplicitAttribute( method ) ) ) { Resolution resolution = GetResolution( method.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods(); foreach( System.Reflection.MethodInfo methodInfo in methods ) { // if method starts with "test" and is not marked as [Test], // then an explicit [Test] should be added since NUnit will // treat it as a test case. if ( IsTestCaseMethod( methodInfo ) && !Reflect.HasTestAttribute( methodInfo ) ) { Resolution resolution = GetResolution( methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { PropertyInfo[] properties; // check for instance public properties properties = runtimeType.GetProperties( BindingFlags.Instance | BindingFlags.Public ); foreach( PropertyInfo instanceProperty in properties ) { Resolution resolution = GetResolution( instanceProperty.DeclaringType.Name, instanceProperty.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } // check for static public properties, whether declared in the class // or one of its base classes. properties = runtimeType.GetProperties( BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy ); foreach( PropertyInfo staticProperty in properties ) { Resolution resolution = GetResolution( staticProperty.DeclaringType.Name, staticProperty.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { // if more than one setup, trigger error. if ( GetTestSetupMethodsCount( runtimeType ) > 1 ) { Resolution resolution = GetNamedResolution( "SetUp", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } // if more than one setup, trigger error. if ( GetFixtureSetupMethodsCount( runtimeType ) > 1 ) { Resolution resolution = GetNamedResolution( "TestFixtureSetUp", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) && !runtimeType.IsAbstract && type.IsVisibleOutsideAssembly ) { MemberList constructors = type.GetConstructors(); for ( int i = 0; i < constructors.Length; ++i ) { Member constructor = constructors[i]; // only examine non-static constructors Microsoft.Cci.InstanceInitializer instanceConstructor = constructor as Microsoft.Cci.InstanceInitializer; if ( instanceConstructor == null ) continue; // trigger errors for non-default constructors. if ( ( instanceConstructor.Parameters.Length != 0 ) && ( !instanceConstructor.IsPrivate ) ) { Resolution resolution = GetResolution( runtimeType.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { if ( IsTestFixture( type.GetRuntimeType() ) && type.IsAbstract ) { Resolution resolution = GetResolution( type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { if ( IsTestFixture( type.GetRuntimeType() ) && !type.IsAbstract && // abstract is handled by another rule type.IsVisibleOutsideAssembly && // if not visible, another rule will be triggered. !type.IsSealed ) { Resolution resolution = GetResolution( type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods(); foreach( System.Reflection.MethodInfo methodInfo in methods ) { if ( IsNUnitMethod( methodInfo ) ) { if ( methodInfo.GetParameters().Length > 0 ) { Resolution resolution = GetNamedResolution( "Parameters", methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } if ( methodInfo.ReturnType != typeof(void) ) { Resolution resolution = GetNamedResolution( "ReturnType", methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } if ( methodInfo.IsAbstract ) { Resolution resolution = GetNamedResolution( "Abstract", methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } if ( methodInfo.IsStatic ) { Resolution resolution = GetNamedResolution( "Static", methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); // runtimeType can be null for Microsoft.Cci types. if ( ( runtimeType != null ) && !IsTestFixture( runtimeType ) && ( Reflect.HasCategoryAttribute( runtimeType ) || Reflect.HasExplicitAttribute( runtimeType ) || Reflect.HasIgnoreAttribute( runtimeType ) ) ) { Resolution resolution = GetResolution( type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } return base.Check (type); }