Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4a5750d
test: Add comprehensive tests for DiagnosticEditProperties methods
rjmurillo Jul 26, 2025
55867eb
test: Add unit tests for DiagnosticExtensions methods
rjmurillo Jul 26, 2025
df1886c
test: Add unit test for CreateDiagnostic_FromOperation_WithProperties…
rjmurillo Jul 26, 2025
e51072f
test: Add unit tests for MoqVerificationHelpers methods
rjmurillo Jul 26, 2025
da87546
test: Add unit test for NoFixForExplicitInterfaceImplementation method
rjmurillo Jul 27, 2025
ca2f3bc
docs: Update C# file instructions to enforce valid code in tests
rjmurillo Jul 27, 2025
0bc2ba6
docs: Update C# file instructions to include code coverage validation…
rjmurillo Jul 27, 2025
63d39b6
test: Update test data for RedundantTimesSpecificationAnalyzer to inc…
rjmurillo Jul 27, 2025
774d2b2
docs: Update CONTRIBUTING.md to include code coverage validation requ…
rjmurillo Jul 27, 2025
a89a5d2
refactor: Remove unused using directives in MoqVerificationHelpersTests
rjmurillo Jul 27, 2025
368dffc
test: Remove redundant entry from test data in RedundantTimesSpecific…
rjmurillo Jul 27, 2025
2e85b52
test: Add additional cases for ExtractLambdaFromArgument in MoqVerifi…
rjmurillo Jul 27, 2025
59bf028
test: Enhance InvalidTestData with detailed comments and add verifica…
rjmurillo Jul 27, 2025
2067433
test: Add edge case tests for LinqToMocks expressions and refine exis…
rjmurillo Jul 27, 2025
bc5e21f
refactor: Simplify TestData method by using array initializers and im…
rjmurillo Jul 27, 2025
50267de
test: Enhance TestData method with additional edge cases and improve …
rjmurillo Jul 27, 2025
30c9fce
test: Remove unnecessary test case for property access in TestData me…
rjmurillo Jul 27, 2025
7a2df5c
test: Update CodeCoverage settings to exclude additional attributes a…
rjmurillo Jul 27, 2025
af00375
test: Add coverage history management to CI workflow and update cover…
rjmurillo Jul 27, 2025
e928265
test: Add baseline SHA to performance results summary
rjmurillo Jul 27, 2025
48662fd
test: Add comprehensive tests for DiagnosticEditProperties methods
rjmurillo Jul 26, 2025
26347b2
test: Add unit tests for DiagnosticExtensions methods
rjmurillo Jul 26, 2025
c284cc5
test: Add unit test for CreateDiagnostic_FromOperation_WithProperties…
rjmurillo Jul 26, 2025
351b6c3
test: Add unit tests for MoqVerificationHelpers methods
rjmurillo Jul 26, 2025
a260489
test: Add unit test for NoFixForExplicitInterfaceImplementation method
rjmurillo Jul 27, 2025
3114a71
docs: Update C# file instructions to enforce valid code in tests
rjmurillo Jul 27, 2025
656e0b4
docs: Update C# file instructions to include code coverage validation…
rjmurillo Jul 27, 2025
ca0aa8b
test: Update test data for RedundantTimesSpecificationAnalyzer to inc…
rjmurillo Jul 27, 2025
afebfd9
docs: Update CONTRIBUTING.md to include code coverage validation requ…
rjmurillo Jul 27, 2025
50024c5
refactor: Remove unused using directives in MoqVerificationHelpersTests
rjmurillo Jul 27, 2025
b7fb7a9
test: Remove redundant entry from test data in RedundantTimesSpecific…
rjmurillo Jul 27, 2025
ea9b2f5
test: Add additional cases for ExtractLambdaFromArgument in MoqVerifi…
rjmurillo Jul 27, 2025
b474f53
test: Enhance InvalidTestData with detailed comments and add verifica…
rjmurillo Jul 27, 2025
43024eb
test: Add edge case tests for LinqToMocks expressions and refine exis…
rjmurillo Jul 27, 2025
8059df2
refactor: Simplify TestData method by using array initializers and im…
rjmurillo Jul 27, 2025
87937b2
test: Enhance TestData method with additional edge cases and improve …
rjmurillo Jul 27, 2025
8f321e0
test: Remove unnecessary test case for property access in TestData me…
rjmurillo Jul 27, 2025
93bc5a2
test: Update CodeCoverage settings to exclude additional attributes a…
rjmurillo Jul 27, 2025
3a543bc
test: Add coverage history management to CI workflow and update cover…
rjmurillo Jul 27, 2025
39c3999
test: Add baseline SHA to performance results summary
rjmurillo Jul 27, 2025
cabb69e
Merge branch 'refactor/coverage-analysis' of https://github.com/rjmur…
rjmurillo Jul 27, 2025
00049eb
test: Remove upload step for coverage history in CI workflow
rjmurillo Jul 27, 2025
ada8199
fix: Update condition for uploading coverage history in CI workflow
rjmurillo Jul 27, 2025
5632bf2
test: Enhance edge case test data for LinqToMocksExpressionShouldBeVa…
rjmurillo Jul 27, 2025
9dccdc1
refactor: Remove redundant comment in LinqToMocksExpressionShouldBeVa…
rjmurillo Jul 27, 2025
930c720
refactor: Remove TryGetFromImmutableDictionary_ParsesCultureInvariant…
rjmurillo Jul 27, 2025
072a688
refactor: Remove unused using directives from analyzer and test files
rjmurillo Jul 27, 2025
56775f4
Merge branch 'main' into refactor/coverage-analysis
rjmurillo Jul 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,85 @@
Assert.Equal("2", dict[DiagnosticEditProperties.EditPositionKey]);
}

