示例#1
0
        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));
        }
        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));
        }
示例#3
0
        public string Present(IMetadataTypeInfo type)
        {
            var subjectAttributeData = type.GetAttributeData<SuiteAttributeBase>();
              if (subjectAttributeData == null)
            return null;

              var subjectAttribute = subjectAttributeData.ToCommon();
              var displayFormatAttribute = subjectAttributeData.UsedConstructor.GetAttributeData<DisplayFormatAttribute>().ToCommon();
              return _introspectionPresenter.Present(displayFormatAttribute, type.ToCommon(), subjectAttribute);
        }
示例#4
0
        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));
        }
示例#5
0
        private ITestMetadata VisitType(IMetadataTypeInfo type, IIdentity parentIdentity)
        {
            var text = _metadataPresenter.Present(type);
              if (text == null)
            return null;

              var identity = parentIdentity.CreateChildIdentity(type.FullyQualifiedName);
              var categories = type.GetAttributeData<CategoriesAttribute>().GetValueOrDefault(
              x => x.ConstructorArguments[0].ValuesArray.Select(y => (string) y.Value),
              () => new string[0]);
              return new TypeTestMetadata(identity, _project, categories, text, type);
        }
示例#6
0
        public string Present(IMetadataTypeInfo type)
        {
            var subjectAttributeData = type.GetAttributeData <SubjectAttributeBase>();

            if (subjectAttributeData == null)
            {
                return(null);
            }

            var subjectAttribute       = subjectAttributeData.ToCommon();
            var displayFormatAttribute = subjectAttributeData.UsedConstructor.GetAttributeData <DisplayFormatAttribute>().ToCommon();

            return(_introspectionPresenter.Present(displayFormatAttribute, subjectAttribute));
        }
示例#7
0
        public ITestMetadata GetTestMetadata(IMetadataTypeInfo type)
        {
            var text = _metadataPresenter.Present(type, suiteAttributeType: "TestFx.SpecK.SubjectAttribute");

            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();

            return(new TypeTestMetadata(identity, _project, categories, text, new ITestMetadata[0], type));
        }
示例#8
0
        private ITestMetadata VisitType(IMetadataTypeInfo type, IIdentity parentIdentity)
        {
            var text = _metadataPresenter.Present(type);

            if (text == null)
            {
                return(null);
            }

            var identity   = parentIdentity.CreateChildIdentity(type.FullyQualifiedName);
            var categories = type.GetAttributeData <CategoriesAttribute>().GetValueOrDefault(
                x => x.ConstructorArguments[0].ValuesArray.Select(y => (string)y.Value),
                () => new string[0]);

            return(new TypeTestMetadata(identity, _project, categories, text, type));
        }