Example #1
0
        public override ExpressionKind Eat(ISnapshot snapshot, IBinaryExpression expression)
        {
            var leftKind = Eater.Eat(snapshot, expression.LeftOperand);

            snapshot.Add(leftKind, expression.LeftOperand);

            var rightKind = Eater.Eat(snapshot, expression.RightOperand);

            snapshot.Add(rightKind, expression.RightOperand);

            if (leftKind == ExpressionKind.TargetCall || rightKind == ExpressionKind.TargetCall)
            {
                return(ExpressionKind.Result);
            }

            if (leftKind == ExpressionKind.Target || rightKind == ExpressionKind.Target)
            {
                return(ExpressionKind.Target);
            }

            if (leftKind == ExpressionKind.Result || rightKind == ExpressionKind.Result)
            {
                return(ExpressionKind.Result);
            }

            return(ExpressionKind.StubCandidate);
        }
        public void EatStubOptions(ISnapshot snapshot, ICSharpExpression options)
        {
            if (options is IConditionalAndExpression)
            {
                EatStubOptions(snapshot, (options as IConditionalAndExpression).LeftOperand);
                EatStubOptions(snapshot, (options as IConditionalAndExpression).RightOperand);
                return;
            }

            if (options is IEqualityExpression)
            {
                EatStubOptions(snapshot, (options as IEqualityExpression).LeftOperand);
                var kind = _eater.Eat(snapshot, (options as IEqualityExpression).RightOperand);
                EatOptionValue(snapshot, kind, (options as IEqualityExpression).RightOperand);
                return;
            }

            if (options is IInvocationExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IInvocationExpression);
                snapshot.Add(optType, options);
                return;
            }

            if (options is IReferenceExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IReferenceExpression);
                snapshot.Add(optType, options);
                return;
            }

            throw new MoqStubOptionWrongTypeException(this, options);
        }
Example #3
0
        public override void Eat(ISnapshot snapshot, ILocalVariableDeclaration variableDeclaration)
        {
            if (variableDeclaration.Initial == null)
            {
                var typeKind = _typeEater.EatVariableType(snapshot, variableDeclaration.Type);
                snapshot.Add(typeKind, variableDeclaration);
                return;
            }

            ExpressionKind kind = _variableInitializerEater.Eat(snapshot, variableDeclaration.Initial);

            if (kind == ExpressionKind.StubCandidate)
            {
                snapshot.Add(ExpressionKind.Stub, variableDeclaration);
                return;
            }

            if (kind == ExpressionKind.TargetCall || kind == ExpressionKind.Assert)
            {
                snapshot.Add(ExpressionKind.Result, variableDeclaration);
                return;
            }

            snapshot.Add(kind, variableDeclaration);
        }
        public override ExpressionKind Eat(ISnapshot snapshot, IQueryExpression expression)
        {
            Eater.Eat(snapshot, expression.From.Expression);
            snapshot.Add(expression.From.Declaration);

            IQuerySelectClause lastSelect;

            foreach (var queryClause in expression.Clauses)
            {
                Eater.Eat(snapshot, queryClause);
            }

            lastSelect = expression.Clauses.Last() as IQuerySelectClause;

            foreach (var queryContinuation in expression.Continuations)
            {
                snapshot.Add(queryContinuation.Declaration);

                foreach (var queryClause in queryContinuation.Clauses)
                {
                    Eater.Eat(snapshot, queryClause);
                }

                lastSelect = queryContinuation.Clauses.Last() as IQuerySelectClause;
            }

            // the final query kind is provided based on type of last select clause
            // so if it return stubs(for example), all query returns stubs
            return(Eater.Eat(snapshot, lastSelect));
        }
        public void EatStubOptions(ISnapshot snapshot, ICSharpExpression options)
        {
            if (options is IConditionalAndExpression)
            {
                EatStubOptions(snapshot, (options as IConditionalAndExpression).LeftOperand);
                EatStubOptions(snapshot, (options as IConditionalAndExpression).RightOperand);
                return;
            }

            if (options is IEqualityExpression)
            {
                EatStubOptions(snapshot, (options as IEqualityExpression).LeftOperand);
                var kind = _eater.Eat(snapshot, (options as IEqualityExpression).RightOperand);
                EatOptionValue(snapshot, kind, (options as IEqualityExpression).RightOperand);
                return;
            }

            if (options is IInvocationExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IInvocationExpression);
                snapshot.Add(optType, options);
                return;
            }

            if (options is IReferenceExpression)
            {
                var optType = _moqStubOptionTargetEater.EatOption(snapshot, options as IReferenceExpression);
                snapshot.Add(optType, options);
                return;
            }

            throw new MoqStubOptionWrongTypeException(this, options);
        }
