/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Workspaces/CoreTest/UtilityTest/ExceptionHelpersTests.cs
69 строк
2 KB
Jason Malinowski
Switch code that was using Assert.True/False as a replacement for .Fail
21 апр 2026, 23:28
21 апр 2026, 23:28
3bf59ba
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Text.Json; using Microsoft.CodeAnalysis.ErrorReporting; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.UnitTests; public sealed class ExceptionHelpersTests : TestBase { /// <summary> /// Test that throwing OperationCanceledException does NOT trigger FailFast /// </summary> [Fact] public void TestExecuteWithErrorReportingThrowOperationCanceledException() { var finallyExecuted = false; void a() { try { throw new OperationCanceledException(); } finally { finallyExecuted = true; } } try { try { a(); } catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e)) { throw ExceptionUtilities.Unreachable(); } Assert.Fail("Should not get here because an exception should be thrown before this point."); } catch (OperationCanceledException) { Assert.True(finallyExecuted); return; } Assert.Fail("Should have returned in the catch block before this point."); } [Fact] public void ErrorReporting_SerializesException() { FatalError.SetHandlers(delegate { }, delegate { }); var e = new Exception("Hello"); FatalError.ReportNonFatalError(e); Assert.NotEmpty(e.Data); Assert.NotNull(JsonSerializer.Serialize(e)); Assert.NotNull(Newtonsoft.Json.JsonConvert.SerializeObject(e)); } }