コード例 #1
0
        public void Should_ThrowException_With_IllFormedSeparator()
        {
            Assert.Throws <ArgumentException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a={", null);
            });

            Assert.Throws <ArgumentException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a=}", null);
            });

            Assert.Throws <ArgumentException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a={{}}", null);
            });

            Assert.Throws <ArgumentException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a={}}", null);
            });

            Assert.Throws <ArgumentException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a={}{", null);
            });
        }
コード例 #2
0
 public void Should_ThrowException_When_MaxValueCountOutOfRange()
 {
     Assert.Throws <ArgumentOutOfRangeException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("a", null, -1);
     });
 }
コード例 #3
0
 public void Should_ThrowException_When_DefaultHandlerRequiresValue()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("<>=", null);
     });
 }
コード例 #4
0
 public void Should_ThrowException_When_OptionTypesConflict()
 {
     Assert.Throws <InvalidDataException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("a=|b:", null);
     });
 }
コード例 #5
0
 public void Should_ThrowException_When_PrototypeEmpty()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("", null);
     });
 }
コード例 #6
0
 public void Should_ThrowException_When_MaxValueCountZero_And_RequiredType()
 {
     Assert.Throws <ArgumentException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("a=", null, 0);
     });
 }
コード例 #7
0
 public void Should_ThrowException_When_OptionNameEmpty()
 {
     Assert.Throws <InvalidDataException>(delegate
     {
         // ReSharper disable once UnusedVariable
         var option = new DefaultOption("a|b||c=", null);
     });
 }
コード例 #8
0
        public void Should_Not_ThrowException()
        {
            // ReSharper disable NotAccessedVariable
            // ReSharper disable RedundantAssignment
            var ex = Record.Exception(() =>
            {
                var option = new DefaultOption("a|b=", null, 2);
                option     = new DefaultOption("t|<>=", null, 1);
                option     = new DefaultOption("a", null, 0);
            });

            // ReSharper restore RedundantAssignment
            // ReSharper restore NotAccessedVariable

            Assert.Null(ex);
        }
コード例 #9
0
        public void Should_ThrowException_When_CannotProvideSeparatorsWhenTakingOneValue()
        {
            Assert.Throws <InvalidDataException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a==", null);
            });

            Assert.Throws <InvalidDataException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a={}", null);
            });

            Assert.Throws <InvalidDataException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var option = new DefaultOption("a=+-*/", null);
            });
        }
コード例 #10
0
ファイル: ConsoleIO.cs プロジェクト: MidgeOnGithub/trvs-core
        /// <summary>
        ///     Gives a yes/no prompt and evaluates user response.
        /// </summary>
        /// <returns>
        ///     <see langword="true"/> if <c>yes</c>/<c>y</c>, <see langword="false"/> if <c>no</c>/<c>n</c>
        /// </returns>
        public static bool UserPromptYesNo(string promptText = "", DefaultOption option = DefaultOption.None)
        {
            if (string.IsNullOrEmpty(promptText))
            {
                promptText = "Yes or no? " + option switch
                {
                    DefaultOption.Yes => "[Y/n]",
                    DefaultOption.No => "[y/N]",
                    _ => "[y/n]"
                } +": ";
            }

            bool value      = false;
            bool validInput = false;

            while (!validInput)
            {
                Console.Write(promptText);
                string inputString = Console.ReadLine();
                Console.WriteLine();
                bool emptyOrNull = string.IsNullOrEmpty(inputString);
                if (!emptyOrNull || option != DefaultOption.None)
                {
                    inputString = inputString?.Trim().ToLower();
                    if (inputString == "yes" || inputString == "y" || (emptyOrNull && option == DefaultOption.Yes))
                    {
                        value      = true;
                        validInput = true;
                    }
                    else if (inputString == "no" || inputString == "n" || (emptyOrNull && option == DefaultOption.No))
                    {
                        validInput = true;
                    }
                }
            }

            return(value);
        }
