-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first mstest analyzer * added Assert.IsFalse * cleanup * progress * added helper for mstest * more analyzers * wip * fix conflicts * add support for Assert.ThrowsException & Assert.ThrowsExceptionAsync * save * added support for more AssertEqual cases * support AssertAreNotEqual * completed mstest Assert scenarios * cleanup rule messages * add CollectionAssertAllItemsAreInstancesOfType * CollectionAssert fixes * cleanup usings * cleanups * fix parent class for mstest Assert * add CollectionAssert AreEqual / AreNotEqual * fix parent class for CollectionAssert * fix parent class for StringAssert * add CollectionAssert AreEquivalent / AreNotEquivalent * add CollectionAssertAllItemsAreNotNull * add CollectionAssert.AllItemsAreUnique * add CollectionAssert.Contains * add CollectionAssert.DoesNotContain * fix tests * add CollectionAssert.IsSubsetOf / CollectionAssert.IsNotSubsetOf * add StringAssert methods * fix tests
- Loading branch information
Showing
54 changed files
with
2,268 additions
and
32 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
545 changes: 545 additions & 0 deletions
545
src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
src/FluentAssertions.Analyzers/Tips/MsTest/AssertAreEqual.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,104 @@ | ||
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; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using TypeSelector = FluentAssertions.Analyzers.Utilities.SemanticModelTypeExtensions; | ||
|
||
namespace FluentAssertions.Analyzers | ||
{ | ||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class AssertAreEqualAnalyzer : MsTestAssertAnalyzer | ||
{ | ||
public const string DiagnosticId = Constants.Tips.MsTest.AssertAreEqual; | ||
public const string Category = Constants.Tips.Category; | ||
|
||
public const string Message = "Use .Should().BeApproximately() for complex numbers and .Should().Be() for other cases."; | ||
|
||
protected override DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Message, Category, DiagnosticSeverity.Info, true); | ||
protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors | ||
{ | ||
get | ||
{ | ||
yield return new AssertFloatAreEqualWithDeltaSyntaxVisitor(); | ||
yield return new AssertDoubleAreEqualWithDeltaSyntaxVisitor(); | ||
yield return new AssertStringAreEqualSyntaxVisitor(); | ||
yield return new AssertObjectAreEqualSyntaxVisitor(); | ||
} | ||
} | ||
|
||
// public static void AreEqual(float expected, float actual, float delta) | ||
public class AssertFloatAreEqualWithDeltaSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertFloatAreEqualWithDeltaSyntaxVisitor() : base( | ||
MemberValidator.ArgumentsMatch("AreEqual", | ||
ArgumentValidator.IsType(TypeSelector.GetFloatType), | ||
ArgumentValidator.IsType(TypeSelector.GetFloatType), | ||
ArgumentValidator.IsType(TypeSelector.GetFloatType)) | ||
) | ||
{ | ||
} | ||
} | ||
|
||
// public static void AreEqual(double expected, double actual, double delta) | ||
public class AssertDoubleAreEqualWithDeltaSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertDoubleAreEqualWithDeltaSyntaxVisitor() : base( | ||
MemberValidator.ArgumentsMatch("AreEqual", | ||
ArgumentValidator.IsType(TypeSelector.GetDoubleType), | ||
ArgumentValidator.IsType(TypeSelector.GetDoubleType), | ||
ArgumentValidator.IsType(TypeSelector.GetDoubleType)) | ||
) | ||
{ | ||
} | ||
} | ||
|
||
// public static void AreEqual(string expected, string actual, bool ignoreCase, CultureInfo culture | ||
public class AssertStringAreEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertStringAreEqualSyntaxVisitor() : base( | ||
MemberValidator.ArgumentsMatch("AreEqual", | ||
ArgumentValidator.IsType(TypeSelector.GetStringType), | ||
ArgumentValidator.IsType(TypeSelector.GetStringType), | ||
ArgumentValidator.IsType(TypeSelector.GetBooleanType))) | ||
{ | ||
} | ||
} | ||
|
||
// public static void AreEqual<T>(T expected, T actual) | ||
// public static void AreEqual(object expected, object actual) | ||
public class AssertObjectAreEqualSyntaxVisitor : FluentAssertionsCSharpSyntaxVisitor | ||
{ | ||
public AssertObjectAreEqualSyntaxVisitor() : base(new MemberValidator("AreEqual")) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AssertAreEqualCodeFix)), Shared] | ||
public class AssertAreEqualCodeFix : MsTestCodeFixProvider | ||
{ | ||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AssertAreEqualAnalyzer.DiagnosticId); | ||
|
||
protected override async Task<ExpressionSyntax> GetNewExpressionAsync(ExpressionSyntax expression, Document document, FluentAssertionsDiagnosticProperties properties, CancellationToken cancellationToken) | ||
{ | ||
switch (properties.VisitorName) | ||
{ | ||
case nameof(AssertAreEqualAnalyzer.AssertFloatAreEqualWithDeltaSyntaxVisitor): | ||
case nameof(AssertAreEqualAnalyzer.AssertDoubleAreEqualWithDeltaSyntaxVisitor): | ||
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "AreEqual", "BeApproximately", "Assert"); | ||
case nameof(AssertAreEqualAnalyzer.AssertObjectAreEqualSyntaxVisitor): | ||
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "AreEqual", "Be", "Assert"); | ||
case nameof(AssertAreEqualAnalyzer.AssertStringAreEqualSyntaxVisitor): | ||
var semanticModel = await document.GetSemanticModelAsync(cancellationToken); | ||
return GetNewExpressionForAreNotEqualOrAreEqualStrings(expression, semanticModel, "AreEqual", "Be", "BeEquivalentTo", "Assert"); | ||
default: | ||
throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.