Skip to content

Commit

Permalink
Upgraded to support VS 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
Litee committed Jul 28, 2019
1 parent c6bbe56 commit d64e270
Show file tree
Hide file tree
Showing 60 changed files with 3,248 additions and 3,181 deletions.
576 changes: 288 additions & 288 deletions .gitignore

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017, Andrey Lipatkin
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
BSD 3-Clause License
Copyright (c) 2017, Andrey Lipatkin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 changes: 37 additions & 37 deletions Moq.Analyzers.sln
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers", "Source\Moq.Analyzers\Moq.Analyzers.csproj", "{41ECC571-F586-460A-9BED-23528C8210C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.Test", "Source\Moq.Analyzers.Test\Moq.Analyzers.Test.csproj", "{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.Vsix", "Source\Moq.Analyzers.Vsix\Moq.Analyzers.Vsix.csproj", "{6C178A5C-B77B-484D-AD33-38E24B76FF35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{41ECC571-F586-460A-9BED-23528C8210C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Release|Any CPU.Build.0 = Release|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Release|Any CPU.Build.0 = Release|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C917BC1-C0DE-4A46-BEE8-32FD66B447B1}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers", "Source\Moq.Analyzers\Moq.Analyzers.csproj", "{41ECC571-F586-460A-9BED-23528C8210C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.Test", "Source\Moq.Analyzers.Test\Moq.Analyzers.Test.csproj", "{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.Vsix", "Source\Moq.Analyzers.Vsix\Moq.Analyzers.Vsix.csproj", "{6C178A5C-B77B-484D-AD33-38E24B76FF35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{41ECC571-F586-460A-9BED-23528C8210C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41ECC571-F586-460A-9BED-23528C8210C4}.Release|Any CPU.Build.0 = Release|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2348836-7129-4BE5-8AE6-D05FC8C28FC1}.Release|Any CPU.Build.0 = Release|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C178A5C-B77B-484D-AD33-38E24B76FF35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C917BC1-C0DE-4A46-BEE8-32FD66B447B1}
EndGlobalSection
EndGlobal
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Moq.Analyzers

Visual Studio extension and Roslyn analyzer that helps to write unit tests using Moq mocking library. Port of Resharper extension to Roslyn.

Note: If you are using Visual Studio 2017 then you can additionally install [Moq.Autocomplete](https://github.com/Litee/moq.autocomplete) extension/package to get better autocomplete suggestions when writing code.

## Detected issues

* Moq1000 = Sealed classes cannot be mocked
* Moq1001 = Mocked interfaces cannot have constructor parameters
* Moq1002 = Parameters provided into mock do not match any existing constructors
* Moq1100 = Callback signature must match the signature of the mocked method
* Moq1101 = SetupGet/SetupSet should be used for properties, not for methods

## TODO

* Setup() should be used for methods, not for properties
* Mock.As<T>() should take interfaces only
* AdvancedMatcherAttribute should accept only IMatcher types
* Checks for protected mocks when dynamically referencing their members
* Setup() requires overridable members
* Mock.Get() should not take literals

## How to install:

* (Option 1) Install "Moq.Analyzers" NuGet package into test projects. Con: Extension will work for specific projects only. Pro: It will be available for all project developers automatically.
* (Option 2) Install "Moq.Analyzers" extension into Visual Studio. Con: Every developer must install extension manually. Pro: It works for all your projects.
# Moq.Analyzers

Visual Studio extension and Roslyn analyzer that helps to write unit tests using Moq mocking library. Port of Resharper extension to Roslyn.

Note: If you are using Visual Studio 2017 then you can additionally install [Moq.Autocomplete](https://github.com/Litee/moq.autocomplete) extension/package to get better autocomplete suggestions when writing code.

## Detected issues

* Moq1000 = Sealed classes cannot be mocked
* Moq1001 = Mocked interfaces cannot have constructor parameters
* Moq1002 = Parameters provided into mock do not match any existing constructors
* Moq1100 = Callback signature must match the signature of the mocked method
* Moq1101 = SetupGet/SetupSet should be used for properties, not for methods

## TODO

* Setup() should be used for methods, not for properties
* Mock.As<T>() should take interfaces only
* AdvancedMatcherAttribute should accept only IMatcher types
* Checks for protected mocks when dynamically referencing their members
* Setup() requires overridable members
* Mock.Get() should not take literals

## How to install:

* (Option 1) Install "Moq.Analyzers" NuGet package into test projects. Con: Extension will work for specific projects only. Pro: It will be available for all project developers automatically.
* (Option 2) Install "Moq.Analyzers" extension into Visual Studio. Con: Every developer must install extension manually. Pro: It works for all your projects.
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
Diagnostic 1
Id: Moq1100
Location: SourceFile(Test0.cs[699..706))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 2
Id: Moq1100
Location: SourceFile(Test0.cs[780..802))
Highlight: (string s1, string s2)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((string s1, string s2) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 3
Id: Moq1100
Location: SourceFile(Test0.cs[915..934))
Highlight: (string s1, int i1)
Lines: mock.Setup(x => x.Do(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<DateTime>())).Callback((string s1, int i1) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 4
Id: Moq1100
Location: SourceFile(Test0.cs[1014..1021))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<List<string>>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 1
Id: Moq1100
Location: SourceFile(Test0.cs[1120..1127))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.
Diagnostic 2
Id: Moq1100
Location: SourceFile(Test0.cs[1201..1223))
Highlight: (string s1, string s2)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((string s1, string s2) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.
Diagnostic 3
Id: Moq1100
Location: SourceFile(Test0.cs[1336..1355))
Highlight: (string s1, int i1)
Lines: mock.Setup(x => x.Do(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<DateTime>())).Callback((string s1, int i1) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.
Diagnostic 4
Id: Moq1100
Location: SourceFile(Test0.cs[1435..1442))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<List<string>>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Diagnostic 1
Id: Moq1100
Location: SourceFile(Test0.cs[695..702))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 2
Id: Moq1100
Location: SourceFile(Test0.cs[776..798))
Highlight: (string s1, string s2)
Lines: mock.Setup(x => x.Do(It.IsAny<string>())).Callback((string s1, string s2) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 3
Id: Moq1100
Location: SourceFile(Test0.cs[911..930))
Highlight: (string s1, int i1)
Lines: mock.Setup(x => x.Do(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<DateTime>())).Callback((string s1, int i1) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Diagnostic 4
Id: Moq1100
Location: SourceFile(Test0.cs[1010..1017))
Highlight: (int i)
Lines: mock.Setup(x => x.Do(It.IsAny<List<string>>())).Callback((int i) => { });
Severity: Warning
Message: Callback signature must match the signature of the mocked method.

Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
namespace Moq.Analyzers.Test
{
using System.IO;
using ApprovalTests;
using ApprovalTests.Reporters;
using Microsoft.CodeAnalysis.Diagnostics;
using TestHelper;
using Xunit;

[UseReporter(typeof(DiffReporter))]
public class CallbackSignatureShouldMatchMockedMethodAnalyzerTests : DiagnosticVerifier
{
[Fact]
public void ShouldPassIfGoodParameters()
{
Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs")));
}

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CallbackSignatureShouldMatchMockedMethodAnalyzer();
}
}
namespace Moq.Analyzers.Test
{
using System.IO;
using ApprovalTests;
using ApprovalTests.Reporters;
using Microsoft.CodeAnalysis.Diagnostics;
using TestHelper;
using Xunit;

[UseReporter(typeof(DiffReporter))]
public class CallbackSignatureShouldMatchMockedMethodAnalyzerTests : DiagnosticVerifier
{
[Fact]
public void ShouldPassIfGoodParameters()
{
Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs")));
}

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CallbackSignatureShouldMatchMockedMethodAnalyzer();
}
}
}
Loading

0 comments on commit d64e270

Please sign in to comment.