From 4f368c10ec956243cdeb7f4fe66d82e581c7bd32 Mon Sep 17 00:00:00 2001 From: medmondson Date: Sun, 29 Jan 2017 17:37:54 +0000 Subject: [PATCH] Added missing tests --- .../UnusedReturnValueAnalyzerTests.cs | 183 +++++++++++++++++ .../UnusedReturnValueAnalyzerTests.cs | 184 ++++++++++++++++++ 2 files changed, 367 insertions(+) diff --git a/tests/FakeItEasy.Analyzer.CSharp.Tests/UnusedReturnValueAnalyzerTests.cs b/tests/FakeItEasy.Analyzer.CSharp.Tests/UnusedReturnValueAnalyzerTests.cs index f630ac9bb..9d77f4115 100644 --- a/tests/FakeItEasy.Analyzer.CSharp.Tests/UnusedReturnValueAnalyzerTests.cs +++ b/tests/FakeItEasy.Analyzer.CSharp.Tests/UnusedReturnValueAnalyzerTests.cs @@ -192,6 +192,66 @@ interface IFoo { int Bar(); } }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallsTo() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var fake = new Fake(); + fake.CallsTo(x => x.Bar()); + } + } + interface IFoo { int Bar(); } +}"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.CallsTo(x => x.Bar())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_AnyCall() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var fake = new Fake(); + fake.AnyCall(); + } + } + interface IFoo { int Bar(); } +}"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.AnyCall()'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WithAnyArguments() @@ -223,6 +283,37 @@ interface IFoo { int Bar(); } }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WithReturnType_With_No_Return_Specified() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var foo = A.Fake(); + A.CallTo(foo).WithReturnType(); + } + } + interface IFoo { int Bar(); } +} +"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(foo).WithReturnType()'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_Where() @@ -254,6 +345,67 @@ interface IFoo { int Bar(); } }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_Where_With_No_Return_Type() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var fake = A.Fake(); + A.CallTo(fake).Where(call => true, output => new object()); + } + } + interface IFoo { int Bar(); } +} +"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(fake).Where(call => true, output => new object())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WhenArgumentsMatch_With_No_Return_Specified() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var foo = A.Fake(); + A.CallTo(foo).WhenArgumentsMatch(x => true); + } + } + interface IFoo { int Bar(); } +}"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(foo).WhenArgumentsMatch(x => true)'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallToSet() @@ -286,6 +438,37 @@ interface IFoo { int Bar { get; set; } } }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallsToSet() + { + var test = @"using FakeItEasy; +namespace TheNamespace +{ + class TheClass + { + void Test() + { + var fake = new Fake(); + fake.CallsToSet(x => x.Bar()); + } + } + interface IFoo { int Bar(); } +} +"; + + this.VerifyCSharpDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.CallsToSet(x => x.Bar())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallToSet_To_Value() diff --git a/tests/FakeItEasy.Analyzer.VisualBasic.Tests/UnusedReturnValueAnalyzerTests.cs b/tests/FakeItEasy.Analyzer.VisualBasic.Tests/UnusedReturnValueAnalyzerTests.cs index 0c1ed08ab..79ee7cddd 100644 --- a/tests/FakeItEasy.Analyzer.VisualBasic.Tests/UnusedReturnValueAnalyzerTests.cs +++ b/tests/FakeItEasy.Analyzer.VisualBasic.Tests/UnusedReturnValueAnalyzerTests.cs @@ -186,6 +186,68 @@ End Namespace }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallsTo() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim fake = New Fake(Of IFoo)() + fake.CallsTo(Function(x) x.Bar()) + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.CallsTo(Function(x) x.Bar())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_AnyCall() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim fake = New Fake(Of IFoo)() + fake.AnyCall() + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.AnyCall()'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WithAnyArguments() @@ -217,6 +279,37 @@ End Namespace }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WithReturnType_With_No_Return_Specified() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim foo = New Fake(Of IFoo)() + A.CallTo(foo).WithReturnType(Of Integer)() + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(foo).WithReturnType(Of Integer)()'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_Where() @@ -248,6 +341,66 @@ End Namespace }); } + [Fact] + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_Where_With_No_Return_Type() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim foo = New Fake(Of IFoo)() + A.CallTo(foo).Where(Function() True, New Object()) + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(foo).Where(Function() True, New Object())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + + [Fact] + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_WhenArgumentsMatch_With_No_Return_Specified() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim foo = New Fake(Of IFoo)() + A.CallTo(foo).WhenArgumentsMatch(Function(x) True) + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'A.CallTo(foo).WhenArgumentsMatch(Function(x) True)'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallToSet() @@ -279,6 +432,37 @@ End Namespace }); } + [Fact] + [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language + public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallsToSet() + { + var test = @"Imports FakeItEasy +Namespace TheNamespace + Class TheClass + Sub Test() + Dim fake = New Fake(Of IFoo)() + fake.CallsToSet(Function(x) x.Bar()) + End Sub + End Class + + Interface IFoo + Function Bar() As Integer + End Interface +End Namespace +"; + + this.VerifyVisualBasicDiagnostic( + test, + new DiagnosticResult + { + Id = DiagnosticDefinitions.UnusedCallSpecification.Id, + Message = + "Unused call specification 'fake.CallsToSet(Function(x) x.Bar())'; did you forget to configure or assert the call?", + Severity = DiagnosticSeverity.Error, + Locations = new[] { new DiagnosticResultLocation("Test0.vb", 6, 13) } + }); + } + [Fact] [UsingCulture("en-US")] // so that the message is in the expected language regardless of the OS language public void Diagnostic_Should_Have_The_Correct_Call_Description_If_Triggered_On_CallToSet_To_Value()