コード例 #11
0
        /// <summary>
        /// Set the XKB layout from the IBus keyboard.
        /// </summary>
        /// <remarks>
        /// This mimics the behavior of the ibus panel applet code.
        /// </remarks>
        protected override void SelectKeyboard(KeyboardDescription keyboard)
        {
            var ibusKeyboard = keyboard as IbusKeyboardDescription;

            var parentLayout = ibusKeyboard.ParentLayout;

            if (parentLayout == "en")
            {
                parentLayout = "us";                    // layout is a country code, not a language code!
            }
            var variant = ibusKeyboard.IBusKeyboardEngine.LayoutVariant;
            var option  = ibusKeyboard.IBusKeyboardEngine.LayoutOption;

            Debug.Assert(parentLayout != null);

            bool need_us_layout = false;

            foreach (string latinLayout in LatinLayouts)
            {
                if (parentLayout == latinLayout && variant != "eng")
                {
                    need_us_layout = true;
                    break;
                }
                if (!String.IsNullOrEmpty(variant) && String.Format("{0}({1})", parentLayout, variant) == latinLayout)
                {
                    need_us_layout = true;
                    break;
                }
            }

            if (String.IsNullOrEmpty(parentLayout) || parentLayout == "default")
            {
                parentLayout = DefaultLayout;
                variant      = DefaultVariant;
            }
            if (String.IsNullOrEmpty(variant) || variant == "default")
            {
                variant = null;
            }
            if (String.IsNullOrEmpty(option) || option == "default")
            {
                option = DefaultOption;
            }
            else if (!string.IsNullOrEmpty(DefaultOption))
            {
                if (DefaultOption.Split(',').Contains(option, StringComparison.InvariantCulture))
                {
                    option = DefaultOption;
                }
                else
                {
                    option = String.Format("{0},{1}", DefaultOption, option);
                }
            }

            if (need_us_layout)
            {
                parentLayout = parentLayout + ",us";
                // If we have a variant, we need to indicate an empty variant to
                // match the "us" layout.
                if (!String.IsNullOrEmpty(variant))
                {
                    variant = variant + ",";
                }
            }

            SetXkbLayout(parentLayout, variant, option);

            if (!ibusKeyboard.Name.StartsWith("xkb:", StringComparison.InvariantCulture))
            {
                // Set the IBus keyboard
                var context = GlobalCachedInputContext.InputContext;
                context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName);
            }
        }
コード例 #12
0
ファイル: ApiActionFilter.cs プロジェクト: qiqigou/QuickFrame
 /// <summary>
 /// 方法执行后拦截
 /// </summary>
 /// <param name="context"></param>
 public void OnActionExecuted(ActionExecutedContext context) => DefaultOption.EmptyFunc();
