Skip to content

Commit a3a642c

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into MiscBugFixes2
2 parents 137d68a + f202cad commit a3a642c

27 files changed

+436
-1771
lines changed

Rubberduck.Core/UI/Converters/ImageSourceConverter.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ public abstract class ImageSourceConverter : IValueConverter
1212
{
1313
protected static ImageSource ToImageSource(Image source)
1414
{
15-
using (var ms = new MemoryStream())
16-
{
17-
((Bitmap) source).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
18-
var image = new BitmapImage();
19-
image.BeginInit();
20-
image.CacheOption = BitmapCacheOption.OnLoad;
21-
ms.Seek(0, SeekOrigin.Begin);
22-
image.StreamSource = ms;
23-
image.EndInit();
24-
image.Freeze();
15+
var ms = new MemoryStream();
2516

26-
return image;
27-
}
17+
((Bitmap)source).Save(ms, System.Drawing.Imaging.ImageFormat.Png);
18+
var image = new BitmapImage();
19+
image.BeginInit();
20+
ms.Seek(0, SeekOrigin.Begin);
21+
image.StreamSource = ms;
22+
image.EndInit();
23+
image.Freeze();
24+
25+
return image;
2826
}
2927

3028
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
using System.Collections.Generic;
12
using System.Linq;
23
using System.Threading;
34
using NUnit.Framework;
45
using Rubberduck.Inspections.Concrete;
6+
using Rubberduck.Parsing.Inspections.Abstract;
57
using Rubberduck.Parsing.VBA;
68
using Rubberduck.VBEditor.SafeComWrappers;
79
using RubberduckTests.Mocks;
810

911
namespace RubberduckTests.Inspections
1012
{
1113
[TestFixture]
12-
public class ApplicationWorksheetFunctionInspectionTests
14+
public class ApplicationWorksheetFunctionInspectionTests : InspectionTestsBase
1315
{
14-
private static RubberduckParserState ArrangeParserAndParse(string inputCode)
16+
private IEnumerable<IInspectionResult> GetInspectionResultsUsingExcelLibrary(string inputCode)
1517
{
1618
var builder = new MockVbeBuilder();
1719
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
1820
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
1921
.AddReference("Excel", MockVbeBuilder.LibraryPathMsExcel, 1, 8, true)
2022
.Build();
2123

22-
var vbe = builder.AddProject(project).Build();
23-
24-
return MockParser.CreateAndParse(vbe.Object); ;
24+
var vbe = builder.AddProject(project).Build().Object;
25+
return InspectionResults(vbe);
2526
}
2627

2728
[Test]
@@ -34,15 +35,7 @@ Dim foo As Double
3435
foo = Application.Pi
3536
End Sub
3637
";
37-
38-
using (var state = ArrangeParserAndParse(inputCode))
39-
{
40-
41-
var inspection = new ApplicationWorksheetFunctionInspection(state);
42-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
43-
44-
Assert.AreEqual(1, inspectionResults.Count());
45-
}
38+
Assert.AreEqual(1, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
4639
}
4740

4841
[Test]
@@ -57,15 +50,7 @@ With Application
5750
End With
5851
End Sub
5952
";
60-
61-
using (var state = ArrangeParserAndParse(inputCode))
62-
{
63-
64-
var inspection = new ApplicationWorksheetFunctionInspection(state);
65-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
66-
67-
Assert.AreEqual(1, inspectionResults.Count());
68-
}
53+
Assert.AreEqual(1, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
6954
}
7055

7156
[Test]
@@ -80,15 +65,7 @@ Dim xlApp as Excel.Application
8065
foo = xlApp.Pi
8166
End Sub
8267
";
83-
84-
using (var state = ArrangeParserAndParse(inputCode))
85-
{
86-
87-
var inspection = new ApplicationWorksheetFunctionInspection(state);
88-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
89-
90-
Assert.AreEqual(1, inspectionResults.Count());
91-
}
68+
Assert.AreEqual(1, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
9269
}
9370

9471
[Test]
@@ -105,15 +82,7 @@ With xlApp
10582
End With
10683
End Sub
10784
";
108-
109-
using (var state = ArrangeParserAndParse(inputCode))
110-
{
111-
112-
var inspection = new ApplicationWorksheetFunctionInspection(state);
113-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
114-
115-
Assert.AreEqual(1, inspectionResults.Count());
116-
}
85+
Assert.AreEqual(1, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
11786
}
11887

11988
[Test]
@@ -126,15 +95,7 @@ Dim foo As Double
12695
foo = Application.WorksheetFunction.Pi
12796
End Sub
12897
";
129-
130-
using (var state = ArrangeParserAndParse(inputCode))
131-
{
132-
133-
var inspection = new ApplicationWorksheetFunctionInspection(state);
134-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
135-
136-
Assert.IsFalse(inspectionResults.Any());
137-
}
98+
Assert.AreEqual(0, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
13899
}
139100

140101
[Test]
@@ -149,15 +110,7 @@ Dim xlApp as Excel.Application
149110
foo = xlApp.WorksheetFunction.Pi
150111
End Sub
151112
";
152-
153-
using (var state = ArrangeParserAndParse(inputCode))
154-
{
155-
156-
var inspection = new ApplicationWorksheetFunctionInspection(state);
157-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
158-
159-
Assert.IsFalse(inspectionResults.Any());
160-
}
113+
Assert.AreEqual(0, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
161114
}
162115

163116
[Test]
@@ -170,25 +123,7 @@ Dim foo As Double
170123
foo = Application.Pi
171124
End Sub
172125
";
173-
var builder = new MockVbeBuilder();
174-
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
175-
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
176-
.Build();
177-
178-
var vbe = builder.AddProject(project).Build();
179-
180-
using (var state = MockParser.CreateAndParse(vbe.Object))
181-
{
182-
if (state.Status >= ParserState.Error)
183-
{
184-
Assert.Inconclusive("Parser Error");
185-
}
186-
187-
var inspection = new ApplicationWorksheetFunctionInspection(state);
188-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
189-
190-
Assert.IsFalse(inspectionResults.Any());
191-
}
126+
Assert.AreEqual(0, InspectionResultsForStandardModule(inputCode).Count());
192127
}
193128

194129
[Test]
@@ -202,15 +137,7 @@ Dim foo As Double
202137
foo = Application.Pi
203138
End Sub
204139
";
205-
206-
using (var state = ArrangeParserAndParse(inputCode))
207-
{
208-
209-
var inspection = new ApplicationWorksheetFunctionInspection(state);
210-
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
211-
212-
Assert.IsFalse(inspectionResults.Any());
213-
}
140+
Assert.AreEqual(0, GetInspectionResultsUsingExcelLibrary(inputCode).Count());
214141
}
215142

216143
[Test]
@@ -222,5 +149,10 @@ public void InspectionName()
222149

223150
Assert.AreEqual(inspectionName, inspection.Name);
224151
}
152+
153+
protected override IInspection InspectionUnderTest(RubberduckParserState state)
154+
{
155+
return new ApplicationWorksheetFunctionInspection(state);
156+
}
225157
}
226158
}