[Fact]
public void ToImmutableDictionary_AllEnumValues_RoundTrips()
{
foreach (DiagnosticEditProperties.EditType type in Enum.GetValues(typeof(DiagnosticEditProperties.EditType)))
{
DiagnosticEditProperties props = new DiagnosticEditProperties { TypeOfEdit = type, EditPosition = 0 };
ImmutableDictionary<string, string?> dict = props.ToImmutableDictionary();
Assert.Equal(type.ToString(), dict[DiagnosticEditProperties.EditTypeKey]);
Assert.Equal("0", dict[DiagnosticEditProperties.EditPositionKey]);
Assert.True(DiagnosticEditProperties.TryGetFromImmutableDictionary(dict, out DiagnosticEditProperties? roundTripped));
Assert.Equal(type, roundTripped!.TypeOfEdit);
}
}

[Fact]
public void ToImmutableDictionary_HandlesNegativeAndLargeEditPosition()
{
DiagnosticEditProperties propsNeg = new DiagnosticEditProperties { TypeOfEdit = DiagnosticEditProperties.EditType.Insert, EditPosition = -1 };
ImmutableDictionary<string, string?> dictNeg = propsNeg.ToImmutableDictionary();
Assert.Equal("-1", dictNeg[DiagnosticEditProperties.EditPositionKey]);
Assert.True(DiagnosticEditProperties.TryGetFromImmutableDictionary(dictNeg, out DiagnosticEditProperties? roundTrippedNeg));
Assert.Equal(-1, roundTrippedNeg!.EditPosition);

DiagnosticEditProperties propsLarge = new DiagnosticEditProperties { TypeOfEdit = DiagnosticEditProperties.EditType.Replace, EditPosition = int.MaxValue };
ImmutableDictionary<string, string?> dictLarge = propsLarge.ToImmutableDictionary();
Assert.Equal(int.MaxValue.ToString(), dictLarge[DiagnosticEditProperties.EditPositionKey]);
Assert.True(DiagnosticEditProperties.TryGetFromImmutableDictionary(dictLarge, out DiagnosticEditProperties? roundTrippedLarge));
Assert.Equal(int.MaxValue, roundTrippedLarge!.EditPosition);
}

[Fact]
public void TryGetFromImmutableDictionary_IgnoresExtraKeys()
{
ImmutableDictionary<string, string?> dict = ImmutableDictionary<string, string?>.Empty
.Add(DiagnosticEditProperties.EditTypeKey, "Insert")
.Add(DiagnosticEditProperties.EditPositionKey, "1")
.Add("ExtraKey", "ExtraValue");
Assert.True(DiagnosticEditProperties.TryGetFromImmutableDictionary(dict, out DiagnosticEditProperties? props));
Assert.Equal(DiagnosticEditProperties.EditType.Insert, props!.TypeOfEdit);
Assert.Equal(1, props.EditPosition);
}

[Fact]
public void DiagnosticEditProperties_EqualityAndImmutability()
{
DiagnosticEditProperties a = new DiagnosticEditProperties { TypeOfEdit = DiagnosticEditProperties.EditType.Insert, EditPosition = 1 };
DiagnosticEditProperties b = new DiagnosticEditProperties { TypeOfEdit = DiagnosticEditProperties.EditType.Insert, EditPosition = 1 };
DiagnosticEditProperties c = new DiagnosticEditProperties { TypeOfEdit = DiagnosticEditProperties.EditType.Replace, EditPosition = 1 };
Assert.Equal(a, b);
Assert.NotEqual(a, c);
Assert.True(a.Equals(b));
Assert.False(a.Equals(c));
Assert.Equal(a.GetHashCode(), b.GetHashCode());
}

