當前位置: 首頁>>代碼示例>>C#>>正文


C# System.NullReferenceException類代碼示例

本文整理匯總了C#中System.NullReferenceException的典型用法代碼示例。如果您正苦於以下問題:C# NullReferenceException類的具體用法?C# NullReferenceException怎麽用?C# NullReferenceException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NullReferenceException類屬於System命名空間,在下文中一共展示了NullReferenceException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConstructorWithMessageWorks

 public void ConstructorWithMessageWorks()
 {
     var ex = new NullReferenceException("The message");
     Assert.True((object)ex is NullReferenceException, "is NullReferenceException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "The message");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:NullReferenceExceptionTests.cs

示例2: TypePropertiesAreCorrect

 public void TypePropertiesAreCorrect()
 {
     Assert.AreEqual(typeof(NullReferenceException).GetClassName(), "Bridge.NullReferenceException", "Name");
     object d = new NullReferenceException();
     Assert.True(d is NullReferenceException, "is NullReferenceException");
     Assert.True(d is Exception, "is Exception");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:NullReferenceExceptionTests.cs

示例3: DefaultConstructorWorks

 public void DefaultConstructorWorks()
 {
     var ex = new NullReferenceException();
     Assert.True((object)ex is NullReferenceException, "is NullReferenceException");
     Assert.AreEqual(ex.InnerException, null, "InnerException");
     Assert.AreEqual(ex.Message, "Object is null.");
 }
開發者ID:TinkerWorX,項目名稱:Bridge,代碼行數:7,代碼來源:NullReferenceExceptionTests.cs

示例4: Given

 protected override void Given()
 {
     base.Given();
     _caughtExceptions = new List<Exception>();
     _config = new CircuitBreakerConfig {ExpectedExceptionListType = ExceptionListType.BlackList};
     _config.ExpectedExceptionList.Add(typeof(ArgumentNullException));
     _circuitBreaker = new CircuitBreaker(_config);
     _circuitBreaker.ToleratedOpenCircuitBreaker += (sender, args) => _toleratedOpenEventFired = true;
     _thrownException = new NullReferenceException();
 }
開發者ID:RokitSalad,項目名稱:Helpful.CircuitBreaker,代碼行數:10,代碼來源:when_receiving_exceptions_not_in_the_blacklist_within_tolerance.cs

示例5: RunTestsOfJUUTTestClassWithFailingClassSetUp

        public void RunTestsOfJUUTTestClassWithFailingClassSetUp()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMockWithFailingClassSetUp));
            session.Add(typeof(TestClassMockWithFailingClassSetUp).GetMethod("Bar"));

            //Testing the run of a specific testMethod
            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test report
            Report report = GetFirstMethodReportFrom(classReport.MethodReports);
            Exception raisedException = new NullReferenceException("Failing class set up.");
            Report expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(report, Is.EqualTo(expectedReport));

            //Testing the run of all tests
            MethodCallOrder = new List<string>();
            session.AddAll();
            classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test reports
            ICollection<MethodReport> reports = classReport.MethodReports;
            raisedException = new NullReferenceException("Failing class set up.");
            expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(reports.Count, Is.EqualTo(1));
            AssertEx.That(GetFirstMethodReportFrom(reports), Is.EqualTo(expectedReport));
        }
開發者ID:LennartH,項目名稱:JUUT,代碼行數:29,代碼來源:TestSimpleTestClassRunner.cs

示例6: Test2

 public static void Test2()
 {
     var e1 = new NullReferenceException();
     var e2 = new NullReferenceException("бла бла", e1);
     var e3 = new Exception("Ураааа", e2);
     throw e3;
 }
開發者ID:arbium,項目名稱:democratia2,代碼行數:7,代碼來源:Form1.cs

示例7: AgainstNull_WithValidLambdaExpression_DoesNotThrow

        public void AgainstNull_WithValidLambdaExpression_DoesNotThrow()
        {
            NullReferenceException ex = new NullReferenceException();

            // valid cast, does not evaluate to null
            Assert.DoesNotThrow(() => Guard.AgainstNull(() => ex as Exception));
        }
開發者ID:hermanpotgieter,項目名稱:Code.Pizza,代碼行數:7,代碼來源:GuardTests.cs

