-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add BooleanAsserts * add xunit to tests * introduce base codeFixer for testing libraries * xunit: add IdentityAsserts
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/FluentAssertions.Analyzers/Tips/Xunit/AssertNotSame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
|
||
namespace FluentAssertions.Analyzers.Xunit | ||
{ | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class AssertNotSameAnalyzer : XunitAnalyzer | ||
{ | ||
public const string DiagnosticId = Constants.Tips.Xunit.AssertNotSame; | ||
public const string Category = Constants.Tips.Category; | ||
|
||
public const string Message = "Use .Should().NotBeSameAs() instead."; | ||
|
||
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true); | ||
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | ||
{ | ||
get | ||
{ | ||
yield return new AssertNotSameSyntaxVisitor(); | ||
} | ||
} | ||
|
||
public class AssertNotSameSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertNotSameSyntaxVisitor() : base(new MemberValidator("NotSame")) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AssertNotSameCodeFix)), Shared] | ||
public class AssertNotSameCodeFix : XunitCodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AssertNotSameAnalyzer.DiagnosticId); | ||
|
||
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) | ||
{ | ||
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "NotSame", "NotBeSameAs"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeFixes; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
|
||
namespace FluentAssertions.Analyzers.Xunit | ||
{ | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class AssertSameAnalyzer : XunitAnalyzer | ||
{ | ||
public const string DiagnosticId = Constants.Tips.Xunit.AssertSame; | ||
public const string Category = Constants.Tips.Category; | ||
|
||
public const string Message = "Use .Should().BeSameAs() instead."; | ||
|
||
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true); | ||
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | ||
{ | ||
get | ||
{ | ||
yield return new AssertSameSyntaxVisitor(); | ||
} | ||
} | ||
|
||
public class AssertSameSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertSameSyntaxVisitor() : base(new MemberValidator("Same")) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AssertSameCodeFix)), Shared] | ||
public class AssertSameCodeFix : XunitCodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AssertSameAnalyzer.DiagnosticId); | ||
|
||
protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression, FluentAssertionsDiagnosticProperties properties) | ||
{ | ||
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "Same", "BeSameAs"); | ||
} | ||
} | ||
} |