// Handle sign-in errors differently than generic errors. private Task RemoteFailure(FailureContext context) { context.HandleResponse(); context.Response.Redirect("/"); //context.Response.Redirect("/Home/Error?message=" + context.Failure.Message); return Task.FromResult(0); }
public override Task RemoteFailure(FailureContext context) { context.HandleResponse(); context.Response.Redirect("/Home/AuthenticationFailed"); return(Task.FromResult(0)); }
public void ShouldReactToThirdFailure() { var normalPeriod = TimeSpan.FromMilliseconds(50); var maxPeriod = TimeSpan.FromSeconds(2); var exception1 = new InvalidOperationException("Boom"); var exception2 = new InvalidCastException("Boom2"); var exception3 = new IndexOutOfRangeException("Boom3"); var failContext = new FailureContext(normalPeriod, maxPeriod, () => DateTime.Now); failContext.SetException(exception1); var timeOfFirstFailure = failContext.FirstFailureDateTime; failContext.SetException(exception2); // call failContext.SetException(exception3); // assert failContext.FirstFailureDateTime.Should().Be(timeOfFirstFailure); failContext.Period.Should().Be(normalPeriod); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(200)); failContext.MaxPeriod.Should().Be(maxPeriod); failContext.FailCount.Should().Be(3); failContext.Exception.Should().Be(exception3); }
// Handle sign-in errors differently than generic errors. private Task OnAuthenticationFailed(FailureContext context) { context.HandleResponse(); context.Response.Redirect("/Home/Error?message=" + context.Failure.Message); return(Task.FromResult(0)); }
public void ShouldRecoverToNormalPeriodAfterReset() { var normalPeriod = TimeSpan.FromMilliseconds(50); var maxPeriod = TimeSpan.FromSeconds(1); var exception = new InvalidOperationException("Boom"); var failContext = new FailureContext(normalPeriod, maxPeriod, () => DateTime.Now); failContext.SetException(exception); failContext.SetException(exception); failContext.SetException(exception); failContext.SetException(exception); failContext.SetException(exception); failContext.SetException(exception); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(1000)); failContext.Reset(); failContext.Period.Should().Be(normalPeriod); failContext.CurrentPeriod.Should().Be(normalPeriod); failContext.MaxPeriod.Should().Be(maxPeriod); failContext.FailCount.Should().Be(0); failContext.Exception.Should().BeNull(); }
public void ShouldNotExceedMaxBackoffPeriodAfterSeveralFailures() { var normalPeriod = TimeSpan.FromMilliseconds(50); var maxPeriod = TimeSpan.FromSeconds(1); var exception = new InvalidOperationException("Boom"); var failContext = new FailureContext(normalPeriod, maxPeriod, () => DateTime.Now); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(50)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(100)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(200)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(400)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(800)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(1000)); failContext.SetException(exception); failContext.CurrentPeriod.Should().Be(TimeSpan.FromMilliseconds(1000)); }
private Task OtherFailure(FailureContext context) { var encoder = System.Text.Encodings.Web.HtmlEncoder.Default; context.Response.Redirect("/Home/Error?message=" + encoder.Encode(context.Failure.Message)); return(Task.FromResult(0)); }
/// <summary> /// Get test name and line number where error occurred. /// </summary> private static void SetReflectedTestData() { StackTrace st = new StackTrace(true); List <StackFrame> stf = st.GetFrames().ToList(); if (_failureContext == FailureContext.Default) { List <string> reflectedTypes = new List <string>(); for (int s = 0; s < stf.Count; s++) { if (stf[s].GetMethod().ReflectedType != null) { reflectedTypes.Add(stf[s].GetMethod().ReflectedType.Name.ToLower()); } } if (reflectedTypes.FindAll(x => x.Contains("<setupclass>")).Any()) { _failureContext = FailureContext.SetUpClass; } else if (reflectedTypes.FindAll(x => x.Contains("<setup>")).Any()) { _failureContext = FailureContext.SetUp; } else if (reflectedTypes.FindAll(x => x.Contains("<teardownclass>")).Any()) { _failureContext = FailureContext.TearDownClass; } else if (reflectedTypes.FindAll(x => x.Contains("<teardown>")).Any()) { _failureContext = FailureContext.TearDown; } else { _failureContext = FailureContext.TestMethod; } } for (int i = 0; i < stf.Count; i++) { string filename = stf[i].GetFileName(); if (!string.IsNullOrEmpty(filename)) { string[] fragments = filename.Split('/'); className = fragments[fragments.Length - 1].Replace(".cs", string.Empty); Type thisType = Type.GetType(string.Format("TrilleonAutomation.{0}", className)); if (thisType != null && thisType.GetCustomAttributes(typeof(AutomationClass), false).Length > 0) { lineCall = stf[i].ToString(); lineNumber = stf[i].GetFileLineNumber().ToString(); return; } } } }
public void ShouldHaveDefaultValuesAfterCreation() { var normalPeriod = TimeSpan.FromMilliseconds(50); var maxPeriod = TimeSpan.FromSeconds(2); var failContext = new FailureContext(normalPeriod, maxPeriod, () => DateTime.Now); failContext.Period.Should().Be(normalPeriod); failContext.CurrentPeriod.Should().Be(normalPeriod); failContext.MaxPeriod.Should().Be(maxPeriod); failContext.FailCount.Should().Be(0); failContext.Exception.Should().BeNull(); }
private Task RemoteFailure(FailureContext context) { context.HandleResponse(); if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied")) { context.Response.Redirect("/"); } else { context.Response.Redirect("/Home/Error?message=" + context.Failure.Message); } return(Task.FromResult(0)); }
// Used for avoiding yellow-screen-of-death // FAP : See http://stackoverflow.com/questions/41224543/how-to-get-azure-aad-b2c-forgot-password-link-to-work/41772017 // for discussion around handling of password reset - code below modified per this link but changed because ASP.Net Core // AD B2C integration is different than ASP.Net 4.X private Task RemoteFailure(FailureContext context) { Task result = Task.FromResult(0); _logger.LogDebug("RemoteFailure!"); context.HandleResponse(); if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("AADB2C90118")) { // If the user clicked the reset password link, redirect to the reset password route _logger.LogDebug("User clicked reset password link, redirect to ResetPassword route!"); if (OnResetPasswordRequested != null) { result = OnResetPasswordRequested(context); } else { context.Response.Redirect("/Account/ResetPassword"); } } else if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied")) { // If the user canceled the sign in, redirect back to the home page _logger.LogDebug("User canceled out of sign in or was denied access, redirect to Home"); if (OnResetPasswordRequested != null) { result = OnCanceledSignIn(context); } else { context.Response.Redirect("/Home/Index"); } } else { _logger.LogDebug("Not sure why we got here - show error page with message: {0}", context.Failure.Message); if (OnOtherFailure != null) { result = OnCanceledSignIn(context); } else { context.Response.Redirect("/Home/Error?message=" + context.Failure.Message); } } return(result); }
private async Task <bool> TryExecuteFailedRecoveryAction(MessageBrokerContext messageContext, string failureDescription, Exception exception, int deliveryCount, TransactionContext transactionContext) { try { var failureContext = new FailureContext(messageContext.BrokeredMessage, this.ErrorQueueName, failureDescription, exception, deliveryCount, transactionContext); return(await _recoveryStrategy.ExecuteAsync(async() => { await _failedRecoveryAction.ExecuteAsync(failureContext); return true; }, messageContext.CancellationToken)); } catch (Exception e) { _logger.LogError(e, "Unable to execute recovery action"); return(false); } }
public void ShouldReactToFirstFailure() { var normalPeriod = TimeSpan.FromMilliseconds(50); var maxPeriod = TimeSpan.FromSeconds(2); var exception = new InvalidOperationException("Boom"); var failContext = new FailureContext(normalPeriod, maxPeriod, () => DateTime.Now); failContext.SetException(exception); failContext.Period.Should().Be(normalPeriod); failContext.CurrentPeriod.Should().Be(normalPeriod); failContext.MaxPeriod.Should().Be(maxPeriod); failContext.FailCount.Should().Be(1); failContext.Exception.Should().Be(exception); }
public async Task Notify(FailureContext failureContext) { _logger.LogDebug($"Dispatching '{nameof(CriticalFailureEvent)}'."); using var scope = _scopeFactory.CreateScope(); var dispatcher = scope.ServiceProvider.GetService <IMessageDispatcher>(); if (dispatcher != null) { await dispatcher.Dispatch(new CriticalFailureEvent() { Context = failureContext }).ConfigureAwait(false); _logger.LogDebug($"Dispatched '{nameof(CriticalFailureEvent)}'."); } else { _logger.LogDebug($"{nameof(CriticalFailureEvent)} not dispatched. No {nameof(IMessageDispatcher)} registered."); } }
public Task OnRemoteFailure(FailureContext context) { context.HandleResponse(); // Handle the error code that Azure AD B2C throws when trying to reset a password from the login page // because password reset is not supported by a "sign-up or sign-in policy" if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("AADB2C90118")) { // If the user clicked the reset password link, redirect to the reset password route context.Response.Redirect("/Account/ResetPassword"); } else if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied")) { context.Response.Redirect("/"); } else { context.Response.Redirect("/Home/Error"); } return(Task.FromResult(0)); }
public Task RemoteFailure(FailureContext context) { _logger.LogError("Remote Failure", context.Failure); return(Task.FromResult(0)); }
private async Task OnAuthenticationFailed(FailureContext arg) { //Error from OpenID framework! }
public void AddFailure(FailureContext context) { Interlocked.Increment(ref _failedUriCount); _failedUris.Add(context.Uri.ToString()); }
public IEnumerator IsDirty(Component originalState, object currentState, string message, bool expectDirty = false, FailureContext failureContext = FailureContext.Default, params int[] testRailsIds) { throw new UnityException("Not implemented!"); }
private Task B2CResetPasswordRequested(FailureContext context) { context.Response.Redirect("/Account/ResetPassword"); return(Task.FromResult(0)); }
/// <summary> /// Calculates the exponential delay that will occur between operations based on the number of previous attempts /// </summary> /// <returns>The time in seconds to delay. Truncated to the nearest second.</returns> /// <remarks> /// Exponential delay per attempt: ///<br>Attempt #1 - 0s</br> ///<br>Attempt #2 - 2s</br> ///<br>Attempt #3 - 4s</br> ///<br>Attempt #4 - 8s</br> ///<br>Attempt #5 - 16s</br> ///<br>Attempt #6 - 32s</br> ///<br>Attempt #7 - 1m 4s</br> ///<br>Attempt #8 - 2m 8s</br> ///<br>Attempt #9 - 4m 16s</br> ///<br>Attempt #10 - 8m 32s</br> ///<br>Attempt #11 - 17m 4s</br> ///<br>Attempt #12 - 34m 8s</br> ///<br>Attempt #13 - 1h 8m 16s</br> ///<br>Attempt #14 - 2h 16m 32s</br> ///<br>Attempt #15 - 4h 33m 4s</br> /// </remarks> public Task ExecuteAsync(FailureContext failureContext) { _ = failureContext ?? throw new ArgumentNullException(nameof(failureContext)); return(ExecuteAsync(failureContext.DeliveryCount)); }
public Task ExecuteAsync(FailureContext failureContext) => Task.CompletedTask;
//Handles remote login failure typically where user doesn't give consent private static Task HandleRemoteLoginFailure(FailureContext ctx) { ctx.Response.Redirect("/Account/Login"); ctx.HandleResponse(); return(Task.FromResult(0)); }
public IEnumerator Fail(string message, FailureContext failureContext = FailureContext.Default, params int[] testRailsIds) { yield return(StartCoroutine(Unifier(false, false, message, FailureContext.Default, testRailsIds))); }
protected IEnumerator Unifier(bool b, bool inverse, string message, FailureContext newFailureContext, params int[] testRailsId) { //If test was already marked as a failure, and test has flag indicating that it should continue despite failure, ignore. if (!AutomationMaster.CurrentTestContext.IsSuccess || ((AutomationMaster.TryContinueOnFailure || MideExecution_MarkTestToTryContinueAfterFail) && IsFailing)) { UnitTestStepFailure = isSoft = isTry = quiet = false; //Reset the UnitTestStepFailure, Soft, Try, and Quiet flags. yield break; } //Automatically label this assertion as quiet if the previous assertion is identical to this one. quiet = quiet ? true : AutomationMaster.CurrentTestContext.Assertions.Last() == message; _failureContext = newFailureContext; if ((!b && inverse) || (b && !inverse)) { if (isTry && !quiet) { AutomationMaster.CurrentTestContext.AddAssertion(string.Format("**TRY_SUCCESS**{0}", message)); UnitTestStepFailure = isSoft = isTry = quiet = false; //Reset the UnitTestStepFailure, Soft, Try, and Quiet flags. yield break; } ConcurrentFailures = 0; AutomationMaster.CurrentTestContext.IsSuccess = true; if (!string.IsNullOrEmpty(message) && !isTry && !quiet) { AutomationMaster.CurrentTestContext.AddAssertion(message); } } else { //TODO: UnitTestStepFailure - Determine if an assertion has failed within the context of a TestObject "steps" method. If so, set this to true. Used to disabled certain TestRunner reactive logic, such as screenshots. if (isTry) { if (!quiet) { AutomationMaster.CurrentTestContext.AddAssertion(string.Format("**TRY_FAIL**{0}", message)); } UnitTestStepFailure = isSoft = isTry = quiet = false; //Reset the UnitTestStepFailure, Soft, Try, and Quiet flags. yield break; } IsFailing = true; bool recordLogDetails = newFailureContext != FailureContext.Skipped; SetReflectedTestData(); string recentLogs = AutomationReport.EncodeCharactersForJson(AutoConsole.ReturnLatestLogs(5)); if (newFailureContext == FailureContext.Skipped) { AutomationMaster.TestRunContext.Skipped.Add(AutomationMaster.CurrentTestContext.TestName); } else { AutomationMaster.TestRunContext.Failed.Add(AutomationMaster.CurrentTestContext.TestName, new string[] { message, recentLogs.ToString(), lineNumber }); } AutomationMaster.CurrentTestContext.IsSuccess = false; AutomationMaster.CurrentTestContext.AddAssertion(message); AutomationMaster.CurrentTestContext.ErrorDetails += string.Format("Error Message [{0}] : Test Line [{1}] : Debug Logs [{2}] ", message, string.Format("Line [{0}] Call [{1}]", lineNumber, lineCall), (recordLogDetails ? recentLogs : string.Format("#SKIPPED#{0}", message))); AutomationMaster.CurrentTestContext.ErrorDetails += string.Format(" FULL STACK: [{0}]", Environment.StackTrace.Replace(" at", string.Format(" {0} at", AutomationMaster.NEW_LINE_INDICATOR))); if (failureContext != FailureContext.Skipped) { //Take screenshot if a failure is not a "Skip" failure (In which case a test does not run at all, and there is no value in taking a screenshot as the current screen has no relevance to the reason it failed). yield return(StartCoroutine(AutomationMaster.StaticSelfComponent.TakeScreenshot())); screenshotRequestTime = DateTime.UtcNow; } //Handle errors occurring outside of the context of the current test's execution. Only certain contexts require additional handling over what is offered by default. switch (AutomationMaster.ExecutionContext) { case AutomationMaster.CurrentExecutionContext.SetUpClass: AutomationMaster.AutoSkips.Add(new KeyValuePair <string[], string>(new string[] { "class", AutomationMaster.CurrentTestContext.ClassName }, string.Format("FAILURE OCCURRED IN SETUPCLASS:", message))); break; case AutomationMaster.CurrentExecutionContext.SetUp: AutomationMaster.AutoSkips.Add(new KeyValuePair <string[], string>(new string[] { "test", AutomationMaster.CurrentTestContext.TestName }, string.Format("FAILURE OCCURRED IN SETUP:", message))); break; case AutomationMaster.CurrentExecutionContext.TearDownClass: yield return(StartCoroutine(Q.assert.Warn(string.Format("A failure occurred in the TearDownClass logic for the test \"{0}.{1}\". This fails the last-run test, and may cause other undesirable behavior for downstream test execution.", AutomationMaster.CurrentTestContext.ClassName, AutomationMaster.CurrentTestContext.TestName)))); //Will automatically handle the failure of this test. break; case AutomationMaster.CurrentExecutionContext.TearDown: //Will automatically handle the failure of this test. case AutomationMaster.CurrentExecutionContext.Test: //Will automatically handle the failure of this test. default: break; } if ((AutomationMaster.TryContinueOnFailure || MideExecution_MarkTestToTryContinueAfterFail) && ConcurrentFailures > 5) { AutomationMaster.OverrideContinueOnFailureAfterTooManyConcurrentFailures = true; } #if UNITY_EDITOR AutomationMaster.PauseEditorOnFailure(); #endif //Any FailureContext beyond TestMethod will not have an instantiated test method. if (!AutomationMaster.TryContinueOnFailure) { if ((!isSoft && AutomationMaster.OverrideContinueOnFailureAfterTooManyConcurrentFailures) || (!MideExecution_MarkTestToTryContinueAfterFail && (_failureContext == FailureContext.TestMethod || _failureContext == FailureContext.Default) && failureContext != FailureContext.Skipped)) { try { AutomationMaster.CurrentTestMethod.Stop(); //Kill current test, only if the currently queued test has been initialized. } catch { } yield return(new WaitForEndOfFrame()); //Allow all Coroutines to be stopped before returning control. In reality, the coroutine calling this will be stopped, so control will never be returned anyway. } } if (!isSoft && (AutomationMaster.TryContinueOnFailure || MideExecution_MarkTestToTryContinueAfterFail)) { ConcurrentFailures++; } } if (testRailsId.Length > 0) { AutomationReport.MarkTestRailsTestCase(AutomationMaster.CurrentTestContext.IsSuccess ? "Passed" : "Failed", testRailsId); } AutoConsole.PostMessage(string.Format("Assert [{0}] |{1}| {2}", AutomationMaster.CurrentTestContext.TestName, AutomationMaster.CurrentTestContext.IsSuccess ? "Success" : "Failure", message), MessageLevel.Verbose, ConsoleMessageType.TestRunnerUpdate); UnitTestStepFailure = isSoft = isTry = quiet = false; //Reset the UnitTestStepFailure, Soft, Try, and Quiet flags. yield return(null); }
//Handles remote login failure typically where user doesn't give consent private static Task HandleRemoteLoginFailure(FailureContext ctx) { ctx.Response.Redirect("/Account/Login"); ctx.HandleResponse(); return(Task.CompletedTask); }
private Task OnRemoteFailure(FailureContext context) { context.Response.Redirect("/AccessDenied?error=" + context.Failure.Message); return(Task.FromResult(0)); }
// Handle sign-in errors differently than generic errors. private Task OnAuthenticationFailed(FailureContext context) { context.HandleResponse(); context.Response.StatusCode = 401; // this should trigger the status code error pages return(Task.FromResult(0)); }
public IEnumerator Warn(string message, FailureContext failureContext = FailureContext.Default) { AutoConsole.PostMessage(string.Format("{0} {1}", AutomationMaster.WARNING_FLAG, message), MessageLevel.Abridged); yield return(StartCoroutine(Unifier(true, false, message, failureContext))); }