From e2d0c9a2be3df862eb16720d343df8c2d1ecb653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=F0=9F=8C=A9=EF=B8=8FH?= Date: Sun, 7 Jan 2024 15:14:53 -0800 Subject: [PATCH] adding test for overrides --- DocGpt.Test/CodeFixTests.cs | 64 +++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/DocGpt.Test/CodeFixTests.cs b/DocGpt.Test/CodeFixTests.cs index 02e808b..71f6fa8 100644 --- a/DocGpt.Test/CodeFixTests.cs +++ b/DocGpt.Test/CodeFixTests.cs @@ -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) @@ -23,7 +23,7 @@ public static void ClassInit(TestContext context) DocGptOptions.Instance.ApiKey = "foo"; DocGptOptions.Instance.ModelDeploymentName = "foo"; - Context = context; + //Context = context; } /// @@ -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); } + + /// + /// Analyzers the throws class decl. + /// + /// A Task. + [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 +{ + /// + class MyClass + { + /// Foo + protected virtual bool DoSomething() => true; + } + + /// + 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 +{ + /// + class MyClass + { + /// Foo + protected virtual bool DoSomething() => true; + } + + /// + class MyDerivedClass : MyClass + { + /// + 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); + } } }