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));
        }
Beispiel #2
0
        private string GetText(IMetadataTypeInfo type)
        {
            var subjectAttribute = type.DescendantsAndSelf(x => x.DeclaringType)
                                   .Select(x => x.GetAttributeData(MSpecUtility.SubjectAttributeFullName)).WhereNotNull().First();

            var subjectTypes = subjectAttribute.ConstructorArguments.Select(x => x.Value as IMetadataType).WhereNotNull();
            var subjectText  = subjectAttribute.ConstructorArguments.Select(x => x.Value as string).WhereNotNull().FirstOrDefault();

            return(MSpecUtility.CreateText(type.ToCommon(), subjectTypes.SingleOrDefault()?.ToCommon(), subjectText));
        }
Beispiel #3
0
 public IEnumerable <IMetadataTypeInfo> GetImplementedTypes(IMetadataTypeInfo type)
 {
     return(type.DescendantsAndSelf(x => x.Base.NotNull().Type, x => x.Base != null).Concat(type.Interfaces.Select(x => x.Type)));
 }
Beispiel #4
0
 public IEnumerable<IMetadataTypeInfo> GetImplementedTypes(IMetadataTypeInfo type)
 {
     return type.DescendantsAndSelf(x => x.Base.AssertNotNull().Type, x => x.Base != null).Concat(type.Interfaces.Select(x => x.Type));
 }