Skip to content

Commit 2aebda3

Browse files
authored
Allow Array(1,3,...) as row test parameter (#70)
1 parent 4c7d5cc commit 2aebda3

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

source/AccUnit/Integration/TestRowGenerator.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,28 @@ private string ConvertVbaParamStringToVB(string paramstring)
170170
m =>
171171
string.Format("{0}{1}{2}", m.Groups[1].Value,
172172
"DBNull.Value", m.Groups[3].Value));
173+
tempString = ConvertVbArrayStringsToVB(tempString);
173174
tempString = ConvertConstantStringsToVB(tempString);
174175
tempString = tempString.Replace(".Tags(", ".AddTags(");
175176
return "TestManager.AddRow" + tempString;
176177
}
177178

179+
private static readonly Regex VbArrayStringRegex = new Regex(@"([\(\,]?)\s*(Array\((.*)\))\s*([\)\,])", RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
180+
private string ConvertVbArrayStringsToVB(string paramstring)
181+
{
182+
Logger.Log(string.Format("Fill params, replace constants"));
183+
184+
var test = VbArrayStringRegex.Match(paramstring);
185+
186+
var tempString = VbArrayStringRegex.Replace(paramstring,
187+
m =>
188+
string.Format("{0}{1}{2}", m.Groups[1].Value,
189+
"New Object() {New Object() {" + m.Groups[3].Value + "}}", m.Groups[4].Value));
190+
// Note: workaround: New Object() {1, 2, 3} creates 3 params and not an array
191+
Logger.Log("completed");
192+
return tempString;
193+
}
194+
178195
private static readonly Regex ConstantStringRegex = new Regex(@"([\(\,]?)\s*([A-z\.]+)\s*([\)\,])", RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
179196
private string ConvertConstantStringsToVB(string paramstring)
180197
{
@@ -224,7 +241,6 @@ private static string ReplaceParamConstantStringWithValue(string paramstring)
224241
private static object CreateTestRowGenerator(string testparamstring)
225242
{
226243
var sourcecode = GetTestRowGeneratorSource(testparamstring);
227-
228244
using (var bcp = new Microsoft.VisualBasic.VBCodeProvider())
229245
{
230246
var cp = new CompilerParameters();

source/Common/Common.Tools/AccessCodeLib.Common.Tools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
2525
<CodeAnalysisRuleSet>ExtendedCorrectnessRules.ruleset</CodeAnalysisRuleSet>
26-
<PlatformTarget>x86</PlatformTarget>
26+
<PlatformTarget>AnyCPU</PlatformTarget>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2929
<DebugType>pdbonly</DebugType>

source/Common/Common.VBIDETools/AccessCodeLib.Common.VBIDETools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ErrorReport>prompt</ErrorReport>
2424
<WarningLevel>4</WarningLevel>
2525
<CodeAnalysisRuleSet>ExtendedCorrectnessRules.ruleset</CodeAnalysisRuleSet>
26-
<PlatformTarget>x86</PlatformTarget>
26+
<PlatformTarget>AnyCPU</PlatformTarget>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2929
<DebugType>pdbonly</DebugType>

source/Tests/AccessTestClientTests/TestRunnerTests.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ internal class TestRunnerTests
1616
public void TestBuilderTestsSetup()
1717
{
1818
_accessTestHelper = AccessClientTestHelper.NewAccessTestHelper();
19-
var applictionHelper = new AccessApplicationHelper(_accessTestHelper.Application);
20-
_testBuilder = new Interop.TestBuilder(applictionHelper);
19+
var applicationHelper = new AccessApplicationHelper(_accessTestHelper.Application);
20+
_testBuilder = new Interop.TestBuilder(applicationHelper);
2121
}
2222

2323
[TearDown]
@@ -234,6 +234,51 @@ public Function TestMethod1(ByRef x() as Long) as Long
234234
TestMethod1 = x(0)
235235
End Function
236236
237+
public Function GetCheckValue() as long
238+
GetCheckValue = m_Check
239+
End Function
240+
");
241+
var fixtureName = "clsAccUnitTestClass";
242+
var fixture = _testBuilder.CreateTest(fixtureName);
243+
Assert.That(fixture, Is.Not.Null);
244+
245+
var memberName = "TestMethod1";
246+
var fixtureMember = new TestFixtureMember(memberName);
247+
248+
var testClassReader = new TestClassReader(_accessTestHelper.ActiveVBProject);
249+
fixtureMember.TestClassMemberInfo = testClassReader.GetTestClassMemberInfo(fixtureName, memberName);
250+
251+
var rowGenerator = new TestRowGenerator
252+
{
253+
ActiveVBProject = _accessTestHelper.ActiveVBProject,
254+
TestName = fixtureName
255+
};
256+
var testRows = rowGenerator.GetTestRows(memberName);
257+
258+
var invocHelper = new InvocationHelper(fixture);
259+
var returnValue = invocHelper.InvokeMethod("TestMethod1", testRows[0].Args.ToArray());
260+
Assert.That(returnValue, Is.EqualTo(1));
261+
262+
var result = new TestResultCollector();
263+
var testRunner = new Interop.TestRunner(_accessTestHelper.ActiveVBProject);
264+
testRunner.Run(fixture, "TestMethod1", result);
265+
266+
var valueAfterTestRun = invocHelper.InvokeMethod("GetCheckValue");
267+
Assert.That(valueAfterTestRun, Is.EqualTo(2));
268+
}
269+
270+
[Test]
271+
public void RunRowTest_VbaArrayParam()
272+
{
273+
AccessClientTestHelper.CreateTestCodeModule(_accessTestHelper, "clsAccUnitTestClass", vbext_ComponentType.vbext_ct_ClassModule, @"
274+
private m_Check as Long
275+
276+
'AccUnit:Row(Array(1, 2))
277+
public Function TestMethod1(ByRef x() as Variant) as Long
278+
m_Check = x(1)
279+
TestMethod1 = x(0)
280+
End Function
281+
237282
public Function GetCheckValue() as long
238283
GetCheckValue = m_Check
239284
End Function

source/Tests/Common.TestHelper/AccessCodeLib.Common.TestHelpers.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1515
<FileAlignment>512</FileAlignment>
1616
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17-
<SccProjectName>Svn</SccProjectName>
18-
<SccLocalPath>Svn</SccLocalPath>
19-
<SccAuxPath>Svn</SccAuxPath>
20-
<SccProvider>SubversionScc</SccProvider>
17+
<SccProjectName>
18+
</SccProjectName>
19+
<SccLocalPath>
20+
</SccLocalPath>
21+
<SccAuxPath>
22+
</SccAuxPath>
23+
<SccProvider>
24+
</SccProvider>
2125
<TargetFrameworkProfile />
2226
</PropertyGroup>
2327
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

0 commit comments

Comments
 (0)