Exemple #1
0
        public ExpressionKind EatVariableType([NotNull] ISnapshot snapshot, [NotNull] IType type)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var classType = _eatExpressionHelper.GetTypeClass(type);

            if (snapshot.IsInTestScope(classType.Module.Name))
            {
                //TODO if type is interface or abstract class return stub/mock?
                return(ExpressionKind.Target);
            }

            if (snapshot.IsInTestProject(classType.Module.Name))
            {
                return(ExpressionKind.Mock);
            }

            return(ExpressionKind.StubCandidate);
        }
        private ExpressionKind GetCreationObjectKind(ISnapshot snapshot, IObjectCreationExpression expression)
        {
            if (expression.Type().Classify == TypeClassification.REFERENCE_TYPE)
            {
                var projectName = GetProjectName(expression);

                if (snapshot.IsInTestScope(projectName))
                {
                    return(ExpressionKind.Target);
                }

                if (snapshot.IsInTestProject(projectName))
                {
                    return(ExpressionKind.Mock);
                }

                if (_expressionHelper.GetCreationTypeName(expression)
                    .StartsWith("Moq.Mock"))
                {
                    return(ExpressionKind.Mock);
                }
            }

            return(ExpressionKind.StubCandidate);
        }
        public override ExpressionKind Eat(ISnapshot snapshot, IInvocationExpression expression)
        {
            var invokedName = _expressionHelper.GetInvokedElementName(expression);

            if (invokedName.StartsWith("Method:Moq.Mock.Of"))
            {
                _mockOfInvocationEater.Eat(snapshot, expression);
                return(ExpressionKind.Stub);
            }

            _argumentsEater.Eat(snapshot, expression.Arguments);

            var parentKind = _parentReferenceEater.Eat(snapshot, expression);

            if (invokedName.StartsWith("Method:NUnit.Framework.Assert"))
            {
                snapshot.Add(ExpressionKind.Assert, expression);
                return(ExpressionKind.Assert);
            }

            if (invokedName.StartsWith("Method:Moq.Mock.Verify"))
            {
                snapshot.Add(ExpressionKind.Assert, expression);
                return(ExpressionKind.Assert);
            }

            var invoked = _expressionHelper.GetInvokedElement(expression);

            if (invoked is IMethod)
            {
                var invokedMethod = invoked as IMethod;
                if (snapshot.IsInTestScope(invokedMethod.Module.Name))
                {
                    snapshot.Add(ExpressionKind.TargetCall, expression);
                    return(ExpressionKind.TargetCall);
                }
            }

            if (parentKind == ExpressionKind.None)
            {
                return(ExpressionKind.StubCandidate);
            }

            var basedOnParentKind = _expressionKindHelper.InvocationKindByParentReferenceKind(parentKind);

            if (basedOnParentKind == ExpressionKind.TargetCall)
            {
                snapshot.Add(ExpressionKind.TargetCall, expression);
                return(ExpressionKind.TargetCall);
            }

            return(basedOnParentKind);
        }
Exemple #4
0
        public ExpressionKind EatCastType([NotNull] ISnapshot snapshot, [NotNull] ITypeUsage typeUsage)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            if (typeUsage == null)
            {
                throw new ArgumentNullException("typeUsage");
            }

            if (typeUsage is IDynamicTypeUsage)
            {
                return(ExpressionKind.StubCandidate);
            }

            if (typeUsage is IPredefinedTypeUsage)
            {
                return(ExpressionKind.StubCandidate);
            }

            if (typeUsage is IUserTypeUsage)
            {
                var userTypeUsage = typeUsage as IUserTypeUsage;
                var classType     = _eatExpressionHelper.GetUserTypeUsageClass(userTypeUsage);

                if (snapshot.IsInTestScope(classType.Module.Name))
                {
                    return(ExpressionKind.Target);
                }

                if (snapshot.IsInTestProject(classType.Module.Name))
                {
                    return(ExpressionKind.Mock);
                }
            }

            return(ExpressionKind.StubCandidate);
        }