[Fact]
public void TryGetFromImmutableDictionary_ParsesCultureInvariant()
{
// Use reflection to set CurrentCulture to avoid RS1035 banned symbol in test context
System.Type cultureType = typeof(System.Globalization.CultureInfo);
System.Reflection.PropertyInfo? currentCultureProperty = cultureType.GetProperty("CurrentCulture");
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
object? originalCulture = currentCultureProperty!.GetValue(null);
try
{
System.Globalization.CultureInfo frCulture = new System.Globalization.CultureInfo("fr-FR");
currentCultureProperty.SetValue(null, frCulture);
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
ImmutableDictionary<string, string?> dict = ImmutableDictionary<string, string?>.Empty
.Add(DiagnosticEditProperties.EditTypeKey, "Insert")
.Add(DiagnosticEditProperties.EditPositionKey, "1234");
DiagnosticEditProperties? props;
Assert.True(DiagnosticEditProperties.TryGetFromImmutableDictionary(dict, out props));
Assert.Equal(1234, props!.EditPosition);

Check notice on line 85 in tests/Moq.Analyzers.Test/Common/DiagnosticEditPropertiesTests.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/Moq.Analyzers.Test/Common/DiagnosticEditPropertiesTests.cs#L85

Assign this magic number '1234' to a well-named variable or constant, and use that instead.
}
finally
{
currentCultureProperty.SetValue(null, originalCulture);
}
}
Comment thread
rjmurillo marked this conversation as resolved.
Outdated

[Fact]
public void TryGetFromImmutableDictionary_Succeeds_WithValidDictionary()
{
Expand Down
66 changes: 66 additions & 0 deletions tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.Immutable;

Check warning on line 1 in tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs#L1

Provide an 'AssemblyVersion' attribute for assembly 'srcassembly.dll'.
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
using Microsoft.CodeAnalysis;

Check notice on line 2 in tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/Moq.Analyzers.Test/Common/DiagnosticExtensionsTests.cs#L2

Remove this unnecessary 'using'.
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using Moq.Analyzers.Common;
using Xunit;

namespace Moq.Analyzers.Test.Common;

public class DiagnosticExtensionsTests
{
[Fact]
public void CreateDiagnostic_FromSyntaxNode_Basic()
{
SyntaxTree tree = CSharpSyntaxTree.ParseText("class C { void M() {} }");
SyntaxNode root = tree.GetRoot();
DiagnosticDescriptor rule = new DiagnosticDescriptor("TEST0001", "Test", "Test message", "Test", DiagnosticSeverity.Warning, true);
Diagnostic diag = root.CreateDiagnostic(rule);
Assert.Equal("TEST0001", diag.Id);
Assert.Equal(DiagnosticSeverity.Warning, diag.Severity);
}

[Fact]
public void CreateDiagnostic_FromLocation_WithProperties()
{
SyntaxTree tree = CSharpSyntaxTree.ParseText("class C { void M() {} }");
Location loc = tree.GetRoot().GetLocation();
DiagnosticDescriptor rule = new DiagnosticDescriptor("TEST0002", "Test2", "Test message 2", "Test", DiagnosticSeverity.Info, true);
ImmutableDictionary<string, string?> properties = ImmutableDictionary<string, string?>.Empty.Add("Key", "Value");
Diagnostic diag = loc.CreateDiagnostic(rule, properties);
Assert.Equal("TEST0002", diag.Id);
Assert.Equal("Value", diag.Properties["Key"]);
}

[Fact]
public void CreateDiagnostic_FromOperation_DelegatesToSyntax()
{
SyntaxTree tree = CSharpSyntaxTree.ParseText("class C { void M() {} }");
SyntaxNode root = tree.GetRoot();
CSharpCompilation compilation = CSharpCompilation.Create("Test", new[] { tree });
SemanticModel model = compilation.GetSemanticModel(tree);
MethodDeclarationSyntax methodDecl = root.DescendantNodes().OfType<MethodDeclarationSyntax>().First();
Comment thread
rjmurillo marked this conversation as resolved.
Microsoft.CodeAnalysis.IOperation? operation = model.GetOperation(methodDecl);
DiagnosticDescriptor rule = new DiagnosticDescriptor("TEST0003", "Test3", "Test message 3", "Test", DiagnosticSeverity.Error, true);
Diagnostic diag = operation!.CreateDiagnostic(rule);
Assert.Equal("TEST0003", diag.Id);
Assert.Equal(DiagnosticSeverity.Error, diag.Severity);
}

[Fact]
public void CreateDiagnostic_FromOperation_WithProperties()
{
SyntaxTree tree = CSharpSyntaxTree.ParseText("class C { void M() {} }");
SyntaxNode root = tree.GetRoot();
CSharpCompilation compilation = CSharpCompilation.Create("Test", new[] { tree });
SemanticModel model = compilation.GetSemanticModel(tree);
MethodDeclarationSyntax methodDecl = root.DescendantNodes().OfType<MethodDeclarationSyntax>().First();
Microsoft.CodeAnalysis.IOperation? operation = model.GetOperation(methodDecl);
DiagnosticDescriptor rule = new DiagnosticDescriptor("TEST0004", "Test4", "Test message 4", "Test", DiagnosticSeverity.Warning, true);
ImmutableDictionary<string, string?> properties = ImmutableDictionary<string, string?>.Empty.Add("Key2", "Value2");
Diagnostic diag = operation!.CreateDiagnostic(rule, properties);
Assert.Equal("TEST0004", diag.Id);
Assert.Equal("Value2", diag.Properties["Key2"]);
}
}
Loading