Exemplo n.º 1
0
        public void Consume_Using_Only_The_First_Parameter_That_Can_Consume()
        {
            // arrange
            var parser = new Parser("base");
            var info   = new IterationInfo("a b c".Split(' '));

            var mock0 = new Mock <Parameter>();

            mock0.SetupAllProperties();
            mock0.Setup(p => p.CanConsume(It.IsAny <object>(), It.IsAny <IterationInfo>())).Returns(new
                                                                                                    ConsumptionResult(info.Consume(1), 1, mock0.Object));
            mock0.Setup(p => p.Consume(It.IsAny <object>(), It.IsAny <ConsumptionRequest>()))
            .Returns(new ConsumptionResult(info.Consume(1), 1, mock0.Object));
            parser.AddParameter(mock0.Object);

            var mock1 = new Mock <Parameter>();

            mock1.SetupAllProperties();
            mock1.Setup(p => p.CanConsume(It.IsAny <object>(), It.IsAny <IterationInfo>()))
            .Returns(new ConsumptionResult(info.Consume(1), 1, mock1.Object));
            mock1.Setup(p => p.Consume(It.IsAny <object>(), It.IsAny <ConsumptionRequest>()))
            .Returns(new ConsumptionResult(info.Consume(1), 1, mock1.Object));
            parser.AddParameter(mock1.Object);

            // act
            // assert
            parser.Consume("", new ConsumptionRequest(info));
            mock0.Verify(p => p.Consume(It.IsAny <object>(), It.IsAny <ConsumptionRequest>()), Times.Once);
            mock1.Verify(p => p.Consume(It.IsAny <object>(), It.IsAny <ConsumptionRequest>()), Times.Never);
        }
Exemplo n.º 2
0
        public void NonPresentNoValueParameterShouldBeFalse()
        {
            var args   = new string[] { "--stuff", "and", "--things" };
            var parser = new Parser();

            parser.AddParameter("stuff", null, true);
            parser.AddParameter("things");
            parser.AddParameter("this-should-be-false");

            var dict = parser.Parse(args);

            Assert.IsFalse((bool)dict["this-should-be-false"]);
        }
Exemplo n.º 3
0
        public void ShouldFailIfArgumentHasNoValue()
        {
            var args   = new string[] { "--arg-with-no-value" };
            var parser = new Parser();

            parser.AddParameter("arg-with-no-value", "n", true);
            parser.Parse(args);
        }
Exemplo n.º 4
0
        public void ShouldFailIfRequiredArgumentHasNoValue()
        {
            var args = new string[] { "--not-required" };

            var parser = new Parser();

            parser.AddParameter("required", "r", true, true);

            parser.Parse(args);
        }
Exemplo n.º 5
0
        public void ShouldFailWhenParameterIsValue()
        {
            var args = new string[] { "--arg1", "-b", "bleh", "--arg3" };

            var parser = new Parser();

            parser.AddParameter("arg1", "a", true);

            parser.Parse(args);
        }
Exemplo n.º 6
0
        public void ShouldParseValidQuery()
        {
            var args = new string[] { "--arg1", "blah", "this is a random value", "-b", "bleh", "bleh", "--arg3" };

            var parser = new Parser();

            parser.AddOrderedValue("randovalue");
            parser.AddOrderedValue("anotherrandovalue");
            parser.AddParameter("arg1", "a", true);
            parser.AddParameter("arg2", "b", true);
            parser.AddParameter("arg3", "c", false);

            var dict = parser.Parse(args);

            foreach (var kvp in dict)
            {
                Console.WriteLine(kvp.Key + ": " + kvp.Value);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Adds the parameter
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <param name="helpSetupCallback">The help setup callback.</param>
 protected void AddParameterInternal(Parameter parameter, Action <ParameterHelpBuilder> helpSetupCallback = null)
 {
     Parser.AddParameter(parameter);
     if (helpSetupCallback != null)
     {
         var builder = new ParameterHelpBuilder(parameter);
         helpSetupCallback(builder);
         parameter.Help = builder.Build();
     }
     OnParameterCreated(parameter);
 }
Exemplo n.º 8
0
        public void Indicate_It_Can_Consume_When_One_Of_Its_Parameters_Can_Consume()
        {
            // arrange
            var parser = new Parser("base");
            var info   = new IterationInfo("a b c".Split(' '));
            var mock   = new Mock <Parameter>();

            mock.Setup(p => p.CanConsume(It.IsAny <object>(), info))
            .Returns(new ConsumptionResult(info.Consume(1), 1, mock.Object));
            parser.AddParameter(mock.Object);

            // act
            // assert
            parser.CanConsume(new object(), info).NumConsumed.Should().Be(1);
        }
Exemplo n.º 9
0
        public void Reset_All_Parameters_When_Reset()
        {
            // arrange
            var mock = new Mock <Parameter>();

            mock.SetupAllProperties();
            mock.Object.HasBeenConsumed = true;
            mock.CallBase = true;
            var parser = new Parser("a");

            parser.AddParameter(mock.Object);

            // act
            parser.Reset();

            // assert
            mock.Object.HasBeenConsumed.Should().BeFalse();
        }