Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
26 changes: 15 additions & 11 deletions src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,22 @@ private static void AnalyzeInstanceCall(SyntaxNodeAnalysisContext context)
return;
}

switch (genericNameSyntax.Identifier.Value)
if (genericNameSyntax.Identifier.Value is not string genericNameSyntaxIdentifierValue)
{
case WellKnownTypeNames.Create:
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockFactory, true, true);
break;

case WellKnownTypeNames.Of:
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockName, false, true);
break;
return;
}
Comment thread
rjmurillo marked this conversation as resolved.

default:
return;
if (string.Equals(genericNameSyntaxIdentifierValue, WellKnownTypeNames.Create, StringComparison.Ordinal))
{
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockFactory, true, true);
}
else if (string.Equals(genericNameSyntaxIdentifierValue, WellKnownTypeNames.Of, StringComparison.Ordinal))
{
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.Mock, false, true);
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
}
else
{
return;
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
}
}

Expand Down Expand Up @@ -286,7 +290,7 @@ private static void AnalyzeNewObject(SyntaxNodeAnalysisContext context)
// Quick check
if (!string.Equals(
genericNameSyntax.Identifier.ValueText,
WellKnownTypeNames.MockName,
WellKnownTypeNames.Mock,
StringComparison.Ordinal))
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/MoqMethodDescriptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
internal abstract class MoqMethodDescriptorBase
{
private static readonly string ContainingNamespace = WellKnownTypeNames.Moq;
private static readonly string ContainingType = WellKnownTypeNames.MockName;
private static readonly string ContainingType = WellKnownTypeNames.Mock;

public abstract bool IsMatch(SemanticModel semanticModel, MemberAccessExpressionSyntax memberAccessSyntax, CancellationToken cancellationToken);

Comment thread
rjmurillo marked this conversation as resolved.
Expand Down
24 changes: 11 additions & 13 deletions src/Common/WellKnownTypeNames.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
namespace Moq.Analyzers.Common;

#pragma warning disable ECS0200 // Consider using readonly instead of const for flexibility

internal static class WellKnownTypeNames
{
internal const string Moq = nameof(Moq);
internal const string MockName = "Mock";
internal const string MockBehavior = nameof(MockBehavior);
internal const string MockFactory = nameof(MockFactory);
internal const string MoqMock = $"{Moq}.{MockName}";
internal const string MoqMock1 = $"{MoqMock}`1";
internal const string MoqBehavior = $"{Moq}.{MockBehavior}";
internal const string MoqRepository = $"{Moq}.MockRepository";
internal const string As = nameof(As);
internal const string Create = nameof(Create);
internal const string Of = nameof(Of);
internal static readonly string Moq = nameof(Moq);
Comment thread
MattKotsenas marked this conversation as resolved.
Outdated
internal static readonly string Mock = nameof(Mock);
Comment thread
rjmurillo marked this conversation as resolved.
Outdated
internal static readonly string MockBehavior = nameof(MockBehavior);
internal static readonly string MockFactory = nameof(MockFactory);
internal static readonly string MoqMock = $"{Moq}.{Mock}";
internal static readonly string MoqMock1 = $"{MoqMock}`1";
internal static readonly string MoqBehavior = $"{Moq}.{MockBehavior}";
internal static readonly string MoqRepository = $"{Moq}.MockRepository";
internal static readonly string As = nameof(As);
internal static readonly string Create = nameof(Create);
internal static readonly string Of = nameof(Of);
}