Skip to content

Commit 442555d

Browse files
authored
Update Unit Tests (#383)
***NO_CI***
1 parent 58bcc8c commit 442555d

File tree

2 files changed

+102
-70
lines changed

2 files changed

+102
-70
lines changed

samples/UnitTest/NFUnitTestDemo.sln

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31019.35
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.11.35222.181
54
MinimumVisualStudioVersion = 10.0.40219.1
65
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "NFUnitTest", "NFUnitTestDemo\NFUnitTest.nfproj", "{FBD29C49-D7DC-425E-BAD1-1AE63484A6CD}"
76
EndProject

samples/UnitTest/NFUnitTestDemo/Test.cs

Lines changed: 100 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class TestOfTest
1616
public void TestRaisesException()
1717
{
1818
Debug.WriteLine("Test will raise exception");
19-
Assert.Throws(typeof(Exception), ThrowMe);
19+
Assert.ThrowsException(typeof(Exception), ThrowMe);
2020
}
2121

2222
private void ThrowMe()
@@ -25,86 +25,116 @@ private void ThrowMe()
2525
}
2626

2727
[TestMethod]
28-
public void TestCheckAllEqual()
28+
public void TestCheckAllAreEqual()
2929
{
3030
Debug.WriteLine("Test will check that all the Equal are actually equal");
31+
3132
// Arrange
32-
byte bytea = 42; byte byteb = 42;
33-
char chara = (char)42; char charb = (char)42;
34-
sbyte sbytea = 42; sbyte sbyteb = 42;
35-
int inta = 42; int intb = 42;
36-
uint uinta = 42; uint uintb = 42;
37-
long longa = 42; long longb = 42;
38-
ulong ulonga = 42; ulong ulongb = 42;
39-
bool boola = true; bool boolb = true;
40-
short shorta = 42; short shortb = 42;
41-
ushort ushorta = 42; ushort ushortb = 42;
42-
float floata = 42; float floatb = 42;
33+
byte bytea = 42;
34+
byte byteb = 42;
35+
char chara = (char)42;
36+
char charb = (char)42;
37+
sbyte sbytea = 42;
38+
sbyte sbyteb = 42;
39+
int inta = 42;
40+
int intb = 42;
41+
uint uinta = 42;
42+
uint uintb = 42;
43+
long longa = 42;
44+
long longb = 42;
45+
ulong ulonga = 42;
46+
ulong ulongb = 42;
47+
bool boola = true;
48+
bool boolb = true;
49+
short shorta = 42;
50+
short shortb = 42;
51+
ushort ushorta = 42;
52+
ushort ushortb = 42;
53+
float floata = 42;
54+
float floatb = 42;
4355
int[] intArraya = new int[5] { 1, 2, 3, 4, 5 };
4456
int[] intArrayb = new int[5] { 1, 2, 3, 4, 5 };
45-
object obja = new object(); object objb = obja;
46-
string stra = "42"; string strb = "42";
57+
object obja = new object();
58+
object objb = obja;
59+
string stra = "42";
60+
string strb = "42";
4761
byte[] arrayempty = new byte[0];
62+
4863
// Assert
49-
Assert.True(boola);
50-
Assert.Equal(bytea, byteb);
51-
Assert.Equal(chara, charb);
52-
Assert.Equal(sbytea, sbyteb);
53-
Assert.Equal(inta, intb);
54-
Assert.Equal(uinta, uintb);
55-
Assert.Equal(longa, longb);
56-
Assert.Equal(ulonga, ulongb);
57-
Assert.Equal(boola, boolb);
58-
Assert.Equal(shorta, shortb);
59-
Assert.Equal(ushorta, ushortb);
60-
Assert.Equal(floata, floatb);
61-
Assert.Equal(intArraya, intArrayb);
62-
Assert.Equal(stra, strb);
63-
Assert.Same(obja, objb);
64-
Assert.Empty(arrayempty);
64+
Assert.IsTrue(boola);
65+
Assert.AreEqual(bytea, byteb);
66+
Assert.AreEqual(chara, charb);
67+
Assert.AreEqual(sbytea, sbyteb);
68+
Assert.AreEqual(inta, intb);
69+
Assert.AreEqual(uinta, uintb);
70+
Assert.AreEqual(longa, longb);
71+
Assert.AreEqual(ulonga, ulongb);
72+
Assert.AreEqual(boola, boolb);
73+
Assert.AreEqual(shorta, shortb);
74+
Assert.AreEqual(ushorta, ushortb);
75+
Assert.AreEqual(floata, floatb);
76+
Assert.AreEqual(intArraya, intArrayb);
77+
Assert.AreEqual(stra, strb);
78+
Assert.AreSame(obja, objb);
79+
CollectionAssert.Empty(arrayempty);
6580
}
6681

