Example #1
0
        public void Actually_Configures()
        {
            bool marker = false;

            void op(CommandOption o)
            {
                marker = true;
            }

            var cfg = new EnumOptionConfigBuilder <TestEnum>(template, desc)
                      .AllowMultiple(false)
                      .Configuration(op)
                      .DescribeArity(false)
                      .DescribeValues(false)
                      .Inherited(true)
                      .ThrowOnInvalidOption(true)
                      .Use(TestEnum.abc)
                      .Build();

            Assert.AreEqual(false, cfg.AllowMultiple);
            Assert.AreEqual(false, cfg.DescribeArity);
            Assert.AreEqual(false, cfg.DescribeValues);
            Assert.AreEqual(true, cfg.Inherited);
            Assert.AreEqual(true, cfg.ThrowOnInvalidOption);

            cfg.Configuration(null);
            Assert.IsTrue(marker);
        }
Example #2
0
        public void Sets_default_values()
        {
            var cfg = new EnumOptionConfigBuilder <TestEnum>(template, desc)
                      .Use(TestEnum.abc)
                      .Build();

            Assert.AreEqual(template, cfg.Template);
            Assert.AreEqual(desc, cfg.Description);

            Assert.AreEqual(true, cfg.AllowMultiple);
            Assert.AreEqual(true, cfg.DescribeArity);
            Assert.AreEqual(true, cfg.DescribeValues);
            Assert.AreEqual(false, cfg.Inherited);
            Assert.AreEqual(false, cfg.ThrowOnInvalidOption);

            // No exact way to test it's a NoOp, but at least this tries.
            cfg.Configuration(null);
        }
Example #3
0
        public void Prevents_Double_Configure()
        {
            var builder = new EnumOptionConfigBuilder <TestEnum>(template, desc);

            var actions = new Func <EnumOptionConfigBuilder <TestEnum> >[]
            {
                () => builder.AllowMultiple(true),
                () => builder.Configuration((x) => { }),
                () => builder.DescribeArity(true),
                () => builder.DescribeValues(true),
                () => builder.Inherited(true),
                () => builder.ThrowOnInvalidOption(true),
            };

            foreach (var action in actions)
            {
                action();
                Assert.ThrowsException <InvalidOperationException>(() => action());
            }
        }