Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 10 additions & 6 deletions .github/workflows/github-actions-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup .NET 8.x
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.x'

- name: Restore dependencies
run: dotnet restore PosInformatique.Moq.Analyzers.sln
run: dotnet restore PosInformatique.Moq.Analyzers.slnx

- name: Build solution
run: |
dotnet build PosInformatique.Moq.Analyzers.sln \
dotnet build PosInformatique.Moq.Analyzers.slnx \
--configuration Release \
--no-restore

- name: Run tests
run: |
dotnet test PosInformatique.Moq.Analyzers.sln \
dotnet test \
--solution PosInformatique.Moq.Analyzers.slnx \
--configuration Release \
--no-build \
--logger "trx;LogFileName=test_results.trx" \
--coverage \
--coverage-output-format cobertura \
--coverage-settings CodeCoverage.runsettings \
--report-trx \
--results-directory ./TestResults

- name: Publish Test Results
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/github-actions-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: string
description: The version of the library
required: true
default: 2.0.1
default: 2.1.0
VersionSuffix:
type: string
description: The version suffix of the library (for example rc.1)
Expand All @@ -18,12 +18,15 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Setup .NET 8.x
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet pack
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<!-- Common NuGet packages -->
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PackageReference Include="StyleCop.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
18 changes: 18 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="5.0.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.7.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="2.2.3" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.14.15" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.2" />
</ItemGroup>
</Project>
116 changes: 0 additions & 116 deletions PosInformatique.Moq.Analyzers.sln

This file was deleted.

71 changes: 71 additions & 0 deletions PosInformatique.Moq.Analyzers.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path=".gitignore" />
<File Path="CodeCoverage.runsettings" />
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
<File Path="global.json" />
<File Path="LICENSE" />
<File Path="README.md" />
<File Path="stylecop.json" />
</Folder>
<Folder Name="/Solution Items/.github/" />
<Folder Name="/Solution Items/.github/workflows/">
<File Path=".github/workflows/github-actions-ci.yaml" />
<File Path=".github/workflows/github-actions-release.yml" />
</Folder>
<Folder Name="/Solution Items/docs/" />
<Folder Name="/Solution Items/docs/Compilation/">
<File Path="docs/Compilation/PosInfoMoq2000.md" />
<File Path="docs/Compilation/PosInfoMoq2001.md" />
<File Path="docs/Compilation/PosInfoMoq2002.md" />
<File Path="docs/Compilation/PosInfoMoq2003.md" />
<File Path="docs/Compilation/PosInfoMoq2004.md" />
<File Path="docs/Compilation/PosInfoMoq2005.md" />
<File Path="docs/Compilation/PosInfoMoq2006.md" />
<File Path="docs/Compilation/PosInfoMoq2007.md" />
<File Path="docs/Compilation/PosInfoMoq2008.md" />
<File Path="docs/Compilation/PosInfoMoq2009.md" />
<File Path="docs/Compilation/PosInfoMoq2010.md" />
<File Path="docs/Compilation/PosInfoMoq2011.md" />
<File Path="docs/Compilation/PosInfoMoq2012.md" />
<File Path="docs/Compilation/PosInfoMoq2013.md" />
<File Path="docs/Compilation/PosInfoMoq2014.md" />
<File Path="docs/Compilation/PosInfoMoq2015.md" />
<File Path="docs/Compilation/PosInfoMoq2016.md" />
<File Path="docs/Compilation/PosInfoMoq2017.md" />
<File Path="docs/Compilation/PosInfoMoq2018.md" />
<File Path="docs/Compilation/PosInfoMoq2019.md" />
</Folder>
<Folder Name="/Solution Items/docs/Design/">
<File Path="docs/design/PosInfoMoq1000.md" />
<File Path="docs/design/PosInfoMoq1001.md" />
<File Path="docs/Design/PosInfoMoq1002.md" />
<File Path="docs/Design/PosInfoMoq1003.md" />
<File Path="docs/Design/PosInfoMoq1004.md" />
<File Path="docs/Design/PosInfoMoq1005.md" />
<File Path="docs/Design/PosInfoMoq1006.md" />
<File Path="docs/Design/PosInfoMoq1007.md" />
<File Path="docs/Design/PosInfoMoq1008.md" />
<File Path="docs/Design/PosInfoMoq1009.md" />
<File Path="docs/Design/PosInfoMoq1010.md" />
<File Path="docs/Design/PosInfoMoq1011.md" />
</Folder>
<Folder Name="/Solution Items/src/">
<File Path="src/Directory.Build.props" />
</Folder>
<Folder Name="/Solution Items/tests/">
<File Path="tests/.editorconfig" />
<File Path="tests/Directory.Build.props" />
</Folder>
<Folder Name="/src/">
<File Path="src/.editorconfig" />
</Folder>
<Project Path="src/Moq.Analyzers.CodeFixes/Moq.Analyzers.CodeFixes.csproj" />
<Project Path="src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.shproj" />
<Project Path="src/Moq.Analyzers/Moq.Analyzers.csproj" />
<Project Path="tests/Moq.Analyzers.CodeFixes.Tests/Moq.Analyzers.CodeFixes.Tests.csproj" />
<Project Path="tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj" />
<Project Path="tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj" />
</Solution>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Design rules used to make your unit tests more strongly strict.
| [PosInfoMoq1008: The `Mock.Verify()` and `Mock.VerifyAll()` methods must specify at least one mock.](docs/Design/PosInfoMoq1008.md) | When calling the static methods `Mock.Verify()` or `Mock.VerifyAll()` without providing any `Mock<T>` instances, no verification is performed. |
| [PosInfoMoq1009: Avoid using `Verifiable()` method](docs/Design/PosInfoMoq1009.md) | A `Verify()` of an `Mock<T>` instance has not been called in the *Assert* phase of an unit test for `Verifiable()` setups. |
| [PosInfoMoq1010: Use `+= null` syntax when raising events with `Raise()`/`RaiseAsync()`](docs/Design/PosInfoMoq1010.md) | When using `Mock<T>.Raise()` or `Mock<T>.RaiseAsync()`, the lambda expression used to identify the event should consistently use the `+= null` syntax. |
| [PosInfoMoq1011: The `Setup()` expression must explicitly specify optional argument values](docs/Design/PosInfoMoq1011.md) | When setting up a method with optional arguments, the default values must be written explicitly in the `Setup()` expression. |