Example #6
0
 public override void Save(ISnapshot snapshot)
 {
     snapshot.Add("Name", Name);
     snapshot.Add("PositionX", PositionX);
     snapshot.Add("PositionY", PositionY);
     snapshot.Add("PlayerNumber", PlayerNumber);
     snapshot.Add("UnitType", UnitType);
 }
        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);
        }
        private ExpressionKind EatVariableDeclaration(ISnapshot snapshot, IVariableDeclaration variableDeclaration, ExpressionKind assignmentKind)
        {
            // TODO : check on properties, fields, events, parameters
            if (variableDeclaration is IEventDeclaration)
            {
                return(ExpressionKind.None);
            }

            if (variableDeclaration is ILocalVariableDeclaration)
            {
                if ((variableDeclaration as ILocalVariableDeclaration).Initial == null)
                {
                    snapshot.Except(variableDeclaration);
                }
            }

            if (variableDeclaration is IUnsafeCodeFixedPointerDeclaration)
            {
                if ((variableDeclaration as IUnsafeCodeFixedPointerDeclaration).Initial == null)
                {
                    snapshot.Except(variableDeclaration);
                }
            }

            snapshot.Add(assignmentKind, variableDeclaration);
            return(assignmentKind);
        }
Example #9
0
        public override ExpressionKind Eat(ISnapshot snapshot, IConditionalTernaryExpression expression)
        {
            var conditionKind = Eater.Eat(snapshot, expression.ConditionOperand);

            snapshot.Add(conditionKind, expression.ConditionOperand);

            var thenKind = Eater.Eat(snapshot, expression.ThenResult);

            snapshot.Add(thenKind, expression.ThenResult);

            var elseKind = Eater.Eat(snapshot, expression.ElseResult);

            snapshot.Add(elseKind, expression.ElseResult);

            return(ExpressionKind.StubCandidate);
        }
 private void EatOptionValue(ISnapshot snapshot, ExpressionKind kind, ICSharpExpression optionValue)
 {
     var addableKinds = new[] { ExpressionKind.Target, ExpressionKind.Stub, ExpressionKind.Mock };
     if (addableKinds.Contains(kind))
     {
         snapshot.Add(kind, optionValue);
     }
 }
        public override void Eat(ISnapshot snapshot, IWhileStatement statement)
        {
            Eater.Eat(snapshot, statement.Body);

            var condKind = Eater.Eat(snapshot, statement.Condition);

            snapshot.Add(condKind, statement.Condition);
        }
Example #12
0
        public override ExpressionKind Eat(ISnapshot snapshot, IIsExpression expression)
        {
            var kind = Eater.Eat(snapshot, expression.Operand);

            snapshot.Add(kind, expression.Operand);

            return(ExpressionKind.StubCandidate);
        }
        public override void Eat(ISnapshot snapshot, ISwitchStatement statement)
        {
            Eater.Eat(snapshot, statement.Block);

            var condKind = Eater.Eat(snapshot, statement.Condition);

            snapshot.Add(condKind, statement.Condition);
        }
        public override void Eat(ISnapshot snapshot, ILockStatement statement)
        {
            Eater.Eat(snapshot, statement.Body);

            var condKind = Eater.Eat(snapshot, statement.Monitor);

            snapshot.Add(condKind, statement.Monitor);
        }
        public override void Eat(ISnapshot snapshot, IForeachStatement statement)
        {
            Eater.Eat(snapshot, statement.Body);
            Eater.Eat(snapshot, statement.IteratorDeclaration);

            var kind = Eater.Eat(snapshot, statement.Collection);

            snapshot.Add(kind, statement.Collection);
        }
        private void EatOptionValue(ISnapshot snapshot, ExpressionKind kind, ICSharpExpression optionValue)
        {
            var addableKinds = new[] { ExpressionKind.Target, ExpressionKind.Stub, ExpressionKind.Mock };

            if (addableKinds.Contains(kind))
            {
                snapshot.Add(kind, optionValue);
            }
        }
Example #17
0
        public override void Eat(ISnapshot snapshot, IForStatement statement)
        {
            Eater.Eat(snapshot, statement.Body);

            var condKind = Eater.Eat(snapshot, statement.Condition);

            snapshot.Add(condKind, statement.Condition);

            foreach (var initializer in statement.Initializer.Expressions)
            {
                var kind = Eater.Eat(snapshot, initializer);
                snapshot.Add(kind, initializer);
            }

            foreach (var iterator in statement.Iterators.Expressions)
            {
                var kind = Eater.Eat(snapshot, iterator);
                snapshot.Add(kind, iterator);
            }
        }
Example #18
0
        public override ExpressionKind Eat(ISnapshot snapshot, IAnonymousObjectCreationExpression expression)
        {
            // TODO: cover by functional tests
            foreach (var memberDeclaration in expression.AnonymousInitializer.MemberInitializers)
            {
                var kind = Eater.Eat(snapshot, memberDeclaration.Expression);
                snapshot.Add(kind, memberDeclaration);
            }

            return(ExpressionKind.StubCandidate);
        }
