当前位置: 首页>>代码示例>>C#>>正文


C# ParseResult.GetErrorMessage方法代码示例

本文整理汇总了C#中ParseResult.GetErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:C# ParseResult.GetErrorMessage方法的具体用法?C# ParseResult.GetErrorMessage怎么用?C# ParseResult.GetErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParseResult的用法示例。


在下文中一共展示了ParseResult.GetErrorMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseResult_General

        public void ParseResult_General()
        {
            // Make sure that passing in the [Success] status always fails.
            var ex = new Lazy<Exception>(() => new Exception());
            new Action(() => new ParseResult(ParseResultType.Success))
                .AssertThrowsExact<ArgumentException>(
                    "Did not throw when passed [Success] code (0).");
            new Action(() => new ParseResult(ParseResultType.Success, ex))
                .AssertThrowsExact<ArgumentException>(
                    "Did not throw when passed [Success] code (1).");

            // Make sure that an invalid status fails.
            new Action(() => new ParseResult((ParseResultType)(-1)))
                .AssertThrowsExact<ArgumentException>(
                    "Did not throw on invalid status code (0).");
            new Action(() => new ParseResult((ParseResultType)(-1), ex))
                    .AssertThrowsExact<ArgumentException>(
                        "Did not throw on invalid status code (1).");

            // Make sure that a null exception provider fails.
            new Action(
                () => new ParseResult(ParseResultType.InvalidVersion, null))
                .AssertThrows<ArgumentNullException>(
                    "Did not throw on null exception provider.");

            // Tests that accessing the properties of a default-constructed
            // [ParseResult] fails with an exception.
            var defPr = new ParseResult();
            new Action(() => defPr.Type.GetHashCode())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid access (0).");
            new Action(() => defPr.ComparatorSets.GetHashCode())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid access (1).");
            new Action(() => defPr.GetErrorMessage())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid access (2).");
            new Action(() => defPr.CreateException())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid access (3).");

            // Makes sure that attempting to create an exception/retrieve an
            // error message with a success-state [ParseResult] fails.
            var sucPr = new ParseResult(new ComparatorToken[0][]);
            new Action(() => sucPr.GetErrorMessage())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid [GetErrorMessage] call.");
            new Action(() => sucPr.CreateException())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on invalid [CreateException] call.");
        }
开发者ID:McSherry,项目名称:McSherry.SemanticVersioning,代码行数:51,代码来源:RangeIntlParsingTests.cs

示例2: ParseResult_DefaultConstructed

        public void ParseResult_DefaultConstructed()
        {
            // Default-constructed parse results don't contain a valid version or
            // an error code, so the only thing they can reasonably do is throw
            // an exception when you try to use them.
            var pr = new ParseResult();

            new Action(() => { var x = pr.Type == ParseResultType.Success; })
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on use of default-constructed result (0).");

            new Action(() => { var x = pr.Version == null; })
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on use of default-constructed result (1).");

            new Action(() => pr.GetErrorMessage())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on use of default-constructed result (2).");

            new Action(() => pr.CreateException())
                .AssertThrows<InvalidOperationException>(
                    "Did not throw on use of default-constructed result (3).");
        }
开发者ID:McSherry,项目名称:McSherry.SemanticVersioning,代码行数:23,代码来源:SemanticVersionIntlParsingTests.cs


注:本文中的ParseResult.GetErrorMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。