Пример #1
0
        public Snapshot EatUnitTest(IMethodDeclaration unitTest)
        {
            var snapshot = new Snapshot(unitTest);

            foreach (var parameterDeclaration in unitTest.ParameterDeclarations)
            {
                _eater.Eat(snapshot, parameterDeclaration);
            }

            _eater.Eat(snapshot, unitTest.Body);

            return(snapshot);
        }
        public virtual ExpressionKind Eat([NotNull] ISnapshot snapshot, [NotNull] IInvocationExpression expression)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

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

            if (expression.ExtensionQualifier == null)
            {
                return(ExpressionKind.None);
            }

            var mc = expression.ExtensionQualifier.ManagedConvertible;

            if (mc is ExtensionArgumentInfo)
            {
                return(_eater.Eat(snapshot, (mc as ExtensionArgumentInfo).Expression));
            }

            return(ExpressionKind.None);
        }
        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);
        }
Пример #4
0
 public void Eat(IEater eater, Food food)
 {
     // Eater buries bone.
     this.BuryBone(food);
     // Eater digs up the bone.
     this.DigUpAndEatBone();
     // Eater eats the bone.
     eater.Eat(food);
     // Eater barks in satisfaction.
     this.Bark();
 }
Пример #5
0
        /// <summary>
        /// Feeds a baby eater.
        /// </summary>
        /// <param name="newborn">The eater to feed.</param>
        private void FeedNewborn(IEater newborn)
        {
            // Determine milk weight.
            double milkWeight = this.Weight * 0.005;

            // Generate milk.
            Food milk = new Food(milkWeight);

            // Feed baby.
            newborn.Eat(milk);

            // Reduce parent's weight.
            this.Weight -= milkWeight;
        }
Пример #6
0
        /// <summary>
        /// Feeds the specified eater.
        /// </summary>
        /// <param name="eater">The eater to be fed.</param>
        /// <param name="animalSnackMachine">The animal snack machine from which to buy food.</param>
        public void FeedAnimal(IEater eater, VendingMachine animalSnackMachine)
        {
            // Find food price.
            decimal price = animalSnackMachine.DetermineFoodPrice(eater.Weight);

            // Get money from wallet.
            decimal payment = this.wallet.RemoveMoney(price);

            // Buy food.
            Food food = animalSnackMachine.BuyFood(payment);

            // Feed animal.
            eater.Eat(food);
        }
Пример #7
0
        public void Act()
        {
            var objectToEat     = _objectToEatFunc();
            var eatableBehavior = objectToEat?.GetBehavior <EatableBehavior>();

            if (eatableBehavior != null && eatableBehavior.ForType(_eater.EaterType))
            {
                _eater.Eat((int)(eatableBehavior.SatietyCoefficient + objectToEat.WeightDbl));
                objectToEat.RemoveFromContainer?.Invoke();
            }

            var mobileObject = _eater as MobileObject;

            mobileObject?.StateEvent.FireEvent();
        }
Пример #8
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        IEater eater = collision.gameObject.GetComponent <IEater>();

        if (eater == null)
        {
            //TODO score substruct, smash animation
            scoreController.Score -= score;
            Destroy(gameObject);
        }
        else
        {
            eater.Eat(this);
            scoreController.Score += score;
        }
    }
        private ExpressionKind EatResults(ISnapshot snapshot, ICSharpExpression initialExpression)
        {
            ExpressionKind expressionKind = _eater.Eat(snapshot, initialExpression);

            if (expressionKind == ExpressionKind.StubCandidate)
            {
                return(ExpressionKind.Stub);
            }

            if (expressionKind == ExpressionKind.TargetCall)
            {
                return(ExpressionKind.Result);
            }

            return(expressionKind);
        }
Пример #10
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);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Feeds the specified eater.
        /// </summary>
        /// <param name="eater">The eater to be fed.</param>
        /// <param name="animalSnackMachine">The animal snack machine from which to buy food.</param>
        public void FeedAnimal(IEater eater, VendingMachine animalSnackMachine)
        {
            // Find food price.
            decimal price = animalSnackMachine.DetermineFoodPrice(eater.Weight);

            if (this.wallet.MoneyBalance < price)
            {
                // Withdraw 10 times the price of the food.
                this.WithdrawMoney(price * 10);
            }

            // Get money from wallet.
            decimal payment = this.wallet.RemoveMoney(price);

            // Buy food.
            Food food = animalSnackMachine.BuyFood(payment);

            // Feed animal.
            eater.Eat(food);
        }
Пример #12
0
        /// <summary>
        /// Feeds the specified eater.
        /// </summary>
        /// <param name="eater">The eater to be fed.</param>
        /// <param name="animalSnackMachine">The animal snack machine from which to buy food.</param>
        public void FeedAnimal(IEater eater)
        {
            VendingMachine animalSnackMachine = this.GetVendingMachine();

            // Find food price.
            decimal price = animalSnackMachine.DetermineFoodPrice(eater.Weight);

            // Check if guest has enough money on hand and withdraw from account if necessary.
            if (this.wallet.MoneyBalance < price)
            {
                this.WithdrawMoney(price * 10);
            }

            // Get money from wallet.
            decimal payment = this.wallet.RemoveMoney(price);

            // Buy food.
            Food food = animalSnackMachine.BuyFood(payment);

            // Feed animal.
            eater.Eat(food);
        }
Пример #13
0
 public void Eat()
 {
     _eater?.Eat();
 }
Пример #14
0
 public void FeedTo(IEater creature)
 {
     creature.Eat(Nutrition);
     Destroy(gameObject);
 }
Пример #15
0
 public void Eat(IEater eater, Food food)
 {
     eater.Eat(food);
     this.ShowAffection();
 }
Пример #16
0
 //abstraction
 private static void Eat(IEater eater)
 {
     eater.Eat();
 }