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


C# ArgumentException类代码示例

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


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


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