コード例 #13
0
        /// <summary>
        /// Run Test Cases for CMDLineParser
        /// </summary>
        public static void RunTests()
        {
            Console.WriteLine("\nStarting CMDLineParser tests:\n");
            //create parser
            CMDLineParser parser = new CMDLineParser();
            parser.throwInvalidOptionsException = false;

            //add Options
            #region addOptions
            CMDLineParser.Option DebugOption = parser.AddBoolSwitch("-Debug", "Print Command Line Parser Debug information");
            DebugOption.AddAlias("/Debug");
            CMDLineParser.Option OptionOpenfolder = parser.AddBoolSwitch("/openfolder", "Open files in folder if path is a folder");
            OptionOpenfolder.AddAlias("-openfolder");
            CMDLineParser.Option UserNameOpt = parser.AddStringParameter("-User="******"User Name", true);
            UserNameOpt.AddAlias("-U");
            CMDLineParser.NumberOption DoubleOpt = parser.AddDoubleParameter("-DoubleNum", "A Double", false);
            NumberFormatInfo numberformat = (new CultureInfo("de-DE", false)).NumberFormat;
            CMDLineParser.NumberOption FormatedNumOpt = parser.AddDoubleParameter("-NegNum", "A negativ Number", false, numberformat);
            CMDLineParser.Option IntNumOpt = parser.AddIntParameter("-IntNum", "A Integer Number", false);

            //Test creation of an invalid option - Throws exception
            string test = "Test creation of an invalid option";
            string testcomment = " - " + test + " - :";
            try
            {
                CMDLineParser.Option InvalidOpt = parser.AddStringParameter("-Option Nr1", "Invalid Option", false);
                Console.WriteLine("\nTestFailed: " + testcomment);
            }
            catch (CMDLineParser.CMDLineParserException ex)
            {

                Console.WriteLine("\nTestOK: " + testcomment + "Caught Error: " + ex.Message);
            }
            #endregion

            //do tests and write results to the console window
            #region Tests
            //test missing required opt -U
            String[] testmissingreqopt = { "/Debug" }; //missing required opt -U
            TestException("missing required opt -U", parser, testmissingreqopt, typeof(CMDLineParser.MissingRequiredOptionException));

            //test neg. integer
            String[] test1 = { "-UChris", "-NegNum", "-13,56", "-IntNum", "-123", "/Debug" };
            TestOption("test neg. integer", parser, test1, IntNumOpt);

            //test Double Option
            double val = -10113.56;
            String[] testDoubleOptPoint = { "-UChris", "-DoubleNum", "-10113.56" }; //test formated double
            String[] testDoubleOptComma = { "-UChris", "-DoubleNum", "-10113,56" }; //test formated double
            TestOptionValue("testDoubleOpt-dec.point", parser, testDoubleOptPoint, DoubleOpt, val);
            TestOptionValue("testDoubleOpt-dec.comma", parser, testDoubleOptComma, DoubleOpt, val);

            //test formated (globalized) double
            String[] test2 = { "-UChris", "-NegNum", "-10.113,56", "-IntNum", "123", "/Debug" }; //test formated double
            TestOption("test formated double", parser, test2, FormatedNumOpt);

            //test wrong int format
            String[] test3 = { "-UChris", "-IntNum", "123.00", "/Debug" }; //test wrong int format
            TestException("test wrong int format", parser, test3, typeof(CMDLineParser.ParameterConversionException));

            //test InvalidOptionsException
            String[] test4 = { "-UChris", "-Inv", "-IntNum", "-123", "/Debug", "/Inv2" }; //invalid options found
            parser.throwInvalidOptionsException = true;
            TestException("invalid options found", parser, test4, typeof(CMDLineParser.InvalidOptionsException));
            //parser.Debug();

            //test custom (subclassed) option
            String[] testDate = { "-Date", "2001-11-22" }; //test custom (subclassed) option

            // New parser instance
            CMDLineParser parser2 = new CMDLineParser();

            parser2.throwInvalidOptionsException = true;
            PastDateOption DateOpt = new PastDateOption("-Date", "A test Date", false);
            parser2.AddOption(DateOpt);
            TestOption("test custom (subclassed) option", parser2, testDate, DateOpt);
            //parser2.Debug();

            //Test missing parseValue method
            MissingMethodOption missMethOpt = new MissingMethodOption("-missing", "test opt", false);
            parser2.AddOption(missMethOpt);
            string[] testmiss = { "-missing", "123" };
            TestException("Test missing parseValue method", parser2, testmiss, typeof(CMDLineParser.ParameterConversionException));

            //test 'help'
            parser2.AddHelpOption();
            parser2.isConsoleApplication = true;
            parser2.throwInvalidOptionsException = false;
            String[] testh = { "-?" };
            TestOption("test help", parser2, testh, null);

            //test generic DefaultOption ( using Convert.ChangeType..)
            //one of the two methods will fail depend on your system settings
            double dval = -10113.56;
            String[] testDefOpt1 = { "/Debug", "-NegNum", "-10113.56"}; //test formated double
            String[] testDefOpt2 = { "/Debug", "-NegNum", "-10113,56"}; //test formated double

            DefaultOption defnumop = new DefaultOption("-NegNum", "Test default Option", typeof(double), false);
            parser2.AddOption(defnumop);
            TestOptionValue("defnumop - dec.point", parser2, testDefOpt1, defnumop, dval);
            TestOptionValue("defnumop - dec.comma", parser2, testDefOpt2, defnumop, dval);

            #endregion

            parser2.Debug();

            //showCulturinfos();
        }
