Skip to content

Commit

Permalink
adding test for overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
bc3tech committed Jan 7, 2024
1 parent 5f02d24 commit e2d0c9a
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions DocGpt.Test/CodeFixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[TestClass]
public class CodeFixTests
{
public static TestContext Context { get; private set; }
public TestContext Context { get; set; }

[ClassInitialize]
public static void ClassInit(TestContext context)
Expand All @@ -23,7 +23,7 @@ public static void ClassInit(TestContext context)
DocGptOptions.Instance.ApiKey = "foo";
DocGptOptions.Instance.ModelDeploymentName = "foo";

Context = context;
//Context = context;
}

/// <summary>
Expand Down Expand Up @@ -71,5 +71,65 @@ class MyClass
Microsoft.CodeAnalysis.Testing.DiagnosticResult expected = VerifyCS.Diagnostic(DocGptAnalyzer.Rule).WithSpan(14, 31, 14, 38).WithArguments("FieldDeclaration", "MyConst");
await VerifyCS.VerifyCodeFixAsync(test, expected, fixd);
}

/// <summary>
/// Analyzers the throws class decl.
/// </summary>
/// <returns>A Task.</returns>
[TestMethod]
public async Task CodeFix_DGPT001_Override()
{
string test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
/// <summary></summary>
class MyClass
{
/// <summary>Foo</summary>
protected virtual bool DoSomething() => true;
}
/// <summary></summary>
class MyDerivedClass : MyClass
{
protected override bool DoSomething() => false;
}
}";

string fixd = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
/// <summary></summary>
class MyClass
{
/// <summary>Foo</summary>
protected virtual bool DoSomething() => true;
}
/// <summary></summary>
class MyDerivedClass : MyClass
{
/// <inheritdoc />
protected override bool DoSomething() => false;
}
}";

Microsoft.CodeAnalysis.Testing.DiagnosticResult expected = VerifyCS.Diagnostic(DocGptAnalyzer.Rule).WithSpan(21, 33, 21, 44).WithArguments("MethodDeclaration", "DoSomething");
await VerifyCS.VerifyCodeFixAsync(test, expected, fixd);
}
}
}

0 comments on commit e2d0c9a

Please sign in to comment.