Skip to content

Commit 5ec87e0

Browse files
author
Gonzalo Diaz
committed
Hello World sample: new test to instance basic methods
1 parent c5b2617 commit 5ec87e0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

algorithm-exercises-csharp/src/Hello.Test.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ namespace algorithm_exercises_csharp;
33
[TestClass]
44
public class HelloWorldTest
55
{
6+
[TestMethod]
7+
public void TestInstance()
8+
{
9+
HelloWorld a = HelloWorld.Create();
10+
HelloWorld b = HelloWorld.Create();
11+
12+
Type knownType = typeof(HelloWorld);
13+
Type resultType = a.GetType();
14+
Assert.IsInstanceOfType(a, knownType);
15+
Assert.IsInstanceOfType(a, resultType);
16+
17+
int resultHashCode = a.GetHashCode();
18+
Assert.IsNotNull(resultHashCode);
19+
20+
bool expectedEquals = true;
21+
bool expectedNotEquals = false;
22+
Assert.AreEqual(expectedEquals, a.Equals(a));
23+
Assert.AreEqual(expectedNotEquals, a.Equals(b));
24+
25+
string expectedString = "algorithm_exercises_csharp.HelloWorld";
26+
string? resultString = a.ToString();
27+
Assert.AreEqual<string>(expectedString, resultString);
28+
}
29+
630
[TestMethod]
731
public void TestHello()
832
{

algorithm-exercises-csharp/src/Hello.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ public static string Hello()
1111
{
1212
return "Hello World!";
1313
}
14+
15+
public static HelloWorld Create() {
16+
return new HelloWorld();
17+
}
1418
}

0 commit comments

Comments
 (0)