public ITestMetadata GetTestMetadata(IMetadataTypeInfo type) { var isCompilerGenerated = type.GetAttributeData <CompilerGeneratedAttribute>() != null; if (isCompilerGenerated) { return(null); } var hasBecauseField = type.GetFields().Any(x => { var metadataClassType = x.Type as IMetadataClassType; if (metadataClassType == null) { return(false); } var fullyQualifiedName = metadataClassType.Type.FullyQualifiedName; return(fullyQualifiedName == "Machine.Specifications.Because"); }); if (!hasBecauseField) { return(null); } var text = type.DescendantsAndSelf(x => x.DeclaringType) .Select( x => { var subjectAttributeData = x.GetAttributeData("Machine.Specifications.SubjectAttribute"); if (subjectAttributeData == null) { return(null); } var subjectType = subjectAttributeData.ConstructorArguments.First().Type.NotNull().ToCommon(); return(subjectType.Name + ", " + type.ToCommon().Name.Replace(oldChar: '_', newChar: ' ')); }).WhereNotNull().FirstOrDefault(); if (text == null) { return(null); } var identity = _assemblyIdentity.CreateChildIdentity(type.FullyQualifiedName); var categories = type.GetAttributeData <CategoriesAttribute>().GetValueOrDefault( x => x.ConstructorArguments[0].ValuesArray.Select(y => (string)y.Value), () => new string[0]).NotNull(); var fieldTests = type.GetFields().SelectMany(Flatten) .TakeWhile(_notInterrupted) .Select(x => GetFieldTest(x, identity)) .WhereNotNull(); return(new TypeTestMetadata(identity, _project, categories, text, fieldTests, type)); }
public ITestMetadata GetTestMetadata(IMetadataTypeInfo type) { var isCompilerGenerated = type.GetAttributeData <CompilerGeneratedAttribute>() != null; if (isCompilerGenerated) { return(null); } if (!IsSuite(type)) { return(null); } var identity = _assemblyIdentity.CreateChildIdentity(type.FullyQualifiedName); var categories = type.GetAttributeData <CategoriesAttribute>().GetValueOrDefault( x => x.ConstructorArguments[0].ValuesArray.Select(y => (string)y.Value), () => new string[0]).NotNull(); var text = GetText(type); var fieldTests = type.GetFields() .TakeWhile(_notInterrupted) .Select(x => GetFieldTest(x, identity)) .WhereNotNull(); return(new TypeTestMetadata(identity, _project, categories, text, fieldTests, type)); }
private bool IsSuite(IMetadataTypeInfo type) { if (type.GetAttributeData(MSpecUtility.BehaviorsAttributeFullName) != null) { return(false); } return(type.GetFields().Select(x => x.Type).OfType <IMetadataClassType>().Select(x => x.Type.FullyQualifiedName) .Any(x => x == MSpecUtility.ItDelegateFullName || x == MSpecUtility.BehavesLikeDelegateFullName)); }
private void ExploreSpecificationContainer(IProject project, SpecificationContainerElement container, UnitTestElementConsumer consumer, IMetadataTypeInfo metadataTypeInfo) { foreach (var field in metadataTypeInfo.GetFields()) { if (!field.IsPublic) continue; var x = field.Name; var methodElement = _elementFactory.GetOrCreateSpecificationElement(project, container, new ClrTypeName(metadataTypeInfo.FullyQualifiedName), x, string.Empty); consumer(methodElement); } }
public IMetadataField[] GetFields() { return(_metadataTypeInfo.GetFields()); }
static IEnumerable <IMetadataField> GetInstanceFields(this IMetadataTypeInfo type) { return(type.GetFields().Where(field => !field.IsStatic)); }
public IEnumerable <IFieldInfo> GetFields() { return(type.GetFields() .Where(x => !x.IsStatic) .Select(x => x.AsFieldInfo())); }