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."); }
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)); }
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"); }
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)); }
public static void Test2() { var e1 = new NullReferenceException(); var e2 = new NullReferenceException("бла бла", e1); var e3 = new Exception("Ураааа", e2); throw e3; }
public void AgainstNull_WithValidLambdaExpression_DoesNotThrow() { NullReferenceException ex = new NullReferenceException(); // valid cast, does not evaluate to null Assert.DoesNotThrow(() => Guard.AgainstNull(() => ex as Exception)); }
public void Throw_Test() { var exception = new NullReferenceException(); var expected = Observable.Throw<string>(exception); var actual = FactoryMethods.Throw<string>(exception); ReactiveAssert.AreElementsEqual(expected, actual); }
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; }
public void ResponseIsNullForNonWebExceptions() { NullReferenceException exception = new NullReferenceException("The thing is null"); _builder.SetExceptionDetails(exception); RaygunMessage message = _builder.Build(); Assert.IsNull(message.Details.Response); }
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"); }
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"); }
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; }
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; }
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); }
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(); }
public void LogException_SHOULD_log_with_severity_Error() { var dummyException = new NullReferenceException(); var fakeWriter = new Mock<ILogWriter>(); var sut = new Logger(fakeWriter.Object); sut.LogException(dummyException); fakeWriter.Verify(m => m.Write(Match.Create<LogEntry>(e => e.Severity == Severity.Error))); }
public void ReturnTrueGivenExceptionIsOfType() { // Arrange var exception = new NullReferenceException(); // Act var isOfType = exception.IsOrContainsExceptionOfType<NullReferenceException>(); // Assert Assert.IsTrue(isOfType); }
public void ReturnNullGivenExceptionIsNotOfType() { // Arrange var exception = new NullReferenceException(); // Act var returnedException = exception.GetFirstExceptionOfType<NotImplementedException>(); // Assert Assert.IsTrue(returnedException == null); }
protected override void Given() { base.Given(); _config = new CircuitBreakerConfig { ExpectedExceptionListType = ExceptionListType.BlackList }; _config.ExpectedExceptionList.Add(typeof(ArgumentNullException)); _circuitBreaker = new CircuitBreaker(_config); _thrownException = new NullReferenceException(); }
public System_exception () { // 1. System exception is thrown by .Net // 2. determine System.SystemException // True! NullReferenceException is-a SystemException. NullReferenceException nullRefEx = new NullReferenceException(); Console.WriteLine(" NullReferenceException is-a SystemException? : {0}", nullRefEx is SystemException); // if ancestor, then true, or false }
public void ReturnFalseGivenExceptionIsNotOfType() { // Arrange var exception = new NullReferenceException(); // Act var isOfType = exception.IsOrContainsExceptionOfType<NotImplementedException>(); // Assert Assert.IsFalse(isOfType); }
public void TypePropertiesAreCorrect() { Assert.AreEqual(typeof(NullReferenceException).FullName, "ss.NullReferenceException", "Name"); Assert.IsTrue(typeof(NullReferenceException).IsClass, "IsClass"); Assert.AreEqual(typeof(NullReferenceException).BaseType, typeof(Exception), "BaseType"); object d = new NullReferenceException(); Assert.IsTrue(d is NullReferenceException, "is NullReferenceException"); Assert.IsTrue(d is Exception, "is Exception"); var interfaces = typeof(NullReferenceException).GetInterfaces(); Assert.AreEqual(interfaces.Length, 0, "Interfaces length"); }
/// <summary> /// Capture this exception as log4net FAIL (not ERROR) when logged /// </summary> public static void LogAsFail(ref System.NullReferenceException ex) { if (ex.Data.Contains(LogAs)) { ex.Data[LogAs] = OGCSexception.LogLevel.FAIL; } else { ex.Data.Add(LogAs, OGCSexception.LogLevel.FAIL); } }
public void ReturnTrueGivenExceptionContainsType() { // Arrange var innerException = new NotImplementedException(); var exception = new NullReferenceException("Test", innerException); // Act var isOfType = exception.IsOrContainsExceptionOfType<NotImplementedException>(); // Assert Assert.IsTrue(isOfType); }
protected override void Given() { base.Given(); _config = new CircuitBreakerConfig { ExpectedExceptionListType = ExceptionListType.BlackList, PermittedExceptionPassThrough = PermittedExceptionBehaviour.Swallow }; _config.ExpectedExceptionList.Add(typeof(ArgumentNullException)); _circuitBreaker = new CircuitBreaker(_config); _thrownException = new NullReferenceException(); }
public void ReturnNullGivenExceptionDoesNotContainType() { // Arrange var innerException = new NullReferenceException(); var exception = new NullReferenceException("Test", innerException); // Act var returnedException = exception.GetFirstExceptionOfType<FileNotFoundException>(); // Assert Assert.IsTrue(returnedException == null); }
public void IncludeExceptionDataInLoggedRow() { var exception = new NullReferenceException(); var errorId = Guid.NewGuid(); exception.Data["id"] = errorId; exception.Data["name"] = "ahmed"; _logger.Log(LogLevel.Error, "exception message", (Exception)exception); var entities = GetLogEntities(); var entity = entities.Single(); Assert.True(entity.ExceptionData.Contains(errorId.ToString())); Assert.True(entity.ExceptionData.Contains("name=ahmed")); }
public void CheckThatExcludedExceptionsAreIgnored() { var exception = new NullReferenceException(); var circuit = new Circuit<string>(1) { ExcludedExceptions = new[] { typeof(NullReferenceException) } }; var circuit1 = circuit; Action execution = () => circuit1.Execute(() => { throw exception; }); execution.ShouldThrow<NullReferenceException>().Where(e => e == exception); circuit.State.Position.Should().Be(CircuitPosition.Closed); }
public virtual void TestSmartsheetExceptionException() { System.NullReferenceException expected = new System.NullReferenceException(); try { throw new SmartsheetException(expected); } catch (Exception ex) { Assert.AreEqual(typeof(SmartsheetException), ex.GetType()); Assert.That(ex.InnerException, Is.InstanceOf <NullReferenceException>()); } }
public void m_Enable_RequestNull_Default() { QApi api = AppTesting.APIlogin( 2 ); var nex = new NullReferenceException(); try { IQuatrixRequest req = null; bool enable = req.Enable(); } catch (Exception ex) { Assert.AreEqual( ex.Message, nex.Message ); } }
/// <summary> /// Gets the <see cref="BraintreeProviderSettings"/>. /// </summary> /// <returns> /// The <see cref="BraintreeProviderSettings"/>. /// </returns> /// <remarks> /// This is only used by <see cref="BraintreeWebhooksControllerBase"/> /// </remarks> internal static BraintreeProviderSettings GetBraintreeProviderSettings() { var provider = (BraintreePaymentGatewayProvider)MerchelloContext.Current.Gateways.Payment.GetProviderByKey(Constants.Braintree.GatewayProviderSettingsKey); if (provider != null) return provider.ExtendedData.GetBrainTreeProviderSettings(); var logData = MultiLogger.GetBaseLoggingData(); logData.AddCategory("GatewayProviders"); logData.AddCategory("Braintree"); var ex = new NullReferenceException("The BraintreePaymentGatewayProvider could not be resolved. The provider must be activiated"); MultiLogHelper.Error<BraintreeApiController>("BraintreePaymentGatewayProvider not activated.", ex, logData); throw ex; }
public void Creation() { Exception raisedException = null; ReportStatus status = ReportStatus.Create(raisedException); AssertEx.That(status is ReportStatus.Success, Is.True()); raisedException = new AssertException("Assert Exception"); status = ReportStatus.Create(raisedException); AssertEx.That(status is ReportStatus.Failed, Is.True()); raisedException = new NullReferenceException("Other Exception"); status = ReportStatus.Create(raisedException); AssertEx.That(status is ReportStatus.Error, Is.True()); }
public Void execute(CommandContext commandContext) { JobManager jobManager = commandContext.JobManager; outerInstance.timerEntity = new TimerEntity(); outerInstance.timerEntity.LockOwner = System.Guid.randomUUID().ToString(); outerInstance.timerEntity.Duedate = DateTime.Now; outerInstance.timerEntity.Retries = 0; StringWriter stringWriter = new StringWriter(); System.NullReferenceException exception = new System.NullReferenceException(); exception.printStackTrace(new PrintWriter(stringWriter)); outerInstance.timerEntity.ExceptionStacktrace = stringWriter.ToString(); jobManager.insert(outerInstance.timerEntity); assertNotNull(outerInstance.timerEntity.Id); return(null); }
private void UpdateAccount_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (tbUserID.Text == "" || tbPassword.Text == "" || tbConfirmPassword.Text == "") { MessageBox.Show("Please fill in all the required fields !", "Required Fields", MessageBoxButtons.OK, MessageBoxIcon.Error); ReqID.Visible = true; ReqPassword.Visible = true; ReqConPassword.Visible = true; } else if (tbPassword.Text != tbConfirmPassword.Text) { MessageBox.Show("Oops ! The passwords you have entered did not match"); } else { foreach (DataGridViewRow row in dataGridView1.Rows) { // string testUsername = row.Cells[0].Value.ToString(); // string testPassword = row.Cells[6].Value.ToString(); try { if (tbUserID.Text == row.Cells[0].Value.ToString()) { if (row.Cells[6].Value.ToString().Contains(tbPassword.Text)) { SetValueForUserID = tbUserID.Text; DialogResult result = MessageBox.Show("Your account details are currently saved as the following :", "Success ! Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result == DialogResult.OK) { EditAccount edit = new EditAccount(); edit.Show(); refreshPage(); break; } else { this.Close(); } } else { DialogResult result4 = MessageBox.Show("Please enter a Valid Account to edit or refer to the forgot ID or forgot Password link", "Unsuccesfull, Access Denied", MessageBoxButtons.RetryCancel); if (result4 == DialogResult.Retry) { tbUserID.Focus(); break; } if (result4 == DialogResult.Cancel) { refreshPage(); } } } else { DialogResult result2 = MessageBox.Show("The System ID or Password you have entered does not exist", "Unsuccesfull Login", MessageBoxButtons.OK); if (result2 == DialogResult.OK) { break; } } } catch (System.NullReferenceException) { System.NullReferenceException nullex = new System.NullReferenceException("Account not found"); throw nullex; } } } }