Skip to content

Commit 76bb301

Browse files
authored
Migrate Unit Tests to use DataRow (#186)
***NO_CI***
1 parent ede6154 commit 76bb301

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

Tests/NFUnitTestArithmetic/UnitTestFormat.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,44 @@ public enum Case
3838
}
3939

4040
[TestMethod]
41-
public void StringFormat()
41+
public void StringFormat_00()
4242
{
4343
// Test a null string in String.Format - should be treated like an empty string.
4444
string nullArg = null;
4545
Assert.Equal(string.Format("Value is {0}", nullArg), "Value is ", "");
46+
}
4647

48+
[TestMethod]
49+
public void StringFormat_01()
50+
{
4751
// catch an exception if the format string is null
4852
string nullFormat = null;
4953
Assert.Throws(typeof(NullReferenceException), () => { string.Format(nullFormat, 12345.67); });
54+
}
5055

56+
[TestMethod]
57+
[DataRow("Left align in 10 chars: {0,-10:N2}: and then more", 1234.5641, "Left align in 10 chars: 1,234.56 : and then more")]
58+
[DataRow("Right align in 10 chars: {0,10:N2}: and then more", 1234.5641, "Right align in 10 chars: 1,234.56: and then more")]
59+
public void StringFormat_02(string formatString, double value, string outcomeMessage)
60+
{
5161
// Test alignment operator which is the "," and a number. Negative is right aligned, positive left aligned
62+
Assert.Equal(string.Format(formatString, value), outcomeMessage);
63+
}
5264

53-
Assert.Equal(string.Format("Left align in 10 chars: {0,-10:N2}: and then more", 1234.5641), "Left align in 10 chars: 1,234.56 : and then more");
54-
Assert.Equal(string.Format("Right align in 10 chars: {0,10:N2}: and then more", 1234.5641), "Right align in 10 chars: 1,234.56: and then more");
55-
65+
[TestMethod]
66+
[DataRow("{0,}", 12345.67, "Should throw with error message: Format error: empty alignment, column 3")]
67+
[DataRow("{0,a10}", 12345.67, "Should throw with error message: Format error: wrong symbol at alignment, column 3")]
68+
[DataRow("{0, -a10}", 12345.67, "Should throw with error message: Format error: wrong symbol at alignment, column 4")]
69+
[DataRow("{a}", 12345.67, "Should throw with error message: Format error: wrong symbol at {}, column 1")]
70+
[DataRow("{0:}", 12345.67, "Should throw with error message: Format error: empty format after ':', column 3")]
71+
[DataRow("{0", 12345.67, "Should throw with error message: Format error: no closed brace, column 2")]
72+
public void StringFormat_03(string formatString, double value, string outcomeMessage)
73+
{
74+
OutputHelper.WriteLine("formatString is" + formatString);
5675
// invalid alignment cases
57-
58-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{0,}", 12345.67); }, "Should throw with error message: Format error: empty alignment, column 3");
59-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{0,a10}", 12345.67); }, "Should throw with error message: Format error: wrong symbol at alignment, column 3");
60-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{0,-a10}", 12345.67); }, "Should throw with error message: Format error: wrong symbol at alignment, column 4");
61-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{a}", 12345.67); }, "Should throw with error message: Format error: wrong symbol at {}, column 1");
62-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{0:}", 12345.67); }, "Should throw with error message: Format error: empty format after ':', column 3");
63-
Assert.Throws(typeof(ArgumentException), () => { string.Format("{0", 12345.67); }, "Should throw with error message: Format error: no closed brace, column 2");
64-
76+
Assert.Throws(typeof(ArgumentException), () => { string.Format(formatString, value); }, outcomeMessage);
6577
}
6678

67-
68-
6979
[TestMethod]
7080
// the D format can only be used with integers (no double or floats)
7181
public void DecimalFormat()

Tests/NFUnitTest_DummyAdapter/NFUnitTest_DummyAdapter.nfproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@
5858
</PropertyGroup>
5959
<Warning Condition="!Exists('..\..\packages\nanoFramework.TestFramework.2.0.43\build\nanoFramework.TestFramework.targets')" Text="'$(WarningText)'" />
6060
</Target>
61-
</Project>
61+
</Project>

Tests/NFUnitTest_DummyAdapter/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnano1.0" />
44
<package id="nanoFramework.TestFramework" version="2.0.43" targetFramework="netnano1.0" developmentDependency="true" />
5-
</packages>
5+
</packages>

0 commit comments

Comments
 (0)