RubberduckTests/Inspections/ArgumentWithIncompatibleObjectTypeInspectionTests.cs

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace RubberduckTests.Inspections
1717
{
1818
[TestFixture]
19-
public class ArgumentWithIncompatibleObjectTypeInspectionTests
19+
public class ArgumentWithIncompatibleObjectTypeInspectionTests : InspectionTestsBase
2020
{
2121
[Test]
2222
[Category("Inspections")]
@@ -61,23 +61,16 @@ Private Sub Bar(baz As {paramTypeName})
6161
End Sub
6262
";
6363

64-
var vbe = new MockVbeBuilder()
65-
.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
66-
.AddComponent("Class1", ComponentType.ClassModule, class1)
67-
.AddComponent("Interface1", ComponentType.ClassModule, interface1)
68-
.AddComponent("Module1", ComponentType.StandardModule, module1)
69-
.AddProjectToVbeBuilder()
70-
.Build()
71-
.Object;
64+
var vbe = BuildTestVBE(class1, interface1, module1);
7265

7366
var setTypeResolverMock = new Mock<ISetTypeResolver>();
7467
setTypeResolverMock.Setup(m =>
7568
m.SetTypeName(It.IsAny<VBAParser.ExpressionContext>(), It.IsAny<QualifiedModuleName>()))
7669
.Returns((VBAParser.ExpressionContext context, QualifiedModuleName qmn) => expressionFullTypeName);
7770

78-
var inspectionResults = InspectionResults(vbe, setTypeResolverMock.Object).ToList();
71+
var inspectionResults = InspectionResults(vbe, setTypeResolverMock.Object);
7972

80-
Assert.AreEqual(expectedResultsCount, inspectionResults.Count);
73+
Assert.AreEqual(expectedResultsCount, inspectionResults.Count());
8174
}
8275

8376
[Test]
@@ -105,19 +98,8 @@ End Sub
10598
Private Sub Bar(ParamArray baz)
10699
End Sub
107100
";
108-
109-
var vbe = new MockVbeBuilder()
110-
.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
111-
.AddComponent("Class1", ComponentType.ClassModule, class1)
112-
.AddComponent("Interface1", ComponentType.ClassModule, interface1)
113-
.AddComponent("Module1", ComponentType.StandardModule, module1)
114-
.AddProjectToVbeBuilder()
115-
.Build()
116-
.Object;
117-
118-
var inspectionResults = InspectionResults(vbe).ToList();
119-
120-
Assert.IsFalse(inspectionResults.Any());
101+
var vbe = BuildTestVBE(class1, interface1, module1);
102+
Assert.AreEqual(0, InspectionResults(vbe).Count());
121103
}
122104

