Skip to content

Commit

Permalink
Format tests and add test validating correct exception type is caught
Browse files Browse the repository at this point in the history
  • Loading branch information
Qluxzz committed Sep 22, 2024
1 parent 353f766 commit 7bc2b71
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Foo(object parameter)
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddExceptionToDocumentationComment)]
public async Task Test_No_Diagnostic_If_Exception_Is_Caught_In_Same_Method()
public async Task Test_No_Diagnostic_If_Exception_Is_Caught_In_Method()
{
await VerifyNoDiagnosticAsync("""
using System;
Expand All @@ -77,7 +77,7 @@ public void Foo(object parameter)
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddExceptionToDocumentationComment)]
public async Task Test_No_Diagnostic_If_Exception_Is_Caught_In_Same_Method_Nested()
public async Task Test_No_Diagnostic_If_Exception_Is_Caught_In_Method_Nested()
{
await VerifyNoDiagnosticAsync("""
using System;
Expand All @@ -92,7 +92,8 @@ public void Foo(object parameter)
{
try
{
try {
try
{
if (parameter == null)
throw new ArgumentNullException(nameof(parameter));
}
Expand All @@ -101,6 +102,53 @@ public void Foo(object parameter)
catch (ArgumentNullException) {}
}
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddExceptionToDocumentationComment)]
public async Task Test_Diagnostic_If_Not_Correct_Exception_Is_Caught_In_Method()
{
await VerifyDiagnosticAndFixAsync("""
using System;

class C
{
/// <summary>
/// ...
/// </summary>
/// <param name="parameter"></param>
public void Foo(object parameter)
{
try
{
if (parameter == null)
[|throw new ArgumentNullException(nameof(parameter));|]
}
catch (InvalidOperationException) {}
}
}

""", """
using System;

class C
{
/// <summary>
/// ...
/// </summary>
/// <param name="parameter"></param>
/// <exception cref="ArgumentNullException"><paramref name="parameter"/> is <c>null</c>.</exception>
public void Foo(object parameter)
{
try
{
if (parameter == null)
throw new ArgumentNullException(nameof(parameter));
}
catch (InvalidOperationException) {}
}
}

""");
}
}

0 comments on commit 7bc2b71

Please sign in to comment.