コード例 #14
0
        /// <summary>
        /// Call for starting parsing by the contained rules, using provided crude information html content string.
        /// </summary>
        public PageParseResult Parse(string relativeUri = null)
        {
            if (fastWeb == null)
            {
                fastWeb = new FastWeb2(Domain);
            }

            var rawHtml = fastWeb.Get(relativeUri);

            //PreprocessPlan
            string processedHtml = PagePreprocess == null ? rawHtml : rawHtml.Mold(PagePreprocess);

            //interpret as document node
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(processedHtml);
            HtmlNode entireDocumentNode = document.DocumentNode;

            var pageParseResult = new PageParseResult
            {
                Title = Title.ExtractSingle(node: entireDocumentNode)
            };

            if (Subtitle != null)
            {
                pageParseResult.Title += " " + Subtitle.ExtractSingleFromNode(node: entireDocumentNode);
            }

            if (Thumbnail != null)
            {
                pageParseResult.ThumbPath = Thumbnail.ExtractSingleFromNode(node: entireDocumentNode);
            }

            //Parsing Actual Options
            if (DefaultOptionMode != DefaultOptionMode.Single)
            {
                try
                {
                    bool isRegex = OptionsList.SelectMethod == SelectMethod.Regex;

                    IEnumerable <object> crudeOptions;

                    if (isRegex)
                    {
                        crudeOptions = OptionsList.ExtractList(entireDocumentNode.InnerHtml);
                    }
                    else
                    {
                        crudeOptions = OptionsList.ExtractList(entireDocumentNode);
                    }

                    foreach (var entry in crudeOptions)
                    {
                        var optionParseResult = isRegex ? ActualOption.Parse(entry as string) : ActualOption.Parse(entry as HtmlNode);

                        if (optionParseResult.Price.Amount == 0 && PriceMode != PriceMode.Add)
                        {
                            continue;
                        }

                        pageParseResult.OptionParseResults.Add(optionParseResult);
                    }
                }
                catch (NullReferenceException nrex) when(DefaultOptionMode == DefaultOptionMode.Alongside || DefaultOptionMode == DefaultOptionMode.Alternative)
                {
                    //swallow when actual options absence allowed
                    Logger.Log(nrex.Message + " @ PageParsing of " + relativeUri);
                }
            }

            //Default Option Logic
            if (DefaultOptionMode != DefaultOptionMode.Ignore)
            {
                if (DefaultOptionMode == DefaultOptionMode.Single)
                {
                    Logger.Log(Domain + " has 1 option per page setup. Add all options separately.");
                }

                OptionParseResult defaultOption;

                try
                {
                    defaultOption           = DefaultOption.Parse(entireDocumentNode);
                    defaultOption.PropertyA = defaultOption.Code = DefaultOptionMode.ToString();
                }
                catch (NullReferenceException nrex)
                {
                    Logger.Log(nrex.Message + " @ PageParsing of " + relativeUri);
                    throw;
                }

                //Prices correction according to Price Mode Setting
                if (PriceMode == PriceMode.Add)
                {
                    foreach (OptionParseResult optParseRes in pageParseResult.OptionParseResults)
                    {
                        optParseRes.Price.Amount += defaultOption.Price.Amount;
                    }
                }

                //Adding default option to the options list, if necessary
                if (DefaultOptionMode == DefaultOptionMode.Alongside ||
                    DefaultOptionMode == DefaultOptionMode.Single ||
                    (DefaultOptionMode == DefaultOptionMode.Alternative && pageParseResult.OptionParseResults.Count == 0))
                {
                    pageParseResult.OptionParseResults.Add(defaultOption);
                }
            }

            //Prices correction according to the Main Currency & Shop Ordering Rules
            foreach (OptionParseResult optParseRes in pageParseResult.OptionParseResults)
            {
                optParseRes.Price = optParseRes.Price.AsMainCurrency();
                var value = optParseRes.Price.Amount;

                value /= 1 + OrderDeduction;

                if (OrderExtra != null && OrderLimit != null && OrderLimit.AsMainCurrency().Amount > 0)
                {
                    decimal limitValue      = OrderLimit.AsMainCurrency().Amount;
                    decimal orderExtraValue = OrderExtra.AsMainCurrency().Amount;
                    decimal piecesPerOrder  = limitValue / value;
                    decimal extraPerPiece   = orderExtraValue / piecesPerOrder;
                    value += extraPerPiece;
                }

                optParseRes.Price.Amount = value;
            }

            return(pageParseResult);
        }
