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