示例8: Throw_Test

 public void Throw_Test()
 {
     var exception = new NullReferenceException();
     var expected = Observable.Throw<string>(exception);
     var actual = FactoryMethods.Throw<string>(exception);
     ReactiveAssert.AreElementsEqual(expected, actual);
 }
開發者ID:GavinOsborn,項目名稱:Rx,代碼行數:7,代碼來源:FactoryMethodsTest.cs

示例9: Create

        public Models.Repository Create(string RepositoryName, string Description, string HomePage, bool Public)
        {
            LogProvider.LogMessage(string.Format("Repository.Create - RepositoryName : '{0}' , Description : '{1}' , HomePage : '{2}', Public : '{3}'",
                RepositoryName,
                Description,
                HomePage,
                Public));

            Authenticate();

            var url = "repos/create";

            var formValues = new NameValueCollection();
            if (string.IsNullOrEmpty(RepositoryName))
            {
                var error = new NullReferenceException("RepositoryName was null or empty");
                if (LogProvider.HandleAndReturnIfToThrowError(error))
                    throw error;
                return null;
            }
            formValues.Add("name", RepositoryName);

            if (!string.IsNullOrEmpty(Description))
                formValues.Add("description", Description);
            if (!string.IsNullOrEmpty(HomePage))
                formValues.Add("homepage", HomePage);

            formValues.Add("public", (Public ? 1 : 0).ToString());

            var result = ConsumeJsonUrlAndPostData<Models.Internal.RepositoryContainer<Models.Repository>>(url, formValues);

            return result == null ? null : result.Repository;
        }
開發者ID:rumpl,項目名稱:GithubSharp,代碼行數:33,代碼來源:Repository.cs

示例10: ResponseIsNullForNonWebExceptions

 public void ResponseIsNullForNonWebExceptions()
 {
   NullReferenceException exception = new NullReferenceException("The thing is null");
   _builder.SetExceptionDetails(exception);
   RaygunMessage message = _builder.Build();
   Assert.IsNull(message.Details.Response);
 }
開發者ID:ArturDorochowicz,項目名稱:raygun4net,代碼行數:7,代碼來源:RaygunMessageBuilderTests.cs

示例11: ShouldWrite

        public void ShouldWrite()
        {
            var inner1Ex = new NullReferenceException("inner1Message");
            var inner2Ex = new InvalidOperationException("inner2Message", inner1Ex);
            var outerEx = new Exception("outerMessage", inner2Ex);

            var expectedOutput = @"----------
            outerMessage
            ----------
            Debug information:
            ----------
            Exception: outerMessage
            [StackTrace:Exception]
            ----------
            inner InvalidOperationException: inner2Message
            [StackTrace:InvalidOperationException]
            ----------
            inner NullReferenceException: inner1Message
            [StackTrace:NullReferenceException]
            ----------
            ";

            Func<Exception, string> stackTraceFormatter = ex => string.Format("[StackTrace:{0}]", ex.GetType().Name);

            var actual = outerEx.ToLogString(stackTraceFormatter);

            Assert.That(expectedOutput, Is.EqualTo(actual));
        }
開發者ID:endjin,項目名稱:DeployToAzure,代碼行數:28,代碼來源:ExceptionExtensionsTests.cs

示例12: ConstructorWithMessageAndInnerExceptionWorks

		public void ConstructorWithMessageAndInnerExceptionWorks() {
			var inner = new Exception("a");
			var ex = new NullReferenceException("The message", inner);
			Assert.IsTrue((object)ex is NullReferenceException, "is NullReferenceException");
			Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
			Assert.AreEqual(ex.Message, "The message");
		}
開發者ID:ShuntaoChen,項目名稱:SaltarelleCompiler,代碼行數:7,代碼來源:NullReferenceExceptionTests.cs

