diff --git a/Directory.Build.props b/Directory.Build.props index 75594389..b614b1e7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,5 +4,6 @@ + diff --git a/Directory.Build.targets b/Directory.Build.targets index 9bd765d4..1f314eac 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,4 +1,5 @@ + diff --git a/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.approved.txt b/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.verified.txt similarity index 96% rename from Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.approved.txt rename to Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.verified.txt index 6e3df79b..72303589 100644 --- a/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.approved.txt +++ b/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.ShouldPassIfGoodParameters.verified.txt @@ -1,16 +1,16 @@ -Diagnostic 1 - Id: Moq1300 - Location: SourceFile(Test0.cs[1376..1391)) - Highlight: BaseSampleClass - Lines: mock.As(); - Severity: Error - Message: Mock.As() should take interfaces only - -Diagnostic 2 - Id: Moq1300 - Location: SourceFile(Test0.cs[1541..1551)) - Highlight: OtherClass - Lines: mock.As(); - Severity: Error - Message: Mock.As() should take interfaces only - +Diagnostic 1 + Id: Moq1300 + Location: SourceFile(Test0.cs[1376..1391)) + Highlight: BaseSampleClass + Lines: mock.As(); + Severity: Error + Message: Mock.As() should take interfaces only + +Diagnostic 2 + Id: Moq1300 + Location: SourceFile(Test0.cs[1541..1551)) + Highlight: OtherClass + Lines: mock.As(); + Severity: Error + Message: Mock.As() should take interfaces only + diff --git a/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.cs b/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.cs index b98ce7ca..25dc13d8 100644 --- a/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/AsAcceptOnlyInterfaceAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class AsAcceptOnlyInterfaceAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldPassIfGoodParameters() + public Task ShouldPassIfGoodParameters() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/AsAcceptOnlyInterface.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/AsAcceptOnlyInterface.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt.bak b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt.bak deleted file mode 100644 index b4544dfe..00000000 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt.bak +++ /dev/null @@ -1,32 +0,0 @@ -Diagnostic 1 - Id: Moq1100 - Location: SourceFile(Test0.cs[695..702)) - Highlight: (int i) - Lines: mock.Setup(x => x.Do(It.IsAny())).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())).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(), It.IsAny(), It.IsAny())).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>())).Callback((int i) => { }); - Severity: Warning - Message: Callback signature must match the signature of the mocked method. - diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt rename to Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.verified.txt index e8b96be5..efc1df11 100644 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.approved.txt +++ b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.ShouldPassIfGoodParameters.verified.txt @@ -1,32 +1,32 @@ -Diagnostic 1 - Id: Moq1100 - Location: SourceFile(Test0.cs[1120..1127)) - Highlight: (int i) - Lines: mock.Setup(x => x.Do(It.IsAny())).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())).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(), It.IsAny(), It.IsAny())).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>())).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())).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())).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(), It.IsAny(), It.IsAny())).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>())).Callback((int i) => { }); + Severity: Warning + Message: Callback signature must match the signature of the mocked method. + diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.cs b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.cs index 8cc82262..e3bcfb8d 100644 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class CallbackSignatureShouldMatchMockedMethodAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldPassIfGoodParameters() + public Task ShouldPassIfGoodParameters() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt.bak b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt.bak deleted file mode 100644 index 609a95e8..00000000 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt.bak +++ /dev/null @@ -1,62 +0,0 @@ -#pragma warning disable SA1402 // File may only contain a single class -#pragma warning disable SA1649 // File name must match first type name -#pragma warning disable SA1502 // Element must not be on a single line -namespace CallbackSignatureShouldMatchMockedMethod -{ - using System; - using System.Collections.Generic; - using Moq; - - internal interface IFoo - { - int Do(string s); - - int Do(int i, string s, DateTime dt); - - int Do(List l); - } - - internal class MyUnitTests - { - private void TestBadCallbacks() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); - } - - private void TestGoodSetupAndParameterlessCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback(() => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback(() => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback(() => { }); - } - - private void TestGoodSetupAndCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); - } - - private void TestGoodSetupAndReturnsAndCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Returns(0).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns(0).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Returns(0).Callback((List l) => { }); - } - - private void MyGoodSetupAndReturns() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Returns((string s) => { return 0; }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns((int i, string s, DateTime dt) => { return 0; }); - mock.Setup(x => x.Do(It.IsAny>())).Returns((List l) => { return 0; }); - } - } -} \ No newline at end of file diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt rename to Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.verified.txt index d5345fff..fc17fa59 100644 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.approved.txt +++ b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.ShouldSuggestQuickFixIfBadParameters.verified.txt @@ -1,69 +1,69 @@ -#pragma warning disable SA1402 // File may only contain a single class -#pragma warning disable SA1502 // Element must not be on a single line -#pragma warning disable SA1602 // Undocumented enum values -#pragma warning disable SA1649 // File name must match first type name -#pragma warning disable RCS1021 // Simplify lambda expression -#pragma warning disable RCS1163 // Unused parameter -#pragma warning disable RCS1213 // Remove unused member declaration -#pragma warning disable IDE0051 // Unused private member -#pragma warning disable IDE0059 // Unnecessary value assignment -#pragma warning disable IDE0060 // Unused parameter -namespace CallbackSignatureShouldMatchMockedMethod -{ - using System; - using System.Collections.Generic; - using Moq; - - internal interface IFoo - { - int Do(string s); - - int Do(int i, string s, DateTime dt); - - int Do(List l); - } - - internal class MyUnitTests - { - private void TestBadCallbacks() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); - } - - private void TestGoodSetupAndParameterlessCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback(() => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback(() => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback(() => { }); - } - - private void TestGoodSetupAndCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); - } - - private void TestGoodSetupAndReturnsAndCallback() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Returns(0).Callback((string s) => { }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns(0).Callback((int i, string s, DateTime dt) => { }); - mock.Setup(x => x.Do(It.IsAny>())).Returns(0).Callback((List l) => { }); - } - - private void MyGoodSetupAndReturns() - { - var mock = new Mock(); - mock.Setup(x => x.Do(It.IsAny())).Returns((string s) => { return 0; }); - mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns((int i, string s, DateTime dt) => { return 0; }); - mock.Setup(x => x.Do(It.IsAny>())).Returns((List l) => { return 0; }); - } - } +#pragma warning disable SA1402 // File may only contain a single class +#pragma warning disable SA1502 // Element must not be on a single line +#pragma warning disable SA1602 // Undocumented enum values +#pragma warning disable SA1649 // File name must match first type name +#pragma warning disable RCS1021 // Simplify lambda expression +#pragma warning disable RCS1163 // Unused parameter +#pragma warning disable RCS1213 // Remove unused member declaration +#pragma warning disable IDE0051 // Unused private member +#pragma warning disable IDE0059 // Unnecessary value assignment +#pragma warning disable IDE0060 // Unused parameter +namespace CallbackSignatureShouldMatchMockedMethod +{ + using System; + using System.Collections.Generic; + using Moq; + + internal interface IFoo + { + int Do(string s); + + int Do(int i, string s, DateTime dt); + + int Do(List l); + } + + internal class MyUnitTests + { + private void TestBadCallbacks() + { + var mock = new Mock(); + mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); + mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); + mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); + mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); + } + + private void TestGoodSetupAndParameterlessCallback() + { + var mock = new Mock(); + mock.Setup(x => x.Do(It.IsAny())).Callback(() => { }); + mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback(() => { }); + mock.Setup(x => x.Do(It.IsAny>())).Callback(() => { }); + } + + private void TestGoodSetupAndCallback() + { + var mock = new Mock(); + mock.Setup(x => x.Do(It.IsAny())).Callback((string s) => { }); + mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Callback((int i, string s, DateTime dt) => { }); + mock.Setup(x => x.Do(It.IsAny>())).Callback((List l) => { }); + } + + private void TestGoodSetupAndReturnsAndCallback() + { + var mock = new Mock(); + mock.Setup(x => x.Do(It.IsAny())).Returns(0).Callback((string s) => { }); + mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns(0).Callback((int i, string s, DateTime dt) => { }); + mock.Setup(x => x.Do(It.IsAny>())).Returns(0).Callback((List l) => { }); + } + + private void MyGoodSetupAndReturns() + { + var mock = new Mock(); + mock.Setup(x => x.Do(It.IsAny())).Returns((string s) => { return 0; }); + mock.Setup(x => x.Do(It.IsAny(), It.IsAny(), It.IsAny())).Returns((int i, string s, DateTime dt) => { return 0; }); + mock.Setup(x => x.Do(It.IsAny>())).Returns((List l) => { return 0; }); + } + } } \ No newline at end of file diff --git a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.cs b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.cs index b7f639e2..7d6a593f 100644 --- a/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.cs +++ b/Source/Moq.Analyzers.Test/CallbackSignatureShouldMatchMockedMethodCodeFixTests.cs @@ -1,20 +1,18 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class CallbackSignatureShouldMatchMockedMethodCodeFixTests : CodeFixVerifier { [Fact] - public void ShouldSuggestQuickFixIfBadParameters() + public Task ShouldSuggestQuickFixIfBadParameters() { - Approvals.Verify(VerifyCSharpFix(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs"))); + return Verify(VerifyCSharpFix(File.ReadAllText("Data/CallbackSignatureShouldMatchMockedMethod.cs"))); } protected override CodeFixProvider GetCSharpCodeFixProvider() diff --git a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt.bak b/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt.bak deleted file mode 100644 index a6f3120b..00000000 --- a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt.bak +++ /dev/null @@ -1,56 +0,0 @@ -Diagnostic 1 - Id: Moq1002 - Location: SourceFile(Test0.cs[910..919)) - Highlight: (1, true) - Lines: var mock1 = new Moq.Mock(1, true); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 2 - Id: Moq1002 - Location: SourceFile(Test0.cs[991..1000)) - Highlight: (2, true) - Lines: var mock2 = new Mock(2, true); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 3 - Id: Moq1002 - Location: SourceFile(Test0.cs[1072..1080)) - Highlight: ("1", 3) - Lines: var mock3 = new Mock("1", 3); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 4 - Id: Moq1002 - Location: SourceFile(Test0.cs[1152..1175)) - Highlight: (new int[] { 1, 2, 3 }) - Lines: var mock4 = new Mock(new int[] { 1, 2, 3 }); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 5 - Id: Moq1002 - Location: SourceFile(Test0.cs[1272..1302)) - Highlight: (MockBehavior.Strict, 4, true) - Lines: var mock1 = new Mock(MockBehavior.Strict, 4, true); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 6 - Id: Moq1002 - Location: SourceFile(Test0.cs[1378..1407)) - Highlight: (MockBehavior.Loose, 5, true) - Lines: var mock2 = new Moq.Mock(MockBehavior.Loose, 5, true); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 7 - Id: Moq1002 - Location: SourceFile(Test0.cs[1483..1511)) - Highlight: (MockBehavior.Loose, "2", 6) - Lines: var mock3 = new Moq.Mock(MockBehavior.Loose, "2", 6); - Severity: Warning - Message: Sealed classes cannot be mocked. - diff --git a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt b/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt rename to Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.verified.txt index 84b2cdc6..24135f67 100644 --- a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.approved.txt +++ b/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.ShouldFailIfClassParametersDoNotMatch.verified.txt @@ -1,56 +1,56 @@ -Diagnostic 1 - Id: Moq1002 - Location: SourceFile(Test0.cs[1359..1368)) - Highlight: (1, true) - Lines: var mock1 = new Moq.Mock(1, true); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 2 - Id: Moq1002 - Location: SourceFile(Test0.cs[1440..1449)) - Highlight: (2, true) - Lines: var mock2 = new Mock(2, true); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 3 - Id: Moq1002 - Location: SourceFile(Test0.cs[1521..1529)) - Highlight: ("1", 3) - Lines: var mock3 = new Mock("1", 3); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 4 - Id: Moq1002 - Location: SourceFile(Test0.cs[1601..1624)) - Highlight: (new int[] { 1, 2, 3 }) - Lines: var mock4 = new Mock(new int[] { 1, 2, 3 }); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 5 - Id: Moq1002 - Location: SourceFile(Test0.cs[1721..1751)) - Highlight: (MockBehavior.Strict, 4, true) - Lines: var mock1 = new Mock(MockBehavior.Strict, 4, true); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 6 - Id: Moq1002 - Location: SourceFile(Test0.cs[1827..1856)) - Highlight: (MockBehavior.Loose, 5, true) - Lines: var mock2 = new Moq.Mock(MockBehavior.Loose, 5, true); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - -Diagnostic 7 - Id: Moq1002 - Location: SourceFile(Test0.cs[1932..1960)) - Highlight: (MockBehavior.Loose, "2", 6) - Lines: var mock3 = new Moq.Mock(MockBehavior.Loose, "2", 6); - Severity: Warning - Message: Parameters provided into mock do not match any existing constructors. - +Diagnostic 1 + Id: Moq1002 + Location: SourceFile(Test0.cs[1359..1368)) + Highlight: (1, true) + Lines: var mock1 = new Moq.Mock(1, true); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 2 + Id: Moq1002 + Location: SourceFile(Test0.cs[1440..1449)) + Highlight: (2, true) + Lines: var mock2 = new Mock(2, true); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 3 + Id: Moq1002 + Location: SourceFile(Test0.cs[1521..1529)) + Highlight: ("1", 3) + Lines: var mock3 = new Mock("1", 3); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 4 + Id: Moq1002 + Location: SourceFile(Test0.cs[1601..1624)) + Highlight: (new int[] { 1, 2, 3 }) + Lines: var mock4 = new Mock(new int[] { 1, 2, 3 }); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 5 + Id: Moq1002 + Location: SourceFile(Test0.cs[1721..1751)) + Highlight: (MockBehavior.Strict, 4, true) + Lines: var mock1 = new Mock(MockBehavior.Strict, 4, true); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 6 + Id: Moq1002 + Location: SourceFile(Test0.cs[1827..1856)) + Highlight: (MockBehavior.Loose, 5, true) + Lines: var mock2 = new Moq.Mock(MockBehavior.Loose, 5, true); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + +Diagnostic 7 + Id: Moq1002 + Location: SourceFile(Test0.cs[1932..1960)) + Highlight: (MockBehavior.Loose, "2", 6) + Lines: var mock3 = new Moq.Mock(MockBehavior.Loose, "2", 6); + Severity: Warning + Message: Parameters provided into mock do not match any existing constructors. + diff --git a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.cs b/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.cs index a47eed64..d4f9c259 100644 --- a/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/ConstructorArgumentsShouldMatchAnalyzerTests.cs @@ -1,26 +1,24 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class ConstructorArgumentsShouldMatchAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldFailIfClassParametersDoNotMatch() + public Task ShouldFailIfClassParametersDoNotMatch() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/ConstructorArgumentsShouldMatch.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/ConstructorArgumentsShouldMatch.cs"))); } - [Fact] - public void ShouldPassIfCustomMockClassIsUsed() - { - // Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/MockInterfaceWithParametersCustomMockFile.cs"))); - } + // [Fact] + // public Task ShouldPassIfCustomMockClassIsUsed() + // { + // return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/MockInterfaceWithParametersCustomMockFile.cs"))); + // } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() { diff --git a/Source/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj b/Source/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj index 8f536c62..2aafec00 100644 --- a/Source/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj +++ b/Source/Moq.Analyzers.Test/Moq.Analyzers.Test.csproj @@ -15,7 +15,6 @@ - @@ -27,8 +26,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt.bak b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt.bak deleted file mode 100644 index 0e439254..00000000 --- a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt.bak +++ /dev/null @@ -1,64 +0,0 @@ -Diagnostic 1 - Id: Moq1001 - Location: SourceFile(Test0.cs[494..504)) - Highlight: (25, true) - Lines: var mock1 = new Moq.Mock(25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 2 - Id: Moq1001 - Location: SourceFile(Test0.cs[551..558)) - Highlight: ("123") - Lines: var mock2 = new Mock("123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 3 - Id: Moq1001 - Location: SourceFile(Test0.cs[646..656)) - Highlight: (25, true) - Lines: var mock3 = new Mock(25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 4 - Id: Moq1001 - Location: SourceFile(Test0.cs[748..755)) - Highlight: ("123") - Lines: var mock4 = new Moq.Mock("123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 5 - Id: Moq1001 - Location: SourceFile(Test0.cs[863..896)) - Highlight: (Moq.MockBehavior.Default, "123") - Lines: var mock1 = new Moq.Mock(Moq.MockBehavior.Default, "123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 6 - Id: Moq1001 - Location: SourceFile(Test0.cs[943..974)) - Highlight: (MockBehavior.Strict, 25, true) - Lines: var mock2 = new Mock(MockBehavior.Strict, 25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 7 - Id: Moq1001 - Location: SourceFile(Test0.cs[1062..1095)) - Highlight: (Moq.MockBehavior.Default, "123") - Lines: var mock3 = new Mock(Moq.MockBehavior.Default, "123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 8 - Id: Moq1001 - Location: SourceFile(Test0.cs[1187..1217)) - Highlight: (MockBehavior.Loose, 25, true) - Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - diff --git a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt rename to Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.verified.txt index 51be9655..121043ab 100644 --- a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.approved.txt +++ b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldFailIfMockedInterfaceHasParameters.verified.txt @@ -1,64 +1,64 @@ -Diagnostic 1 - Id: Moq1001 - Location: SourceFile(Test0.cs[856..866)) - Highlight: (25, true) - Lines: var mock1 = new Moq.Mock(25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 2 - Id: Moq1001 - Location: SourceFile(Test0.cs[913..920)) - Highlight: ("123") - Lines: var mock2 = new Mock("123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 3 - Id: Moq1001 - Location: SourceFile(Test0.cs[1008..1018)) - Highlight: (25, true) - Lines: var mock3 = new Mock(25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 4 - Id: Moq1001 - Location: SourceFile(Test0.cs[1110..1117)) - Highlight: ("123") - Lines: var mock4 = new Moq.Mock("123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 5 - Id: Moq1001 - Location: SourceFile(Test0.cs[1225..1258)) - Highlight: (Moq.MockBehavior.Default, "123") - Lines: var mock1 = new Moq.Mock(Moq.MockBehavior.Default, "123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 6 - Id: Moq1001 - Location: SourceFile(Test0.cs[1305..1336)) - Highlight: (MockBehavior.Strict, 25, true) - Lines: var mock2 = new Mock(MockBehavior.Strict, 25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 7 - Id: Moq1001 - Location: SourceFile(Test0.cs[1424..1457)) - Highlight: (Moq.MockBehavior.Default, "123") - Lines: var mock3 = new Mock(Moq.MockBehavior.Default, "123"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 8 - Id: Moq1001 - Location: SourceFile(Test0.cs[1549..1579)) - Highlight: (MockBehavior.Loose, 25, true) - Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 25, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - +Diagnostic 1 + Id: Moq1001 + Location: SourceFile(Test0.cs[856..866)) + Highlight: (25, true) + Lines: var mock1 = new Moq.Mock(25, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 2 + Id: Moq1001 + Location: SourceFile(Test0.cs[913..920)) + Highlight: ("123") + Lines: var mock2 = new Mock("123"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 3 + Id: Moq1001 + Location: SourceFile(Test0.cs[1008..1018)) + Highlight: (25, true) + Lines: var mock3 = new Mock(25, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 4 + Id: Moq1001 + Location: SourceFile(Test0.cs[1110..1117)) + Highlight: ("123") + Lines: var mock4 = new Moq.Mock("123"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 5 + Id: Moq1001 + Location: SourceFile(Test0.cs[1225..1258)) + Highlight: (Moq.MockBehavior.Default, "123") + Lines: var mock1 = new Moq.Mock(Moq.MockBehavior.Default, "123"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 6 + Id: Moq1001 + Location: SourceFile(Test0.cs[1305..1336)) + Highlight: (MockBehavior.Strict, 25, true) + Lines: var mock2 = new Mock(MockBehavior.Strict, 25, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 7 + Id: Moq1001 + Location: SourceFile(Test0.cs[1424..1457)) + Highlight: (Moq.MockBehavior.Default, "123") + Lines: var mock3 = new Mock(Moq.MockBehavior.Default, "123"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 8 + Id: Moq1001 + Location: SourceFile(Test0.cs[1549..1579)) + Highlight: (MockBehavior.Loose, 25, true) + Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 25, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + diff --git a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt.bak b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt.bak deleted file mode 100644 index 59ab6a15..00000000 --- a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt.bak +++ /dev/null @@ -1,48 +0,0 @@ -Diagnostic 1 - Id: Moq1001 - Location: SourceFile(Test0.cs[856..865)) - Highlight: (1, true) - Lines: var mock1 = new Moq.Mock(1, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 2 - Id: Moq1001 - Location: SourceFile(Test0.cs[957..962)) - Highlight: ("2") - Lines: var mock2 = new Moq.Mock("2"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 3 - Id: Moq1001 - Location: SourceFile(Test0.cs[1013..1044)) - Highlight: (Moq.MockBehavior.Default, "3") - Lines: var mock3 = new Moq.Mock(Moq.MockBehavior.Default, "3"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 4 - Id: Moq1001 - Location: SourceFile(Test0.cs[1136..1165)) - Highlight: (MockBehavior.Loose, 4, true) - Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 4, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 5 - Id: Moq1001 - Location: SourceFile(Test0.cs[1216..1238)) - Highlight: (MockBehavior.Default) - Lines: var mock5 = new Moq.Mock(MockBehavior.Default); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 6 - Id: Moq1001 - Location: SourceFile(Test0.cs[1330..1352)) - Highlight: (MockBehavior.Default) - Lines: var mock6 = new Moq.Mock(MockBehavior.Default); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - diff --git a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt rename to Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.verified.txt index dd60d5c1..d48a0c3b 100644 --- a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.approved.txt +++ b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.ShouldPassIfCustomMockClassIsUsed.verified.txt @@ -1,48 +1,48 @@ -Diagnostic 1 - Id: Moq1001 - Location: SourceFile(Test0.cs[1219..1228)) - Highlight: (1, true) - Lines: var mock1 = new Moq.Mock(1, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 2 - Id: Moq1001 - Location: SourceFile(Test0.cs[1320..1325)) - Highlight: ("2") - Lines: var mock2 = new Moq.Mock("2"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 3 - Id: Moq1001 - Location: SourceFile(Test0.cs[1376..1407)) - Highlight: (Moq.MockBehavior.Default, "3") - Lines: var mock3 = new Moq.Mock(Moq.MockBehavior.Default, "3"); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 4 - Id: Moq1001 - Location: SourceFile(Test0.cs[1499..1528)) - Highlight: (MockBehavior.Loose, 4, true) - Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 4, true); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 5 - Id: Moq1001 - Location: SourceFile(Test0.cs[1579..1601)) - Highlight: (MockBehavior.Default) - Lines: var mock5 = new Moq.Mock(MockBehavior.Default); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - -Diagnostic 6 - Id: Moq1001 - Location: SourceFile(Test0.cs[1693..1715)) - Highlight: (MockBehavior.Default) - Lines: var mock6 = new Moq.Mock(MockBehavior.Default); - Severity: Warning - Message: Mocked interfaces cannot have constructor parameters. - +Diagnostic 1 + Id: Moq1001 + Location: SourceFile(Test0.cs[1219..1228)) + Highlight: (1, true) + Lines: var mock1 = new Moq.Mock(1, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 2 + Id: Moq1001 + Location: SourceFile(Test0.cs[1320..1325)) + Highlight: ("2") + Lines: var mock2 = new Moq.Mock("2"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 3 + Id: Moq1001 + Location: SourceFile(Test0.cs[1376..1407)) + Highlight: (Moq.MockBehavior.Default, "3") + Lines: var mock3 = new Moq.Mock(Moq.MockBehavior.Default, "3"); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 4 + Id: Moq1001 + Location: SourceFile(Test0.cs[1499..1528)) + Highlight: (MockBehavior.Loose, 4, true) + Lines: var mock4 = new Moq.Mock(MockBehavior.Loose, 4, true); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 5 + Id: Moq1001 + Location: SourceFile(Test0.cs[1579..1601)) + Highlight: (MockBehavior.Default) + Lines: var mock5 = new Moq.Mock(MockBehavior.Default); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + +Diagnostic 6 + Id: Moq1001 + Location: SourceFile(Test0.cs[1693..1715)) + Highlight: (MockBehavior.Default) + Lines: var mock6 = new Moq.Mock(MockBehavior.Default); + Severity: Warning + Message: Mocked interfaces cannot have constructor parameters. + diff --git a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.cs b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.cs index c6155ddb..03cddc0c 100644 --- a/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/NoConstructorArgumentsForInterfaceMockAnalyzerTests.cs @@ -1,25 +1,23 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class NoConstructorArgumentsForInterfaceMockAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldFailIfMockedInterfaceHasParameters() + public Task ShouldFailIfMockedInterfaceHasParameters() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoConstructorArgumentsForInterfaceMock_1.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoConstructorArgumentsForInterfaceMock_1.cs"))); } [Fact] - public void ShouldPassIfCustomMockClassIsUsed() + public Task ShouldPassIfCustomMockClassIsUsed() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoConstructorArgumentsForInterfaceMock_2.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoConstructorArgumentsForInterfaceMock_2.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt.bak b/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt.bak deleted file mode 100644 index 8f799ae6..00000000 --- a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt.bak +++ /dev/null @@ -1,16 +0,0 @@ -Diagnostic 1 - Id: Moq1101 - Location: SourceFile(Test0.cs[595..605)) - Highlight: x.Method() - Lines: mock.SetupGet(x => x.Method()); - Severity: Warning - Message: SetupGet/SetupSet should be used for properties, not for methods. - -Diagnostic 2 - Id: Moq1101 - Location: SourceFile(Test0.cs[640..650)) - Highlight: x.Method() - Lines: mock.SetupSet(x => x.Method()); - Severity: Warning - Message: SetupGet/SetupSet should be used for properties, not for methods. - diff --git a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt b/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.verified.txt similarity index 96% rename from Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt rename to Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.verified.txt index 72da9ee3..85a9ede5 100644 --- a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.approved.txt +++ b/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.Test.verified.txt @@ -1,16 +1,16 @@ -Diagnostic 1 - Id: Moq1101 - Location: SourceFile(Test0.cs[957..967)) - Highlight: x.Method() - Lines: mock.SetupGet(x => x.Method()); - Severity: Warning - Message: SetupGet/SetupSet should be used for properties, not for methods. - -Diagnostic 2 - Id: Moq1101 - Location: SourceFile(Test0.cs[1002..1012)) - Highlight: x.Method() - Lines: mock.SetupSet(x => x.Method()); - Severity: Warning - Message: SetupGet/SetupSet should be used for properties, not for methods. - +Diagnostic 1 + Id: Moq1101 + Location: SourceFile(Test0.cs[957..967)) + Highlight: x.Method() + Lines: mock.SetupGet(x => x.Method()); + Severity: Warning + Message: SetupGet/SetupSet should be used for properties, not for methods. + +Diagnostic 2 + Id: Moq1101 + Location: SourceFile(Test0.cs[1002..1012)) + Highlight: x.Method() + Lines: mock.SetupSet(x => x.Method()); + Severity: Warning + Message: SetupGet/SetupSet should be used for properties, not for methods. + diff --git a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.cs b/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.cs index 16ff68dd..c908bcd7 100644 --- a/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/NoMethodsInPropertySetupAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class NoMethodsInPropertySetupAnalyzerTests : DiagnosticVerifier { [Fact] - public void Test() + public Task Test() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoMethodsInPropertySetup.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoMethodsInPropertySetup.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt.bak b/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt.bak deleted file mode 100644 index 28bff2e4..00000000 --- a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt.bak +++ /dev/null @@ -1,32 +0,0 @@ -Diagnostic 1 - Id: Moq1000 - Location: SourceFile(Test0.cs[494..503)) - Highlight: FooSealed - Lines: var mock1 = new Moq.Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 2 - Id: Moq1000 - Location: SourceFile(Test0.cs[542..551)) - Highlight: FooSealed - Lines: var mock2 = new Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 3 - Id: Moq1000 - Location: SourceFile(Test0.cs[590..618)) - Highlight: NoSealedClassMocks.FooSealed - Lines: var mock3 = new Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 4 - Id: Moq1000 - Location: SourceFile(Test0.cs[661..689)) - Highlight: NoSealedClassMocks.FooSealed - Lines: var mock4 = new Moq.Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - diff --git a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt b/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.verified.txt similarity index 96% rename from Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt rename to Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.verified.txt index 96751f56..f2677d87 100644 --- a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.approved.txt +++ b/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.ShouldFailIfFileIsSealed.verified.txt @@ -1,32 +1,32 @@ -Diagnostic 1 - Id: Moq1000 - Location: SourceFile(Test0.cs[852..861)) - Highlight: FooSealed - Lines: var mock1 = new Moq.Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 2 - Id: Moq1000 - Location: SourceFile(Test0.cs[900..909)) - Highlight: FooSealed - Lines: var mock2 = new Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 3 - Id: Moq1000 - Location: SourceFile(Test0.cs[948..976)) - Highlight: NoSealedClassMocks.FooSealed - Lines: var mock3 = new Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - -Diagnostic 4 - Id: Moq1000 - Location: SourceFile(Test0.cs[1019..1047)) - Highlight: NoSealedClassMocks.FooSealed - Lines: var mock4 = new Moq.Mock(); - Severity: Warning - Message: Sealed classes cannot be mocked. - +Diagnostic 1 + Id: Moq1000 + Location: SourceFile(Test0.cs[852..861)) + Highlight: FooSealed + Lines: var mock1 = new Moq.Mock(); + Severity: Warning + Message: Sealed classes cannot be mocked. + +Diagnostic 2 + Id: Moq1000 + Location: SourceFile(Test0.cs[900..909)) + Highlight: FooSealed + Lines: var mock2 = new Mock(); + Severity: Warning + Message: Sealed classes cannot be mocked. + +Diagnostic 3 + Id: Moq1000 + Location: SourceFile(Test0.cs[948..976)) + Highlight: NoSealedClassMocks.FooSealed + Lines: var mock3 = new Mock(); + Severity: Warning + Message: Sealed classes cannot be mocked. + +Diagnostic 4 + Id: Moq1000 + Location: SourceFile(Test0.cs[1019..1047)) + Highlight: NoSealedClassMocks.FooSealed + Lines: var mock4 = new Moq.Mock(); + Severity: Warning + Message: Sealed classes cannot be mocked. + diff --git a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.cs b/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.cs index 852010bc..e18ea233 100644 --- a/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/NoSealedClassMocksAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class NoSealedClassMocksAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldFailIfFileIsSealed() + public Task ShouldFailIfFileIsSealed() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoSealedClassMocks.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/NoSealedClassMocks.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.approved.txt b/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.verified.txt similarity index 96% rename from Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.approved.txt rename to Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.verified.txt index f13fbfe9..9dc3085b 100644 --- a/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.approved.txt +++ b/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.ShouldPassIfGoodParameters.verified.txt @@ -1,24 +1,24 @@ -Diagnostic 1 - Id: Moq1200 - Location: SourceFile(Test0.cs[2075..2088)) - Highlight: x.Calculate() - Lines: mock.Setup(x => x.Calculate()); - Severity: Error - Message: Setup should be used only for overridable members. - -Diagnostic 2 - Id: Moq1200 - Location: SourceFile(Test0.cs[2241..2303)) - Highlight: x.Calculate(It.IsAny(), It.IsAny(), It.IsAny()) - Lines: mock.Setup(x => x.Calculate(It.IsAny(), It.IsAny(), It.IsAny())); - Severity: Error - Message: Setup should be used only for overridable members. - -Diagnostic 3 - Id: Moq1200 - Location: SourceFile(Test0.cs[2462..2472)) - Highlight: x.Property - Lines: mock.Setup(x => x.Property); - Severity: Error - Message: Setup should be used only for overridable members. - +Diagnostic 1 + Id: Moq1200 + Location: SourceFile(Test0.cs[2075..2088)) + Highlight: x.Calculate() + Lines: mock.Setup(x => x.Calculate()); + Severity: Error + Message: Setup should be used only for overridable members. + +Diagnostic 2 + Id: Moq1200 + Location: SourceFile(Test0.cs[2241..2303)) + Highlight: x.Calculate(It.IsAny(), It.IsAny(), It.IsAny()) + Lines: mock.Setup(x => x.Calculate(It.IsAny(), It.IsAny(), It.IsAny())); + Severity: Error + Message: Setup should be used only for overridable members. + +Diagnostic 3 + Id: Moq1200 + Location: SourceFile(Test0.cs[2462..2472)) + Highlight: x.Property + Lines: mock.Setup(x => x.Property); + Severity: Error + Message: Setup should be used only for overridable members. + diff --git a/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.cs b/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.cs index 6e3daaa6..a03a9e19 100644 --- a/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class SetupShouldBeUsedOnlyForOverridableMembersAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldPassIfGoodParameters() + public Task ShouldPassIfGoodParameters() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupOnlyForOverridableMembers.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupOnlyForOverridableMembers.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.approved.txt b/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.verified.txt similarity index 97% rename from Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.approved.txt rename to Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.verified.txt index 3e09ac0b..8b7fa6a5 100644 --- a/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.approved.txt +++ b/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.ShouldPassIfSetupProperly.verified.txt @@ -1,8 +1,8 @@ -Diagnostic 1 - Id: Moq1201 - Location: SourceFile(Test0.cs[871..912)) - Highlight: c.GenericAsyncWithConcreteReturn().Result - Lines: mock.Setup(c => c.GenericAsyncWithConcreteReturn().Result); - Severity: Error - Message: Setup of async methods should use ReturnsAsync instead of .Result - +Diagnostic 1 + Id: Moq1201 + Location: SourceFile(Test0.cs[871..912)) + Highlight: c.GenericAsyncWithConcreteReturn().Result + Lines: mock.Setup(c => c.GenericAsyncWithConcreteReturn().Result); + Severity: Error + Message: Setup of async methods should use ReturnsAsync instead of .Result + diff --git a/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.cs b/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.cs index a04b3c51..b378bd1d 100644 --- a/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.cs +++ b/Source/Moq.Analyzers.Test/SetupShouldNotIncludeAsyncResultAnalyzerTests.cs @@ -1,19 +1,17 @@ namespace Moq.Analyzers.Test { using System.IO; - using ApprovalTests; - using ApprovalTests.Reporters; + using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using TestHelper; using Xunit; - [UseReporter(typeof(DiffReporter))] public class SetupShouldNotIncludeAsyncResultAnalyzerTests : DiagnosticVerifier { [Fact] - public void ShouldPassIfSetupProperly() + public Task ShouldPassIfSetupProperly() { - Approvals.Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupShouldNotIncludeAsyncResult.cs"))); + return Verify(VerifyCSharpDiagnostic(File.ReadAllText("Data/SetupShouldNotIncludeAsyncResult.cs"))); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/build/targets/compiler/Compiler.props b/build/targets/compiler/Compiler.props new file mode 100644 index 00000000..2cab0aac --- /dev/null +++ b/build/targets/compiler/Compiler.props @@ -0,0 +1,7 @@ + + + enable + 12.0 + enable + + diff --git a/build/targets/compiler/Compiler.targets b/build/targets/compiler/Compiler.targets new file mode 100644 index 00000000..8c119d54 --- /dev/null +++ b/build/targets/compiler/Compiler.targets @@ -0,0 +1,2 @@ + +