### Compilation

Expand Down
47 changes: 47 additions & 0 deletions docs/Design/PosInfoMoq1011.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# PosInfoMoq1011: The `Setup()` expression must explicitly specify optional argument values

| Property | Value |
|----------------------|-----------------------------------------------------------------------|
| **Rule ID** | PosInfoMoq1011 |
| **Title** | The `Setup()` expression must explicitly specify optional argument values |
| **Category** | Design |
| **Default severity** | Warning |

## Cause

A `Setup()` expression uses omitted optional arguments instead of explicitly specifying their default values.

## Rule description

When setting up a method or member that declares optional arguments, the optional values must be written explicitly in the `Setup()` expression, even if C# allows omitting them.

For example, if a mocked interface declares the following method:

```csharp
public interface ICalculator
{
void Method(int a = 10);
}
```

The following setup is valid in C#, but it is not accepted by this rule:

```csharp
calculatorMock.Setup(c => c.Method());
```

Instead, the default value must be written explicitly:

```csharp
calculatorMock.Setup(c => c.Method(10));
```

This makes the intended behavior of the test clearer and avoids relying on the compiler-generated default argument expansion inside the lambda expression.

## How to fix violations

To fix a violation of this rule, update the `Setup()` expression so that every optional argument is explicitly passed with its default value.

## When to suppress warnings

Do not suppress warnings from this rule. Optional arguments should be written explicitly in `Setup()` expressions for clarity and consistency.
9 changes: 9 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sdk": {
"version": "10.0.100",
"rollForward": "latestMajor"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
25 changes: 25 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)/../'))" />

<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>

<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>

<DevelopmentDependency>true</DevelopmentDependency>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------

namespace PosInformatique.Moq.Analyzers
namespace PosInformatique.Moq.Analyzers.CodeFixes
{
using System.Collections.Immutable;
using System.Composition;
Expand All @@ -20,7 +20,7 @@ public class AddVerifyAllCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(VerifyAllShouldBeCalledAnalyzer.Rule.Id); }
get { return ImmutableArray.Create(AnalyzerRules.VerifyAllShouldBeCalledAnalyzerRuleId); }
}

public sealed override FixAllProvider GetFixAllProvider()
Expand Down
Loading