示例13: SuccessPayment

        public HttpResponseMessage SuccessPayment(Guid invoiceKey, Guid paymentKey, string token, string payerId)
        {
            var invoice = _merchelloContext.Services.InvoiceService.GetByKey(invoiceKey);
            var payment = _merchelloContext.Services.PaymentService.GetByKey(paymentKey);
            if (invoice == null || payment == null || String.IsNullOrEmpty(token) || String.IsNullOrEmpty(payerId))
            {
                var ex = new NullReferenceException(string.Format("Invalid argument exception. Arguments: invoiceKey={0}, paymentKey={1}, token={2}, payerId={3}.", invoiceKey, paymentKey, token, payerId));
                LogHelper.Error<PayPalApiController>("Payment is not authorized.", ex);
                throw ex;
            }

	        var providerKeyGuid = new Guid(Constants.PayPalPaymentGatewayProviderKey);
			var paymentGatewayMethod = _merchelloContext.Gateways.Payment
				.GetPaymentGatewayMethods()
				.First(item => item.PaymentMethod.ProviderKey == providerKeyGuid);
	        //var paymentGatewayMethod = _merchelloContext.Gateways.Payment.GetPaymentGatewayMethodByKey(providerKeyGuid);

            // Authorize
            var authorizeResult = _processor.AuthorizePayment(invoice, payment, token, payerId);
	        /*
			var authorizePaymentProcArgs = new ProcessorArgumentCollection();

	        authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalTokenKey] = token;
			authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalPayerIDKey] = payerId;
			authorizePaymentProcArgs[Constants.ProcessorArgumentsKeys.internalPaymentKeyKey] = payment.Key.ToString();

	        var authorizeResult = paymentGatewayMethod.AuthorizeCapturePayment(invoice, payment.Amount, authorizePaymentProcArgs);
            */
            _merchelloContext.Services.GatewayProviderService.Save(payment);
            if (!authorizeResult.Payment.Success)
            {
                LogHelper.Error<PayPalApiController>("Payment is not authorized.", authorizeResult.Payment.Exception);
				_merchelloContext.Services.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, "PayPal: request capture authorization error: " + authorizeResult.Payment.Exception.Message, 0);
                return ShowError(authorizeResult.Payment.Exception.Message);
            }
			_merchelloContext.Services.GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, "PayPal: capture authorized", 0);

			// The basket can be empty
            var customerContext = new Merchello.Web.CustomerContext(this.UmbracoContext);
            var currentCustomer = customerContext.CurrentCustomer;
	        if (currentCustomer != null) {
				var basket = Merchello.Web.Workflow.Basket.GetBasket(currentCustomer);
				basket.Empty();
	        }

            // Capture
            var captureResult = paymentGatewayMethod.CapturePayment(invoice, payment, payment.Amount, null);
            if (!captureResult.Payment.Success)
            {
                LogHelper.Error<PayPalApiController>("Payment is not captured.", captureResult.Payment.Exception);
                return ShowError(captureResult.Payment.Exception.Message);
            }

            // redirect to Site
			var returnUrl = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.ReturnUrl);
            var response = Request.CreateResponse(HttpStatusCode.Moved);
            response.Headers.Location = new Uri(returnUrl.Replace("%INVOICE%", invoice.Key.ToString().EncryptWithMachineKey()));
            return response;
        }
開發者ID:drpeck,項目名稱:Merchello,代碼行數:59,代碼來源:PayPalApiController.cs

示例14: ErrorPage

 public ErrorPage(Server server, Request request, Exception e) {
     if (e == null)
         e = new NullReferenceException("Error page passed a null exception");
     this.exception = e;
     this.httpException = (e is HttpException) ? (HttpException)e : new HttpException(e);
     this.server = server;
     this.request = request;
 }
開發者ID:kevtham,項目名稱:twin,代碼行數:8,代碼來源:ErrorPage.cs

示例15: NullReferenceException_Ctor_String_Exception

        public static void NullReferenceException_Ctor_String_Exception()
        {
            Exception ex = new Exception(innerExceptionMessage);
            NullReferenceException i = new NullReferenceException(exceptionMessage, ex);

            Assert.Equal(exceptionMessage, i.Message);
            Assert.Equal(i.InnerException.Message, innerExceptionMessage);
            Assert.Equal(i.InnerException.HResult, ex.HResult);
            Assert.Equal(E_POINTER, (uint)i.HResult);
        }
開發者ID:ChuangYang,項目名稱:corefx,代碼行數:10,代碼來源:ExceptionTests.cs


注:本文中的System.NullReferenceException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。