6782
[TestMethod]
68-
public void TestCheckAllNotEqual()
83+
public void TestCheckAllAreNotEqual()
6984
{
7085
Debug.WriteLine("Test will check that all the NotEqual are actually equal");
86+
7187
// Arrange
72-
byte bytea = 42; byte byteb = 43;
73-
char chara = (char)42; char charb = (char)43;
74-
sbyte sbytea = 42; sbyte sbyteb = 43;
75-
int inta = 42; int intb = 43;
76-
uint uinta = 42; uint uintb = 43;
77-
long longa = 42; long longb = 43;
78-
ulong ulonga = 42; ulong ulongb = 43;
79-
bool boola = true; bool boolb = false;
80-
short shorta = 42; short shortb = 43;
81-
ushort ushorta = 42; ushort ushortb = 43;
82-
float floata = 42; float floatb = 43;
88+
byte bytea = 42;
89+
byte byteb = 43;
90+
char chara = (char)42;
91+
char charb = (char)43;
92+
sbyte sbytea = 42;
93+
sbyte sbyteb = 43;
94+
int inta = 42;
95+
int intb = 43;
96+
uint uinta = 42;
97+
uint uintb = 43;
98+
long longa = 42;
99+
long longb = 43;
100+
ulong ulonga = 42;
101+
ulong ulongb = 43;
102+
bool boola = true;
103+
bool boolb = false;
104+
short shorta = 42;
105+
short shortb = 43;
106+
ushort ushorta = 42;
107+
ushort ushortb = 43;
108+
float floata = 42;
109+
float floatb = 43;
83110
int[] intArraya = new int[5] { 1, 2, 3, 4, 5 };
84111
int[] intArrayb = new int[5] { 1, 2, 3, 4, 6 };
85112
int[] intArraybis = new int[4] { 1, 2, 3, 4 };
86113
int[] intArrayter = null;
87-
object obja = new object(); object objb = new object();
88-
string stra = "42"; string strb = "43";
114+
object obja = new object();
115+
object objb = new object();
116+
string stra = "42";
117+
string strb = "43";
118+
89119
// Assert
90-
Assert.False(boolb);
91-
Assert.NotEqual(bytea, byteb);
92-
Assert.NotEqual(chara, charb);
93-
Assert.NotEqual(sbytea, sbyteb);
94-
Assert.NotEqual(inta, intb);
95-
Assert.NotEqual(uinta, uintb);
96-
Assert.NotEqual(longa, longb);
97-
Assert.NotEqual(ulonga, ulongb);
98-
Assert.NotEqual(boola, boolb);
99-
Assert.NotEqual(shorta, shortb);
100-
Assert.NotEqual(ushorta, ushortb);
101-
Assert.NotEqual(floata, floatb);
102-
Assert.NotEqual(intArraya, intArrayb);
103-
Assert.NotEqual(intArraya, intArraybis);
104-
Assert.NotEqual(intArraya, intArrayter);
105-
Assert.NotEqual(stra, strb);
106-
Assert.NotSame(obja, objb);
107-
Assert.NotEmpty(intArraya);
120+
Assert.IsFalse(boolb);
121+
Assert.AreNotEqual(bytea, byteb);
122+
Assert.AreNotEqual(chara, charb);
123+
Assert.AreNotEqual(sbytea, sbyteb);
124+
Assert.AreNotEqual(inta, intb);
125+
Assert.AreNotEqual(uinta, uintb);
126+
Assert.AreNotEqual(longa, longb);
127+
Assert.AreNotEqual(ulonga, ulongb);
128+
Assert.AreNotEqual(boola, boolb);
129+
Assert.AreNotEqual(shorta, shortb);
130+
Assert.AreNotEqual(ushorta, ushortb);
131+
Assert.AreNotEqual(floata, floatb);
132+
Assert.AreNotEqual(intArraya, intArrayb);
133+
Assert.AreNotEqual(intArraya, intArraybis);
134+
Assert.AreNotEqual(intArraya, intArrayter);
135+
Assert.AreNotEqual(stra, strb);
136+
Assert.AreNotSame(obja, objb);
137+
CollectionAssert.NotEmpty(intArraya);
108138
}
109139

110140
[TestMethod]
@@ -117,24 +147,27 @@ public void TestNullEmpty()
117147
Type typea = typeof(int);
118148
Type typeb = typeof(int);
119149
Type typec = typeof(long);
150+
120151
// Assert
121-
Assert.Null(objnull);
122-
Assert.NotNull(objnotnull);
123-
Assert.IsType(typea, typeb);
124-
Assert.IsNotType(typea, typec);
152+
Assert.IsNull(objnull);
153+
Assert.IsNotNull(objnotnull);
154+
Assert.IsInstanceOfType(typea, typeb);
155+
Assert.IsNotInstanceOfType(typea, typec);
125156
}
126157

127158
[TestMethod]
128159
public void TestStringComparison()
129160
{
130161
Debug.WriteLine("Test string, Contains, EndsWith, StartWith");
162+
131163
// Arrange
132164
string tocontains = "this text contains and end with contains";
133165
string startcontains = "contains start this text";
134166
string contains = "contains";
135167
string doesnotcontains = "this is totally something else";
136168
string empty = string.Empty;
137169
string stringnull = null;
170+
138171
// Assert
139172
Assert.Contains(contains, tocontains);
140173
Assert.DoesNotContains(contains, doesnotcontains);

0 commit comments

Comments
 (0)