123105
[Test]
@@ -145,46 +127,34 @@ End Sub
145127
Private Sub Bar(Optional baz As Class1 = Nothing, Optional bazBaz As Class1 = Nothing)
146128
End Sub
147129
";
130+
var vbe = BuildTestVBE(class1, interface1, module1);
131+
Assert.AreEqual(0, InspectionResults(vbe).Count());
132+
}
148133

149-
var vbe = new MockVbeBuilder()
134+
private static IVBE BuildTestVBE(string class1, string interface1, string module1)
135+
{
136+
return new MockVbeBuilder()
150137
.ProjectBuilder("TestProject", ProjectProtection.Unprotected)
151138
.AddComponent("Class1", ComponentType.ClassModule, class1)
152139
.AddComponent("Interface1", ComponentType.ClassModule, interface1)
153140
.AddComponent("Module1", ComponentType.StandardModule, module1)
154141
.AddProjectToVbeBuilder()
155142
.Build()
156143
.Object;
157-
158-
var inspectionResults = InspectionResults(vbe).ToList();
159-
160-
Assert.IsFalse(inspectionResults.Any());
161-
}
162-
163-
private static IEnumerable<IInspectionResult> InspectionResults(params (string moduleName, string content, ComponentType componentType)[] testModules)
164-
{
165-
var vbe = MockVbeBuilder.BuildFromModules(testModules).Object;
166-
return InspectionResults(vbe);
167-
}
168-
169-
private static IEnumerable<IInspectionResult> InspectionResults(ISetTypeResolver setTypeResolver, params (string moduleName, string content, ComponentType componentType)[] testModules)
170-
{
171-
var vbe = MockVbeBuilder.BuildFromModules(testModules).Object;
172-
return InspectionResults(vbe, setTypeResolver);
173144
}
174145

175-
private static IEnumerable<IInspectionResult> InspectionResults(IVBE vbe, ISetTypeResolver setTypeResolver = null)
146+
private static IEnumerable<IInspectionResult> InspectionResults(IVBE vbe, ISetTypeResolver setTypeResolver)
176147
{
177148
using (var state = MockParser.CreateAndParse(vbe))
178149
{
179-
var inspection = InspectionUnderTest(state, setTypeResolver);
150+
var inspection = new ArgumentWithIncompatibleObjectTypeInspection(state, setTypeResolver);
180151
return inspection.GetInspectionResults(CancellationToken.None);
181152
}
182153
}
183154

184-
private static IInspection InspectionUnderTest(RubberduckParserState state, ISetTypeResolver setTypeResolver = null)
155+
protected override IInspection InspectionUnderTest(RubberduckParserState state)
185156
{
186-
var setTypeResolverToUse = setTypeResolver ?? new SetTypeResolver(state);
187-
return new ArgumentWithIncompatibleObjectTypeInspection(state, setTypeResolverToUse);
157+
return new ArgumentWithIncompatibleObjectTypeInspection(state, new SetTypeResolver(state));
188158
}
189159
}
190160
}

0 commit comments

Comments
 (0)