• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ArgumentException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ArgumentException的典型用法代码示例。如果您正苦于以下问题:C# ArgumentException类的具体用法?C# ArgumentException怎么用?C# ArgumentException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ArgumentException类属于命名空间,在下文中一共展示了ArgumentException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SendAsync_SendCloseMessageType_ThrowsArgumentExceptionWithMessage

        public async Task SendAsync_SendCloseMessageType_ThrowsArgumentExceptionWithMessage(Uri server)
        {
            using (ClientWebSocket cws = await WebSocketHelper.GetConnectedWebSocket(server, TimeOutMilliseconds, _output))
            {
                var cts = new CancellationTokenSource(TimeOutMilliseconds);

                string expectedInnerMessage = ResourceHelper.GetExceptionMessage(
                        "net_WebSockets_Argument_InvalidMessageType",
                        "Close",
                        "SendAsync",
                        "Binary",
                        "Text",
                        "CloseOutputAsync");

                var expectedException = new ArgumentException(expectedInnerMessage, "messageType");
                string expectedMessage = expectedException.Message;

                Assert.Throws<ArgumentException>(() =>
                {
                    Task t = cws.SendAsync(new ArraySegment<byte>(), WebSocketMessageType.Close, true, cts.Token);
                });

                Assert.Equal(WebSocketState.Open, cws.State);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:25,代码来源:SendReceiveTest.cs


示例2: TrueThrowsArgumentException

            public void TrueThrowsArgumentException()
            {
                var expectedEx = new ArgumentException("Custom Message", "paramName");
                var actualEx = Assert.Throws<ArgumentException>(() => Verify.False(true, "paramName", "Custom Message"));

                Assert.Equal(expectedEx.Message, actualEx.Message);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:VerifyTests.cs


示例3: StreamIdCannotBeEmptyGuid

            public void StreamIdCannotBeEmptyGuid()
            {
                var expectedEx = new ArgumentException(Exceptions.ArgumentEqualToValue.FormatWith(Guid.Empty), "streamId");
                var actualEx = Assert.Throws<ArgumentException>(() => new Snapshot(Guid.Empty, 1, new Object()));

                Assert.Equal(expectedEx.Message, actualEx.Message);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:SnapshotTests.cs


示例4: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Using ctor1 to test the message property");

        try
        {
            string randValue = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            ArgumentException argumentException = new ArgumentException(randValue);
            if (argumentException.Message != randValue)
            {
                TestLibrary.TestFramework.LogError("001", "The result is not the value as expected");
                TestLibrary.TestFramework.LogInformation("Expected: " + randValue + "; Actual: " + argumentException.Message);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:rdterner,项目名称:coreclr,代码行数:25,代码来源:argumentexceptionmessage.cs


示例5: PosTest2

 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest2: the parameter string is null.");
     try
     {
         string expectValue = null;
         ArgumentException dpoExpection = new ArgumentException();
         MethodAccessException myException = new MethodAccessException(expectValue, dpoExpection);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("002.1", "MethodAccessException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message == expectValue)
         {
             TestLibrary.TestFramework.LogError("002.2", "the Message should return the default value.");
             retVal = false;
         }
         if (!(myException.InnerException is ArgumentException))
         {
             TestLibrary.TestFramework.LogError("002.3", "the InnerException should return MethodAccessException.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:34,代码来源:methodaccessexceptionctor3.cs


示例6: SetNext

    public void SetNext() {
        var r = new DiscardRedundantWorkThrottle();
        var ax = new ArgumentException();
        var cx = new OperationCanceledException();

        // results are propagated
        var n = 0;
        r.SetNextToAction(() => n++).AssertRanToCompletion();
        n.AssertEquals(1);
        r.SetNextToFunction(() => 2).AssertRanToCompletion().AssertEquals(2);
        r.SetNextToAsyncFunction(Tasks.RanToCompletion).AssertRanToCompletion();
        r.SetNextToAsyncFunction(() => Task.FromResult(3)).AssertRanToCompletion().AssertEquals(3);

        // faulted tasks are propagated
        r.SetNextToAsyncFunction(() => Tasks.Faulted(ax)).AssertFailed<ArgumentException>();
        r.SetNextToAsyncFunction(() => Tasks.Faulted<int>(ax)).AssertFailed<ArgumentException>();

        // cancelled tasks are propagated
        r.SetNextToAsyncFunction(Tasks.Cancelled).AssertCancelled();
        r.SetNextToAsyncFunction(Tasks.Cancelled<int>).AssertCancelled();

        // thrown cancellation exceptions indicate cancellation
        r.SetNextToAsyncFunction(() => { throw cx; }).AssertCancelled();
        r.SetNextToAsyncFunction<int>(() => { throw cx; }).AssertCancelled();
        r.SetNextToAction(() => { throw cx; }).AssertCancelled();
        r.SetNextToFunction<int>(() => { throw cx; }).AssertCancelled();

        // thrown exceptions are propagated
        r.SetNextToAsyncFunction(() => { throw ax; }).AssertFailed<ArgumentException>();
        r.SetNextToAsyncFunction<int>(() => { throw ax; }).AssertFailed<ArgumentException>();
        r.SetNextToAction(() => { throw ax; }).AssertFailed<ArgumentException>();
        r.SetNextToFunction<int>(() => { throw ax; }).AssertFailed<ArgumentException>();
    }
开发者ID:NotYours180,项目名称:Twisted-Oak-Threading-Utilities,代码行数:33,代码来源:DiscardRedundantWorkThrottleTest.cs


示例7: HeaderNameCannotBeReservedName

            public void HeaderNameCannotBeReservedName(String name)
            {
                var expectedEx = new ArgumentException(Exceptions.ReservedHeaderName.FormatWith(name), nameof(name));
                var actualEx = Assert.Throws<ArgumentException>(() =>new Header(name, "value"));

                Assert.Equal(expectedEx.Message, actualEx.Message);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:HeaderTests.cs


示例8: PosTest1

 // Returns true if the expected result is right
 // Returns false if the expected result is wrong
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new instance of MethodAccessException.");
     try
     {
         string expectValue = "HELLO";
         ArgumentException notFoundException = new ArgumentException();
         MethodAccessException myException = new MethodAccessException(expectValue, notFoundException);
         if (myException == null)
         {
             TestLibrary.TestFramework.LogError("001.1", "MethodAccessException instance can not create correctly.");
             retVal = false;
         }
         if (myException.Message != expectValue)
         {
             TestLibrary.TestFramework.LogError("001.2", "the Message should return " + expectValue);
             retVal = false;
         }
         if (!(myException.InnerException is ArgumentException))
         {
             TestLibrary.TestFramework.LogError("001.3", "the InnerException should return ArgumentException.");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
         retVal = false;
     }
     return retVal;
 }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:34,代码来源:methodaccessexceptionctor3.cs


示例9: BaseTypeNotFoundThrowsArgumentException

            public void BaseTypeNotFoundThrowsArgumentException()
            {
                var expectedEx = new ArgumentException(Exceptions.TypeDoesNotDeriveFromBase.FormatWith(typeof(Exception), typeof(Object)), "paramName");
                var actualEx = Assert.Throws<ArgumentException>(() => Verify.TypeDerivesFrom(typeof(Exception), typeof(Object), "paramName"));

                Assert.Equal(expectedEx.Message, actualEx.Message);
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:7,代码来源:VerifyTests.cs


示例10: Constructor_throws_if_invalid_cache_type

        public void Constructor_throws_if_invalid_cache_type()
        {
            var exception = new ArgumentException(
                Strings.Generated_View_Type_Super_Class(typeof(object)),
                "cacheType");

            Assert.Equal(exception.Message,
                Assert.Throws<ArgumentException>(() =>
                    new DbMappingViewCacheTypeAttribute(typeof(SampleContext), typeof(object))).Message);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:10,代码来源:DbMappingViewCacheTypeAttributeTests.cs


示例11: EventTypeMustDeriveFromEvent

            public void EventTypeMustDeriveFromEvent()
            {
                // ReSharper disable NotResolvedInText
                var mapping = new ObjectEventTypeMapping();
                var expectedEx = new ArgumentException(Exceptions.TypeDoesNotDeriveFromBase.FormatWith(typeof(Event), typeof(Object)), "eventType");
                var ex = Assert.Throws<ArgumentException>(() => mapping.GetMappings(new Mock<IServiceProvider>().Object));

                Assert.Equal(expectedEx.Message, ex.Message);
                // ReSharper restore NotResolvedInText
            }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:10,代码来源:HandleMethodMappingTests.cs


示例12: Ctor

        public void Ctor()
        {
            DecoderFallbackException ex = new DecoderFallbackException();
            Assert.Null(ex.BytesUnknown);
            Assert.Equal(default(int), ex.Index);
            Assert.Null(ex.StackTrace);
            Assert.Null(ex.InnerException);
            Assert.Equal(0, ex.Data.Count);
            ArgumentException arg = new ArgumentException();

            Assert.Equal(ex.Message, arg.Message);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:DecoderFallbackExceptionTests.cs


示例13: Cannot_create_mapping_for_non_complex_property

        public void Cannot_create_mapping_for_non_complex_property()
        {
            var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var exception = 
                new ArgumentException(
                    Strings.StorageComplexPropertyMapping_OnlyComplexPropertyAllowed, 
                    "property");

            Assert.Equal(
                exception.Message,
                Assert.Throws<ArgumentException>(
                    () => new ComplexPropertyMapping(property)).Message);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:ComplexPropertyMappingTests.cs


示例14: CreateODataError_CopiesInnerExceptionInformation

        public void CreateODataError_CopiesInnerExceptionInformation()
        {
            Exception innerException = new ArgumentException("innerException");
            Exception exception = new InvalidOperationException("exception", innerException);
            var error = new HttpError(exception, true);

            ODataError oDataError = error.CreateODataError();

            Assert.Equal("An error has occurred.", oDataError.Message);
            Assert.Equal("exception", oDataError.InnerError.Message);
            Assert.Equal("System.InvalidOperationException", oDataError.InnerError.TypeName);
            Assert.Equal("innerException", oDataError.InnerError.InnerError.Message);
            Assert.Equal("System.ArgumentException", oDataError.InnerError.InnerError.TypeName);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:14,代码来源:HttpErrorExtensionsTest.cs


示例15: TestArgumentException

	// Test the ArgumentException class.
	public void TestArgumentException()
			{
				ArgumentException e;
				ExceptionTester.CheckMain(typeof(ArgumentException),
										  unchecked((int)0x80070057));
				e = new ArgumentException();
				AssertNull("ArgumentException (1)", e.ParamName);
				e = new ArgumentException("msg");
				AssertNull("ArgumentException (2)", e.ParamName);
				e = new ArgumentException("msg", "p");
				AssertEquals("ArgumentException (3)", "p", e.ParamName);
				e = new ArgumentException("msg", "p", e);
				AssertEquals("ArgumentException (4)", "p", e.ParamName);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:15,代码来源:TestSystemExceptions.cs


示例16: Ctor

        public static void Ctor()
        {
            EncoderFallbackException ex = new EncoderFallbackException();
            Assert.Equal(default(char), ex.CharUnknown);
            Assert.Equal(default(char), ex.CharUnknownHigh);
            Assert.Equal(default(char), ex.CharUnknownLow);
            Assert.Equal(default(int), ex.Index);

            Assert.Null(ex.StackTrace);
            Assert.Null(ex.InnerException);
            Assert.Equal(0, ex.Data.Count);

            ArgumentException arg = new ArgumentException();
            Assert.Equal(arg.Message, ex.Message);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:EncoderFallbackExceptionTests.cs


示例17: Constructors_throw_if_invalid_context_type

        public void Constructors_throw_if_invalid_context_type()
        {
            var cacheTypeName = typeof(SampleMappingViewCache).AssemblyQualifiedName;
            var exception = new ArgumentException(
                Strings.DbMappingViewCacheTypeAttribute_InvalidContextType(typeof(object)),
                "contextType");

            Assert.Equal(exception.Message,
                Assert.Throws<ArgumentException>(() =>
                    new DbMappingViewCacheTypeAttribute(typeof(object), typeof(SampleMappingViewCache))).Message);

            Assert.Equal(exception.Message,
                Assert.Throws<ArgumentException>(() =>
                    new DbMappingViewCacheTypeAttribute(typeof(object), cacheTypeName)).Message);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:15,代码来源:DbMappingViewCacheTypeAttributeTests.cs


示例18: CompletedCancelledFaultedTask

 public void CompletedCancelledFaultedTask() {
     Tasks.RanToCompletion().AssertRanToCompletion();
     Tasks.RanToCompletion(1).AssertRanToCompletion().AssertEquals(1);
     
     Tasks.Cancelled().AssertCancelled();
     Tasks.Cancelled<int>().AssertCancelled();
     
     var ex = new ArgumentException();
     
     Tasks.Faulted(ex).AssertFailed<ArgumentException>().AssertEquals(ex);
     Tasks.Faulted<int>(ex).AssertFailed<ArgumentException>().AssertEquals(ex);
     
     Tasks.Faulted(new[] { ex, ex }).AssertFailed<AggregateException>().InnerExceptions.AssertSequenceEquals(new[] { ex, ex });
     Tasks.Faulted<int>(new[] { ex, ex }).AssertFailed<AggregateException>().InnerExceptions.AssertSequenceEquals(new[] { ex, ex });
 }
开发者ID:NotYours180,项目名称:Twisted-Oak-Threading-Utilities,代码行数:15,代码来源:TasksTest.cs


示例19: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Using ctor2 to test the message property");

        try
        {
            string randValue = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            string paramName = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
            ArgumentException argumentException = new ArgumentException(randValue, paramName);

            string expectedWindows = randValue + "\r\nParameter name: " + paramName;
            string expectedMac = randValue + "\nParameter name: " + paramName;

            if ((argumentException.Message != randValue))
            {
                if (!Utilities.IsWindows)
                {
                    if (argumentException.Message != expectedMac)
                    {
                        TestLibrary.TestFramework.LogError("003", "The result is not the value as expected");
                        TestLibrary.TestFramework.LogInformation("Expected: " + expectedMac + "; Actual: " + argumentException.Message);
                        retVal = false;
                    }
                }
                else if (argumentException.Message != expectedWindows)
                {
                    TestLibrary.TestFramework.LogError("004", "The result is not the value as expected");
                    TestLibrary.TestFramework.LogInformation("Expected: " + expectedWindows + "; Actual: " + argumentException.Message);
                    retVal = false;
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:rdterner,项目名称:coreclr,代码行数:42,代码来源:argumentexceptionmessage.cs


示例20: PosTest1

 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1:Initialize the InvalidCastException instance with message and InnerException 1");
     try
     {
         string message = "HelloWorld";
         ArgumentException innerException = new ArgumentException();
         InvalidCastException myException = new InvalidCastException(message, innerException);
         if (myException == null || myException.Message != message || !myException.InnerException.Equals(innerException))
         {
             TestLibrary.TestFramework.LogError("001", "the InvalidCastException with message and innerException instance creating failed");
             retVal = false;
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
开发者ID:l1183479157,项目名称:coreclr,代码行数:22,代码来源:invalidcastexceptionctor3.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ArgumentList类代码示例发布时间:2022-05-24
下一篇:
C# Argument1类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap