-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
RubberduckTests/Inspections/WriteOnlyPropertyInspectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.Vbe.Interop; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Rubberduck.Inspections; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.Parsing.VBA; | ||
using Rubberduck.VBEditor.VBEHost; | ||
using RubberduckTests.Mocks; | ||
|
||
namespace RubberduckTests.Inspections | ||
{ | ||
[TestClass] | ||
public class WriteOnlyPropertyInspectionTests | ||
{ | ||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void WriteOnlyProperty_ReturnsResult_Let() | ||
{ | ||
const string inputCode = | ||
@"Property Let Foo(value) | ||
End Property"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new WriteOnlyPropertyInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void WriteOnlyProperty_ReturnsResult_Set() | ||
{ | ||
const string inputCode = | ||
@"Property Set Foo(value) | ||
End Property"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new WriteOnlyPropertyInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.AreEqual(1, inspectionResults.Count()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void WriteOnlyProperty_ReturnsResult_LetAndSet() | ||
{ | ||
const string inputCode = | ||
@"Property Let Foo(value) | ||
End Property | ||
Property Set Foo(value) | ||
End Property"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new WriteOnlyPropertyInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.AreEqual(2, inspectionResults.Count()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void WriteOnlyProperty_DoesNotReturnsResult_Get() | ||
{ | ||
const string inputCode = | ||
@"Property Get Foo() | ||
End Property"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new WriteOnlyPropertyInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.IsFalse(inspectionResults.Any()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void WriteOnlyProperty_DoesNotReturnsResult_GetAndLetAndSet() | ||
{ | ||
const string inputCode = | ||
@"Property Get Foo() | ||
End Property | ||
Property Let Foo(value) | ||
End Property | ||
Property Set Foo(value) | ||
End Property"; | ||
|
||
//Arrange | ||
var builder = new MockVbeBuilder(); | ||
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none) | ||
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode) | ||
.Build(); | ||
var vbe = builder.AddProject(project).Build(); | ||
|
||
var mockHost = new Mock<IHostApplication>(); | ||
mockHost.SetupAllProperties(); | ||
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object)); | ||
|
||
parser.Parse(new CancellationTokenSource()); | ||
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); } | ||
|
||
var inspection = new WriteOnlyPropertyInspection(parser.State); | ||
var inspectionResults = inspection.GetInspectionResults(); | ||
|
||
Assert.IsFalse(inspectionResults.Any()); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void InspectionType() | ||
{ | ||
var inspection = new WriteOnlyPropertyInspection(null); | ||
Assert.AreEqual(CodeInspectionType.CodeQualityIssues, inspection.InspectionType); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("Inspections")] | ||
public void InspectionName() | ||
{ | ||
const string inspectionName = "WriteOnlyPropertyInspection"; | ||
var inspection = new WriteOnlyPropertyInspection(null); | ||
|
||
Assert.AreEqual(inspectionName, inspection.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters