public IEnumerable <MSpecTestCase> DiscoverTests(string assemblyPath) { AssemblyExplorer assemblyExplorer = new AssemblyExplorer(); Assembly assembly = AssemblyHelper.Load(assemblyPath); IEnumerable <Context> contexts = assemblyExplorer.FindContextsIn(assembly); SourceCodeLocationFinder locationFinder = new SourceCodeLocationFinder(assemblyPath); return(contexts.SelectMany(context => CreateTestCase(context, locationFinder)).ToList()); }
private IEnumerable <MSpecTestCase> CreateTestCase(Context context, SourceCodeLocationFinder locationFinder) { foreach (Specification spec in context.Specifications.ToList()) { MSpecTestCase testCase = new MSpecTestCase(); testCase.ClassName = context.Type.Name; testCase.ContextFullType = context.Type.FullName; testCase.ContextDisplayName = GetContextDisplayName(context.Type); testCase.SpecificationName = spec.FieldInfo.Name; testCase.SpecificationDisplayName = spec.Name; string fieldDeclaringType; if (spec.FieldInfo.DeclaringType.GetTypeInfo().IsGenericType&& !spec.FieldInfo.DeclaringType.GetTypeInfo().IsGenericTypeDefinition) { fieldDeclaringType = spec.FieldInfo.DeclaringType.GetGenericTypeDefinition().FullName; } else { fieldDeclaringType = spec.FieldInfo.DeclaringType.FullName; } SourceCodeLocationInfo locationInfo = locationFinder.GetFieldLocation(fieldDeclaringType, spec.FieldInfo.Name); if (locationInfo != null) { testCase.CodeFilePath = locationInfo.CodeFilePath; testCase.LineNumber = locationInfo.LineNumber; } if (spec is BehaviorSpecification behaviorSpec) { PopulateBehaviorField(testCase, behaviorSpec); } if (context.Tags != null) { testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray(); } if (context.Subject != null) { testCase.Subject = context.Subject.FullConcern; } yield return(testCase); } }
private IEnumerable<MSpecTestCase> CreateTestCase(Context context, string assemblyPath) { SourceCodeLocationFinder locationFinder = new SourceCodeLocationFinder(assemblyPath); foreach (Specification spec in context.Specifications.ToList()) { MSpecTestCase testCase = new MSpecTestCase(); testCase.ClassName = context.Type.Name; testCase.ContextFullType = context.Type.FullName; testCase.ContextDisplayName = GetContextDisplayName(context.Type); testCase.SpecificationName = spec.FieldInfo.Name; testCase.SpecificationDisplayName = spec.Name; string fieldDeclaringType; if (spec.FieldInfo.DeclaringType.IsGenericType && !spec.FieldInfo.DeclaringType.IsGenericTypeDefinition) fieldDeclaringType = spec.FieldInfo.DeclaringType.GetGenericTypeDefinition().FullName; else fieldDeclaringType = spec.FieldInfo.DeclaringType.FullName; SourceCodeLocationInfo locationInfo = locationFinder.GetFieldLocation(fieldDeclaringType, spec.FieldInfo.Name); if (locationInfo != null) { testCase.CodeFilePath = locationInfo.CodeFilePath; testCase.LineNumber = locationInfo.LineNumber; } if (context.Tags != null) testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray(); if (context.Subject != null) testCase.Subject = context.Subject.FullConcern; yield return testCase; } }