Skip to content

Commit

Permalink
Modified to use InspectionTestsBase
Browse files Browse the repository at this point in the history
  • Loading branch information
BZngr committed Oct 13, 2019
1 parent 88a7b8f commit 64ef965
Showing 1 changed file with 18 additions and 145 deletions.
163 changes: 18 additions & 145 deletions RubberduckTests/Inspections/HungarianNotationInspectionTests.cs
Expand Up @@ -2,13 +2,15 @@
using System.Threading;
using NUnit.Framework;
using Rubberduck.Inspections.Concrete;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor.SafeComWrappers;
using RubberduckTests.Mocks;

namespace RubberduckTests.Inspections
{
[TestFixture]
public class HungarianNotationInspectionTests
public class HungarianNotationInspectionTests : InspectionTestsBase
{
[Test]
[Category("Inspections")]
Expand All @@ -19,19 +21,7 @@ public void HungarianNotation_ReturnsResult_VariableWithThreeLetterPrefix()
Dim strFoo As String
End Sub";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(1, inspectionResults.Count());
}
Assert.AreEqual(1, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -42,20 +32,7 @@ public void HungarianNotation_ReturnsResult_VariableWithOneLetterPrefix()
@"Sub Hungarian()
Dim oFoo As Object
End Sub";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(1, inspectionResults.Count());
}
Assert.AreEqual(1, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -66,20 +43,12 @@ public void HungarianNotation_ReturnsResult_ForClass()
@"Sub Test()
Debug.Print ""Ez egy objektum""
End Sub";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("clsMagyar", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(1, inspectionResults.Count());
}
Assert.AreEqual(1, InspectionResults(vbe.Object).Count());
}

[Test]
Expand All @@ -90,20 +59,7 @@ public void HungarianNotation_DoesNotReturnsResult_AllLowerCase()
@"Sub NoHungarianHere()
Dim strong As Variant
End Sub";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.IsFalse(inspectionResults.Any());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -112,20 +68,7 @@ public void HungarianNotation_DoesNotReturnsResult_UpperCaseFirstLetter()
{
const string inputCode =
@"Option Explicit";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("Stripper", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.IsFalse(inspectionResults.Any());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -136,19 +79,7 @@ public void HungarianNotation_DoesNotReturnsResult_ThreeLetterVariable()
@"Sub InExcelSomewhere()
Dim col As Long
End Sub";
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.IsFalse(inspectionResults.Any());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -160,19 +91,7 @@ public void HungarianNotation_DoesNotReturnResult_WhenIgnored()
'@Ignore HungarianNotation
Dim strFoo As Variant
End Sub";
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new UseMeaningfulNameInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.IsFalse(inspectionResults.Any());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -183,19 +102,7 @@ public void HungarianNotation_DoesNotReturnResult_WhenWhitelisted()
@"Sub Feherlista()
Dim oRange As Object
End Sub";
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new UseMeaningfulNameInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.IsFalse(inspectionResults.Any());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -207,20 +114,7 @@ public void HungarianNotation_DoesNotReturnResult_Ignored()
'@Ignore HungarianNotation
Dim oFoo As Object
End Sub";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(0, inspectionResults.Count());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -231,20 +125,7 @@ public void HungarianNotation_DoesNotReturnResult_LibraryFunctionParameters()
@"
Private Declare Function GetUserName Lib ""advapi32.dll"" Alias ""GetUserNameA"" (ByVal lpBuffer As String, nSize As Long) As Long
";

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(0, inspectionResults.Count());
}
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

[Test]
Expand All @@ -255,20 +136,12 @@ public void HungarianNotation_DoesNotReturnResult_LibraryFunction()
@"
Private Declare Sub chkVoid Lib ""somelib.dll"" Alias ""chkVoidA"" (number As Long)
";
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
}

var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();

using (var state = MockParser.CreateAndParse(vbe.Object))
{
var inspection = new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);

Assert.AreEqual(0, inspectionResults.Count());
}
protected override IInspection InspectionUnderTest(RubberduckParserState state)
{
return new HungarianNotationInspection(state, UseMeaningfulNameInspectionTests.GetInspectionSettings().Object);
}
}
}

0 comments on commit 64ef965

Please sign in to comment.