Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public ITestFile GetTestFile(ICSharpFile csharpFile)
        {
            var assemblyIdentity = new Identity(_project.GetOutputFilePath().FullPath);
            var classTests       = TreeNodeEnumerable.Create(
                () =>
            {
                return(GetClassDeclarations(csharpFile)
                       .TakeWhile(_notInterrupted)
                       .Select(x => GetClassTest(x, assemblyIdentity))
                       .WhereNotNull());
            });

            return(new TestFile(classTests, csharpFile));
        }