コード例 #15
0
ファイル: OptionTest.cs プロジェクト: pmq20/mono_forked
        public void Exceptions()
        {
            object p = null;

            Utils.AssertException(typeof(ArgumentNullException),
                                  "Argument cannot be null.\nParameter name: prototype",
                                  p, v => { new DefaultOption(null, null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot be the empty string.\nParameter name: prototype",
                                  p, v => { new DefaultOption("", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Empty option names are not supported.\nParameter name: prototype",
                                  p, v => { new DefaultOption("a|b||c=", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Conflicting option types: '=' vs. ':'.\nParameter name: prototype",
                                  p, v => { new DefaultOption("a=|b:", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "The default option handler '<>' cannot require values.\nParameter name: prototype",
                                  p, v => { new DefaultOption("<>=", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "The default option handler '<>' cannot require values.\nParameter name: prototype",
                                  p, v => { new DefaultOption("<>:", null); });
            Utils.AssertException(null, null,
                                  p, v => { new DefaultOption("t|<>=", null, 1); });
            Utils.AssertException(typeof(ArgumentException),
                                  "The default option handler '<>' cannot require values.\nParameter name: prototype",
                                  p, v => { new DefaultOption("t|<>=", null, 2); });
            Utils.AssertException(null, null,
                                  p, v => { new DefaultOption("a|b=", null, 2); });
            Utils.AssertException(typeof(ArgumentOutOfRangeException),
                                  "Argument is out of range.\nParameter name: maxValueCount",
                                  p, v => { new DefaultOption("a", null, -1); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide maxValueCount of 0 for OptionValueType.Required or " +
                                  "OptionValueType.Optional.\nParameter name: maxValueCount",
                                  p, v => { new DefaultOption("a=", null, 0); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={\".\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a=}\".\nParameter name: prototype",
                                  p, v => { new DefaultOption("a=}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={{}}\".\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={{}}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={}}\".\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Ill-formed name/value separator found in \"a={}{\".\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}{", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
                                  p, v => { new DefaultOption("a==", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
                                  p, v => { new DefaultOption("a={}", null); });
            Utils.AssertException(typeof(ArgumentException),
                                  "Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
                                  p, v => { new DefaultOption("a=+-*/", null); });
            Utils.AssertException(null, null,
                                  p, v => { new DefaultOption("a", null, 0); });
            Utils.AssertException(null, null,
                                  p, v => { new DefaultOption("a", null, 0); });
            Utils.AssertException(null, null,
                                  p, v => {
                var d = new DefaultOption("a", null);
                Assert.AreEqual(d.GetValueSeparators().Length, 0);
            });
            Utils.AssertException(null, null,
                                  p, v => {
                var d      = new DefaultOption("a=", null, 1);
                string[] s = d.GetValueSeparators();
                Assert.AreEqual(s.Length, 0);
            });
            Utils.AssertException(null, null,
                                  p, v => {
                var d      = new DefaultOption("a=", null, 2);
                string[] s = d.GetValueSeparators();
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s [0], ":");
                Assert.AreEqual(s [1], "=");
            });
            Utils.AssertException(null, null,
                                  p, v => {
                var d      = new DefaultOption("a={}", null, 2);
                string[] s = d.GetValueSeparators();
                Assert.AreEqual(s.Length, 0);
            });
            Utils.AssertException(null, null,
                                  p, v => {
                var d      = new DefaultOption("a={-->}{=>}", null, 2);
                string[] s = d.GetValueSeparators();
                Assert.AreEqual(s.Length, 2);
                Assert.AreEqual(s [0], "-->");
                Assert.AreEqual(s [1], "=>");
            });
            Utils.AssertException(null, null,
                                  p, v => {
                var d      = new DefaultOption("a=+-*/", null, 2);
                string[] s = d.GetValueSeparators();
                Assert.AreEqual(s.Length, 4);
                Assert.AreEqual(s [0], "+");
                Assert.AreEqual(s [1], "-");
                Assert.AreEqual(s [2], "*");
                Assert.AreEqual(s [3], "/");
            });
        }
コード例 #16
0
ファイル: OptionTest.cs プロジェクト: nlhepler/mono
		public void Exceptions ()
		{
			object p = null;
			Utils.AssertException (typeof(ArgumentNullException), 
					"Argument cannot be null.\nParameter name: prototype", 
					p, v => { new DefaultOption (null, null); });
			Utils.AssertException (typeof(ArgumentException), 
					"Cannot be the empty string.\nParameter name: prototype",
					p, v => { new DefaultOption ("", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Empty option names are not supported.\nParameter name: prototype",
					p, v => { new DefaultOption ("a|b||c=", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Conflicting option types: '=' vs. ':'.\nParameter name: prototype",
					p, v => { new DefaultOption ("a=|b:", null); });
			Utils.AssertException (typeof(ArgumentException),
					"The default option handler '<>' cannot require values.\nParameter name: prototype",
					p, v => { new DefaultOption ("<>=", null); });
			Utils.AssertException (typeof(ArgumentException),
					"The default option handler '<>' cannot require values.\nParameter name: prototype",
					p, v => { new DefaultOption ("<>:", null); });
			Utils.AssertException (null, null,
					p, v => { new DefaultOption ("t|<>=", null, 1); });
			Utils.AssertException (typeof(ArgumentException),
					"The default option handler '<>' cannot require values.\nParameter name: prototype",
					p, v => { new DefaultOption ("t|<>=", null, 2); });
			Utils.AssertException (null, null,
					p, v => { new DefaultOption ("a|b=", null, 2); });
			Utils.AssertException (typeof(ArgumentOutOfRangeException),
					"Argument is out of range.\nParameter name: maxValueCount",
					p, v => { new DefaultOption ("a", null, -1); });
			Utils.AssertException (typeof(ArgumentException),
					"Cannot provide maxValueCount of 0 for OptionValueType.Required or " +
						"OptionValueType.Optional.\nParameter name: maxValueCount",
					p, v => { new DefaultOption ("a=", null, 0); });
			Utils.AssertException (typeof(ArgumentException),
					"Ill-formed name/value separator found in \"a={\".\nParameter name: prototype",
					p, v => { new DefaultOption ("a={", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Ill-formed name/value separator found in \"a=}\".\nParameter name: prototype",
					p, v => { new DefaultOption ("a=}", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Ill-formed name/value separator found in \"a={{}}\".\nParameter name: prototype",
					p, v => { new DefaultOption ("a={{}}", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Ill-formed name/value separator found in \"a={}}\".\nParameter name: prototype",
					p, v => { new DefaultOption ("a={}}", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Ill-formed name/value separator found in \"a={}{\".\nParameter name: prototype",
					p, v => { new DefaultOption ("a={}{", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
					p, v => { new DefaultOption ("a==", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
					p, v => { new DefaultOption ("a={}", null); });
			Utils.AssertException (typeof(ArgumentException),
					"Cannot provide key/value separators for Options taking 1 value(s).\nParameter name: prototype",
					p, v => { new DefaultOption ("a=+-*/", null); });
			Utils.AssertException (null, null,
					p, v => { new DefaultOption ("a", null, 0); });
			Utils.AssertException (null, null,
					p, v => { new DefaultOption ("a", null, 0); });
			Utils.AssertException (null, null, 
					p, v => {
						var d = new DefaultOption ("a", null);
						Assert.AreEqual (d.GetValueSeparators ().Length, 0);
					});
			Utils.AssertException (null, null,
					p, v => {
						var d = new DefaultOption ("a=", null, 1);
						string[] s = d.GetValueSeparators ();
						Assert.AreEqual (s.Length, 0);
					});
			Utils.AssertException (null, null,
					p, v => {
						var d = new DefaultOption ("a=", null, 2);
						string[] s = d.GetValueSeparators ();
						Assert.AreEqual (s.Length, 2);
						Assert.AreEqual (s [0], ":");
						Assert.AreEqual (s [1], "=");
					});
			Utils.AssertException (null, null,
					p, v => {
						var d = new DefaultOption ("a={}", null, 2);
						string[] s = d.GetValueSeparators ();
						Assert.AreEqual (s.Length, 0);
					});
			Utils.AssertException (null, null,
					p, v => {
						var d = new DefaultOption ("a={-->}{=>}", null, 2);
						string[] s = d.GetValueSeparators ();
						Assert.AreEqual (s.Length, 2);
						Assert.AreEqual (s [0], "-->");
						Assert.AreEqual (s [1], "=>");
					});
			Utils.AssertException (null, null,
					p, v => {
						var d = new DefaultOption ("a=+-*/", null, 2);
						string[] s = d.GetValueSeparators ();
						Assert.AreEqual (s.Length, 4);
						Assert.AreEqual (s [0], "+");
						Assert.AreEqual (s [1], "-");
						Assert.AreEqual (s [2], "*");
						Assert.AreEqual (s [3], "/");
					});
		}
コード例 #17
0
ファイル: ApiResultFilter.cs プロジェクト: qiqigou/QuickFrame
 /// <summary>
 /// 生成结果后拦截
 /// </summary>
 /// <param name="context"></param>
 public void OnResultExecuted(ResultExecutedContext context) => DefaultOption.EmptyFunc();