Skip to content

Commit 0e0fa4b

Browse files
authored
152 nested namespaces support fix (#157)
* add test case for scenario * support for full namespace using statement inside a namespace
1 parent 956de8d commit 0e0fa4b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ public void AssertIsTrue_NestedUsingInNamespace7_TestAnalyzer(string assertion)
185185
.AppendLine("}")
186186
.ToString());
187187

188+
[AssertionDataTestMethod]
189+
[AssertionDiagnostic("Assert.IsTrue(actual{0});")]
190+
[AssertionDiagnostic("Assert.IsTrue(bool.Parse(\"true\"){0});")]
191+
[Implemented]
192+
public void AssertIsTrue_NestedUsingInNamespace8_TestAnalyzer(string assertion)
193+
=> VerifyCSharpDiagnostic<AssertIsTrueAnalyzer>("bool actual", assertion, new StringBuilder()
194+
.AppendLine("using System;")
195+
.AppendLine("using FluentAssertions;")
196+
.AppendLine("using FluentAssertions.Extensions;")
197+
.AppendLine("using System.Threading.Tasks;")
198+
.AppendLine("namespace Testing")
199+
.AppendLine("{")
200+
.AppendLine(" using Microsoft.VisualStudio.TestTools.UnitTesting;")
201+
.AppendLine(" class TestClass")
202+
.AppendLine(" {")
203+
.AppendLine($" void TestMethod(bool actual)")
204+
.AppendLine(" {")
205+
.AppendLine($" {assertion}")
206+
.AppendLine(" }")
207+
.AppendLine(" }")
208+
.AppendMainMethod()
209+
.AppendLine("}")
210+
.ToString());
211+
188212
[AssertionDataTestMethod]
189213
[AssertionCodeFix(
190214
oldAssertion: "Assert.IsTrue(actual{0});",

src/FluentAssertions.Analyzers/Utilities/FluentAssertionsAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ protected override bool ShouldAnalyzeMethod(MethodDeclarationSyntax method)
143143
var baseNamespace = string.Join(".", namespaces.Take(i+1).Select(ns => ns.Name));
144144
foreach (var @using in namespaces[i].Usings)
145145
{
146+
if (@using.Name.NormalizeWhitespace().ToString().Equals(TestingLibraryNamespace)) return true;
147+
146148
var fullUsing = SF.ParseName($"{baseNamespace}.{@using.Name}").NormalizeWhitespace().ToString();
147149
if (fullUsing.Equals(TestingLibraryNamespace)) return true;
148150
}

0 commit comments

Comments
 (0)