Example #19
0
        public override void Eat(ISnapshot snapshot, IIfStatement statement)
        {
            Eater.Eat(snapshot, statement.Then);
            if (statement.Else != null)
            {
                Eater.Eat(snapshot, statement.Else);
            }

            var condKind = Eater.Eat(snapshot, statement.Condition);

            snapshot.Add(condKind, statement.Condition);
        }
        public override ExpressionKind Eat(ISnapshot snapshot, IObjectCreationExpression expression)
        {
            _argumentsEater.Eat(snapshot, expression.Arguments);

            if (expression.Initializer != null)
            {
                foreach (IMemberInitializer memberInitializer in expression.Initializer.InitializerElements)
                {
                    var kind = Eater.Eat(snapshot, memberInitializer.Expression);
                    snapshot.Add(kind, memberInitializer);
                }
            }

            return(GetCreationObjectKind(snapshot, expression));
        }
        public override ExpressionKind Eat(ISnapshot snapshot, IArrayCreationExpression expression)
        {
            // TODO : check in functional tests
            foreach (ICSharpExpression size in expression.Sizes)
            {
                ExpressionKind kind = Eater.Eat(snapshot, size);
                if (kind != ExpressionKind.StubCandidate)
                {
                    snapshot.Add(kind, size);
                }
            }

            _variableInitializerEater.Eat(snapshot, expression.ArrayInitializer);

            return(ExpressionKind.StubCandidate);
        }
Example #22
0
        public void Eat([NotNull] ISnapshot snapshot, TreeNodeCollection <ICSharpArgument> arguements)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            foreach (ICSharpArgument arg in arguements)
            {
                ExpressionKind kind = _eater.Eat(snapshot, arg.Value);

                if (kind != ExpressionKind.StubCandidate && !(arg.Value is IReferenceExpression))
                {
                    snapshot.Add(kind, arg);
                }
            }
        }
        public ExpressionKind Eat([NotNull] ISnapshot snapshot, [NotNull] IVariableInitializer initializer)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

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

            if (initializer is IArrayInitializer)
            {
                foreach (IVariableInitializer variableInitializer in (initializer as IArrayInitializer).ElementInitializers)
                {
                    ExpressionKind kind = Eat(snapshot, variableInitializer);

                    // TODO : what if stubcandidate
                    snapshot.Add(kind, variableInitializer);
                }

                // TODO : array of target?
                return(ExpressionKind.StubCandidate);
            }

            ICSharpExpression initialExpression = null;

            if (initializer is IExpressionInitializer)
            {
                initialExpression = (initializer as IExpressionInitializer).Value;
            }

            if (initializer is IUnsafeCodeFixedPointerInitializer)
            {
                initialExpression = (initializer as IUnsafeCodeFixedPointerInitializer).Value;
            }

            if (initializer is IUnsafeCodeStackAllocInitializer)
            {
                initialExpression = (initializer as IUnsafeCodeStackAllocInitializer).DimExpr;
            }

            return(EatResults(snapshot, initialExpression));
        }
Example #24
0
 public override void Save(ISnapshot snapshot)
 {
     snapshot.Add("Speed", Speed);
 }
Example #25
0
 public override void Eat(ISnapshot snapshot, IAnonymousMethodParameterDeclaration variableDeclaration)
 {
     snapshot.Add(variableDeclaration);
 }
Example #26
0
 public override void Eat(ISnapshot snapshot, IRegularParameterDeclaration variableDeclaration)
 {
     snapshot.Add(ExpressionKind.Stub, variableDeclaration);
 }
Example #27
0
 public override void Eat(ISnapshot snapshot, ICatchVariableDeclaration variableDeclaration)
 {
     snapshot.Add(variableDeclaration);
 }
        public override void Eat(ISnapshot snapshot, IUnsafeCodeFixedPointerDeclaration variableDeclaration)
        {
            ExpressionKind kind = _variableInitializerEater.Eat(snapshot, variableDeclaration.Initial);

            snapshot.Add(kind, variableDeclaration);
        }
Example #29
0
        public override void Eat(ISnapshot snapshot, IThrowStatement statement)
        {
            var condKind = Eater.Eat(snapshot, statement.Exception);

            snapshot.Add(condKind, statement.Exception);
        }
Example #30
0
 public override void Save(ISnapshot snapshot)
 {
     snapshot.Add("Health", Health);
 }
Example #31
0
        public override void Eat(ISnapshot snapshot, ISwitchLabelStatement statement)
        {
            var condKind = Eater.Eat(snapshot, statement.ValueExpression);

            snapshot.Add(condKind, statement.ValueExpression);
        }
Example #32
0
 public override void Eat(ISnapshot snapshot, ILocalConstantDeclaration variableDeclaration)
 {
     snapshot.Add(ExpressionKind.Stub, variableDeclaration);
 }