GetFieldLocation() public method

public GetFieldLocation ( string fullTypeName, string fieldName ) : SourceCodeLocationInfo
fullTypeName string
fieldName string
return SourceCodeLocationInfo
Exemplo n.º 1
0
        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;
            }
        }