Skip to content

Commit

Permalink
152 nested namespaces support fix (#157)
Browse files Browse the repository at this point in the history
* add test case for scenario

* support for full namespace using statement inside a namespace
  • Loading branch information
Meir017 authored Apr 1, 2022
1 parent 956de8d commit 0e0fa4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ public void AssertIsTrue_NestedUsingInNamespace7_TestAnalyzer(string assertion)
.AppendLine("}")
.ToString());

[AssertionDataTestMethod]
[AssertionDiagnostic("Assert.IsTrue(actual{0});")]
[AssertionDiagnostic("Assert.IsTrue(bool.Parse(\"true\"){0});")]
[Implemented]
public void AssertIsTrue_NestedUsingInNamespace8_TestAnalyzer(string assertion)
=> VerifyCSharpDiagnostic<AssertIsTrueAnalyzer>("bool actual", assertion, new StringBuilder()
.AppendLine("using System;")
.AppendLine("using FluentAssertions;")
.AppendLine("using FluentAssertions.Extensions;")
.AppendLine("using System.Threading.Tasks;")
.AppendLine("namespace Testing")
.AppendLine("{")
.AppendLine(" using Microsoft.VisualStudio.TestTools.UnitTesting;")
.AppendLine(" class TestClass")
.AppendLine(" {")
.AppendLine($" void TestMethod(bool actual)")
.AppendLine(" {")
.AppendLine($" {assertion}")
.AppendLine(" }")
.AppendLine(" }")
.AppendMainMethod()
.AppendLine("}")
.ToString());

[AssertionDataTestMethod]
[AssertionCodeFix(
oldAssertion: "Assert.IsTrue(actual{0});",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ protected override bool ShouldAnalyzeMethod(MethodDeclarationSyntax method)
var baseNamespace = string.Join(".", namespaces.Take(i+1).Select(ns => ns.Name));
foreach (var @using in namespaces[i].Usings)
{
if (@using.Name.NormalizeWhitespace().ToString().Equals(TestingLibraryNamespace)) return true;

var fullUsing = SF.ParseName($"{baseNamespace}.{@using.Name}").NormalizeWhitespace().ToString();
if (fullUsing.Equals(TestingLibraryNamespace)) return true;
}
Expand Down

0 comments on commit 0e0fa4b

Please sign in to comment.