示例#1
0
        /// <summary>
        ///     Determines whether this parameter can consume the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="info">The information.</param>
        /// <returns>The result of the consumption</returns>
        public override ConsumptionResult CanConsume(object instance, IterationInfo info)
        {
            if (HasBeenConsumed)
            {
                return(new ConsumptionResult(info, 0, null));
            }
            var values = info.FromNowOn().Take(MaxAllowed).ToArray();

            return(new ConsumptionResult(info, values.Length, this));
        }
示例#2
0
        public void Return_The_Current_Item_And_All_SubSequent_Items()
        {
            // arrange
            var info0 = new IterationInfo(new string[0], 0);
            var info1 = new IterationInfo("-h".Split(' '), 0);
            var info2 = new IterationInfo("-v something".Split(' '), 0);
            var info3 = new IterationInfo("a b c d e".Split(' '), 1);

            // act
            // assert
            info0.FromNowOn().Should().BeEmpty();
            info1.FromNowOn().Should().BeEquivalentTo("-h".Split(' '));
            info2.FromNowOn().Should().BeEquivalentTo("-v something".Split(' '));
            info3.FromNowOn().Should().BeEquivalentTo("b c d e".Split(' '));
        }
示例#3
0
        /// <summary>
        ///     Determines whether this parameter can consume the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="info">The information.</param>
        /// <returns>The result of the consumption</returns>
        public override ConsumptionResult CanConsume(object instance, IterationInfo info)
        {
            if (!IsLetterMatch(info) && !IsWordMatch(info))
            {
                return(new ConsumptionResult(info, 0, null));
            }
            var canBeTaken = info.FromNowOn().ToList();

            if (canBeTaken.Count < MinRequired)
            {
                return(new ConsumptionResult(info, 0, null));
            }
            var actuallyTaken = canBeTaken.Take(MaxAllowed).ToList();

            return(new ConsumptionResult(info, actuallyTaken.Count, this));
        }