public ITestDeclaration GetTestDeclaration(IClassDeclaration classDeclaration) { var clazz = classDeclaration.DeclaredElement.NotNull <IClass>(); if (!IsSuite(clazz)) { return(null); } var identity = _assemblyIdentity.CreateChildIdentity(classDeclaration.CLRName); var categories = clazz.GetAttributeData <CategoriesAttribute>() .GetValueOrDefault( x => x.PositionParameter(paramIndex: 0).ArrayValue.NotNull().Select(y => (string)y.ConstantValue.Value), () => new string[0]).NotNull(); var text = GetText(clazz); var fieldTests = TreeNodeEnumerable.Create( () => { return(classDeclaration.FieldDeclarations .TakeWhile(_notInterrupted) .Select(x => GetFieldTest(x, identity)) .WhereNotNull()); }); return(new ClassTestDeclaration(identity, _project, categories, text, fieldTests, classDeclaration)); }
private ITestDeclaration GetClassTest(IClassDeclaration classDeclaration, IIdentity parentIdentity) { var constructorDeclaration = classDeclaration.ConstructorDeclarations.SingleOrDefault(x => !x.IsStatic && x.ParameterDeclarations.Count == 0); if (constructorDeclaration == null) { return(null); } var text = _treePresenter.Present(classDeclaration); if (text == null) { return(null); } var identity = parentIdentity.CreateChildIdentity(classDeclaration.CLRName); var expressionTests = TreeNodeEnumerable.Create( () => { constructorDeclaration.AssertIsValid(); return(GetInvocationExpressions(constructorDeclaration) .TakeWhile(_notInterrupted) .Select(x => GetInvocationTest(x, identity)) .WhereNotNull()); }); return(new ClassTestDeclaration(identity, _project, text, expressionTests, classDeclaration)); }
private ITestDeclaration GetClassTest(IClassDeclaration classDeclaration, IIdentity parentIdentity) { var text = _treePresenter.Present(classDeclaration); if (text == null) { return(null); } var identity = parentIdentity.CreateChildIdentity(classDeclaration.CLRName); var clazz = (IClass)classDeclaration.DeclaredElement; var categories = clazz.GetAttributeData <CategoriesAttribute>().GetValueOrDefault( x => x.PositionParameter(0).ArrayValue.AssertNotNull().Select(y => (string)y.ConstantValue.Value), () => new string[0]); var constructorDeclaration = classDeclaration.ConstructorDeclarations.SingleOrDefault(x => !x.IsStatic && x.ParameterDeclarations.Count == 0); var expressionTests = TreeNodeEnumerable.Create( () => { return(GetInvocationExpressions(constructorDeclaration) .TakeWhile(_notInterrupted) .Select(x => GetInvocationTest(x, identity)) .WhereNotNull()); }); return(new ClassTestDeclaration(identity, _project, categories, text, expressionTests, classDeclaration)); }
public ITestDeclaration GetTestDeclaration(IClassDeclaration classDeclaration) { var text = _treePresenter.Present(classDeclaration, suiteAttributeType: "TestFx.SpecK.SubjectAttribute"); if (text == null) { return(null); } var identity = _assemblyIdentity.CreateChildIdentity(classDeclaration.CLRName); var clazz = classDeclaration.DeclaredElement.NotNull <IClass>(); var categories = clazz.GetAttributeData <CategoriesAttribute>() .GetValueOrDefault( x => x.PositionParameter(paramIndex: 0).ArrayValue.NotNull().Select(y => (string)y.ConstantValue.Value), () => new string[0]).NotNull(); var constructorDeclaration = classDeclaration.ConstructorDeclarations.SingleOrDefault(x => !x.IsStatic && x.ParameterDeclarations.Count == 0); var expressionTests = TreeNodeEnumerable.Create( () => { return(GetInvocationExpressions(constructorDeclaration) .TakeWhile(_notInterrupted) .Select(x => GetInvocationTest(x, identity)) .WhereNotNull()); }); return(new ClassTestDeclaration(identity, _project, categories, text, expressionTests, classDeclaration)); }
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)); }
private TestProvider CreateTestProvider(IIdentity parentIdentity, object instance, FieldInfo actionField) { var text = actionField.Name.Replace("_", " "); var testProvider = TestProvider.Create(parentIdentity.CreateChildIdentity(actionField.Name), text, ignoreReason: null); var action = CreateUnwrappingAction(actionField, instance); var assertion = OperationProvider.Create <Operation>(OperationType.Assertion, text, action); testProvider.OperationProviders = new[] { assertion }; return(testProvider); }
private ITestMetadata GetFieldTest(IMetadataField field, IIdentity identity) { if (field.Type.NotNull().FullName != "Machine.Specifications.It") { return(null); } var text = field.Name.Replace(oldChar: '_', newChar: ' '); return(new MemberTestMetadata(identity.CreateChildIdentity(text), _project, text.Replace("_", " "), field)); }
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); }
private ITestDeclaration GetFieldTest(IFieldDeclaration fieldDeclaration, IIdentity parentIdentity) { if (fieldDeclaration.Type.GetTypeElement().NotNull().GetClrName().FullName != MSpecUtility.ItDelegateFullName) { return(null); } var identity = parentIdentity.CreateChildIdentity(fieldDeclaration.DeclaredName); var text = fieldDeclaration.DeclaredName.Replace(oldChar: '_', newChar: ' '); return(new FieldTestDeclaration(identity, _project, text, fieldDeclaration)); }
private ITestDeclaration GetInvocationTest(IInvocationExpression invocationExpression, IIdentity parentIdentity) { var text = _treePresenter.Present(invocationExpression); if (text == null) { return(null); } var identity = parentIdentity.CreateChildIdentity(text); return(new InvocationTestDeclaration(identity, _project, text, invocationExpression)); }
private ITestMetadata VisitType(IMetadataTypeInfo type, IIdentity parentIdentity) { var text = _metadataPresenter.Present(type); if (text == null) { return(null); } var identity = parentIdentity.CreateChildIdentity(type.FullyQualifiedName); return(new TypeTestMetadata(identity, _project, text, type)); }
private SuiteProvider CreateSuiteProvider(Type suiteType, IIdentity assemblyIdentity) { var text = GetText(suiteType); if (text == null) { return(null); } var identity = assemblyIdentity.CreateChildIdentity(suiteType.FullName); var ignoreReason = suiteType.GetAttribute <IgnoreAttribute>().GetValueOrDefault(x => x.Reason); var resources = suiteType.GetAttribute <ResourcesAttribute>().GetValueOrDefault(x => x.Resources); return(SuiteProvider.Create(identity, text, ignoreReason, resources)); }
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)); }
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)); }
public ITestDeclaration GetTestDeclaration(IClassDeclaration classDeclaration) { var clazz = classDeclaration.DeclaredElement.NotNull <IClass>(); var hasBecauseField = clazz.Fields.Any(x => x.Type.GetTypeElement()?.GetClrName().FullName == "Machine.Specifications.Because"); if (!hasBecauseField) { return(null); } var text = clazz.DescendantsAndSelf(x => x.GetContainingType() as IClass) .Select( x => { var subjectAttributeData = x.GetAttributeData("Machine.Specifications.SubjectAttribute"); if (subjectAttributeData == null) { return(null); } var subjectType = subjectAttributeData.PositionParameter(paramIndex: 0).TypeValue.NotNull().ToCommon(); return(subjectType.Name + ", " + clazz.ToCommon().Name.Replace(oldChar: '_', newChar: ' ')); }) .WhereNotNull().FirstOrDefault(); if (text == null) { return(null); } var identity = _assemblyIdentity.CreateChildIdentity(classDeclaration.CLRName); var categories = clazz.GetAttributeData <CategoriesAttribute>() .GetValueOrDefault( x => x.PositionParameter(0).ArrayValue.NotNull().Select(y => (string)y.ConstantValue.Value), () => new string[0]).NotNull(); var fieldTests = TreeNodeEnumerable.Create( () => { return(classDeclaration.FieldDeclarations.SelectMany(Flatten) .TakeWhile(_notInterrupted) .Select(x => GetFieldTest(x, identity)) .WhereNotNull()); }); return(new ClassTestDeclaration(identity, _project, categories, text, fieldTests, classDeclaration)); }
private ITestMetadata GetFieldTest(IMetadataField field, IIdentity parentIdentity) { if (field.Type.NotNull().FullName != MSpecUtility.ItDelegateFullName) { return(null); } if (field.GetAttributeData <CompilerGeneratedAttribute>() != null) { return(null); } var identity = parentIdentity.CreateChildIdentity(field.Name); var text = field.Name.Replace(oldChar: '_', newChar: ' '); return(new MemberTestMetadata(identity, _project, text, field)); }
public ISuiteProvider Load(Type suiteType, ICollection <TypedLazy <ILazyBootstrap> > assemblySetups, IIdentity assemblyIdentity) { var uninitializedSuite = (TSuiteType)FormatterServices.GetUninitializedObject(suiteType); var subjectAttribute = suiteType.GetAttributeData <SubjectAttributeBase>(); var displayFormatAttribute = subjectAttribute.Constructor.GetAttributeData <DisplayFormatAttribute>(); var text = _introspectionPresenter.Present(displayFormatAttribute.ToCommon(), subjectAttribute.ToCommon()); var identity = assemblyIdentity.CreateChildIdentity(suiteType.FullName); var provider = SuiteProvider.Create(identity, text, ignored: false); InitializeAssemblySetupFields(uninitializedSuite, assemblySetups.ToList()); InitializeTypeSpecificFields(uninitializedSuite, provider); InvokeConstructor(uninitializedSuite); return(provider); }
public ISuiteProvider Load(Type suiteType, IDictionary<Type, Lazy<IAssemblySetup>> assemblySetups, IIdentity assemblyIdentity) { var uninitializedSuite = FormatterServices.GetUninitializedObject(suiteType); var subjectAttribute = suiteType.GetAttributeData<SuiteAttributeBase>(); var displayFormatAttribute = subjectAttribute.Constructor.GetAttributeData<DisplayFormatAttribute>(); var text = _introspectionPresenter.Present(displayFormatAttribute.ToCommon(), suiteType.ToCommon(), subjectAttribute.ToCommon()); var identity = assemblyIdentity.CreateChildIdentity(suiteType.FullName); var resources = suiteType.GetAttribute<ResourcesAttribute>().GetValueOrDefault(x => x.Resources, () => new string[0]); var provider = SuiteProvider.Create(identity, text, ignored: false, resources: resources); InitializeAssemblySetupFields(uninitializedSuite, assemblySetups); InitializeTypeSpecificFields(uninitializedSuite, provider); InvokeConstructor(uninitializedSuite); return provider; }
public ISuiteProvider Load(Type suiteType, IDictionary <Type, Lazy <IAssemblySetup> > assemblySetups, IIdentity assemblyIdentity) { var uninitializedSuite = FormatterServices.GetUninitializedObject(suiteType); var subjectAttribute = suiteType.GetAttributeData <SuiteAttributeBase>(); var displayFormatAttribute = subjectAttribute.Constructor.GetAttributeData <DisplayFormatAttribute>(); var text = _introspectionPresenter.Present(displayFormatAttribute.ToCommon(), suiteType.ToCommon(), subjectAttribute.ToCommon()); var identity = assemblyIdentity.CreateChildIdentity(suiteType.FullName); var resources = suiteType.GetAttribute <ResourcesAttribute>().GetValueOrDefault(x => x.Resources, () => new string[0]); var provider = SuiteProvider.Create(identity, text, ignored: false, resources: resources); InitializeAssemblySetupFields(uninitializedSuite, assemblySetups); InitializeTypeSpecificFields(uninitializedSuite, provider); InvokeConstructor(uninitializedSuite); return(provider); }
private ITestDeclaration GetClassTest(IClassDeclaration classDeclaration, IIdentity parentIdentity) { var text = _treePresenter.Present(classDeclaration); if (text == null) return null; var identity = parentIdentity.CreateChildIdentity(classDeclaration.CLRName); var clazz = (IClass) classDeclaration.DeclaredElement; var categories = clazz.GetAttributeData<CategoriesAttribute>().GetValueOrDefault( x => x.PositionParameter(0).ArrayValue.AssertNotNull().Select(y => (string) y.ConstantValue.Value), () => new string[0]); var constructorDeclaration = classDeclaration.ConstructorDeclarations.SingleOrDefault(x => !x.IsStatic && x.ParameterDeclarations.Count == 0); var expressionTests = TreeNodeEnumerable.Create( () => { return GetInvocationExpressions(constructorDeclaration) .TakeWhile(_notInterrupted) .Select(x => GetInvocationTest(x, identity)) .WhereNotNull(); }); return new ClassTestDeclaration(identity, _project, categories, text, expressionTests, classDeclaration); }
private ITestDeclaration GetInvocationTest(IInvocationExpression invocationExpression, IIdentity parentIdentity) { var text = _treePresenter.Present(invocationExpression); if (text == null) return null; var identity = parentIdentity.CreateChildIdentity(text); return new InvocationTestDeclaration(identity, _project, text, invocationExpression); }