Skip to content

Commit a738b4c

Browse files
author
Cédric Belin
committed
Add the first unit tests
1 parent 0d612cb commit a738b4c

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

test/author_test.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
11
namespace Belin.Akismet;
2+
3+
/// <summary>
4+
/// Tests the features of the <see cref="Author"/> class.
5+
/// </summary>
6+
[TestClass]
7+
public sealed class AuthorTest {
8+
9+
[TestMethod]
10+
public void ToJson() {
11+
// It should return only the IP address with a newly created instance.
12+
var map = new Author(ipAddress: "127.0.0.1").ToJson();
13+
AreEqual(1, map.Count);
14+
AreEqual("127.0.0.1", map["user_ip"]);
15+
16+
// It should return a non-empty map with an initialized instance.
17+
var author = new Author(ipAddress: "192.168.0.1") {
18+
Name = "Cédric Belin",
19+
Email = "cedric@belin.io",
20+
Url = new Uri("https://belin.io"),
21+
UserAgent = "Mozilla/5.0"
22+
};
23+
24+
map = author.ToJson();
25+
AreEqual(5, map.Count);
26+
AreEqual("Cédric Belin", map["comment_author"]);
27+
AreEqual("cedric@belin.io", map["comment_author_email"]);
28+
AreEqual("https://belin.io/", map["comment_author_url"]);
29+
AreEqual("Mozilla/5.0", map["user_agent"]);
30+
AreEqual("192.168.0.1", map["user_ip"]);
31+
}
32+
}

test/blog_test.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace Belin.Akismet;
88
[TestClass]
99
public sealed class BlogTest {
1010

11-
[TestMethod("ToJson")]
11+
[TestMethod]
1212
public void ToJson() {
1313
// It should return only the blog URL with a newly created instance.
14-
var map = new Blog(new Uri("https://github.com/cedx/akismet.cs")).ToJson();
14+
var map = new Blog(url: "https://github.com/cedx/akismet.cs").ToJson();
1515
AreEqual(1, map.Count);
1616
AreEqual("https://github.com/cedx/akismet.cs", map["blog"]);
1717

1818
// It should return a non-empty map with an initialized instance.
19-
map = new Blog(new Uri("https://github.com/cedx/akismet.cs")) { Charset = Encoding.UTF8, Languages = ["en", "fr"] }.ToJson();
19+
map = new Blog(url: "https://github.com/cedx/akismet.cs") { Charset = Encoding.UTF8, Languages = ["en", "fr"] }.ToJson();
2020
AreEqual(3, map.Count);
2121
AreEqual("https://github.com/cedx/akismet.cs", map["blog"]);
2222
AreEqual("utf-8", map["blog_charset"]);

test/comment_test.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
namespace Belin.Akismet;
2+
3+
/// <summary>
4+
/// Tests the features of the <see cref="Comment"/> class.
5+
/// </summary>
6+
[TestClass]
7+
public sealed class CommentTest {
8+
9+
[TestMethod]
10+
public void ToJson() {
11+
// It should return only the author info with a newly created instance.
12+
var map = new Comment(new Author(ipAddress: "127.0.0.1")).ToJson();
13+
AreEqual(1, map.Count);
14+
AreEqual("127.0.0.1", map["user_ip"]);
15+
16+
// It should return a non-empty map with an initialized instance.
17+
var author = new Author(ipAddress: "127.0.0.1") {
18+
Name = "Cédric Belin",
19+
UserAgent = "Doom/6.6.6"
20+
};
21+
22+
var comment = new Comment(author) {
23+
Content = "A user comment.",
24+
Date = DateTime.Parse("2000-01-01T00:00:00.000Z"),
25+
Referrer = new Uri("https://belin.io"),
26+
Type = "blog-post"
27+
};
28+
29+
map = comment.ToJson();
30+
AreEqual(7, map.Count);
31+
AreEqual("Cédric Belin", map["comment_author"]);
32+
AreEqual("A user comment.", map["comment_content"]);
33+
AreEqual("2000-01-01T00:00:00Z", map["comment_date_gmt"]);
34+
AreEqual("blog-post", map["comment_type"]);
35+
AreEqual("https://belin.io/", map["referrer"]);
36+
AreEqual("Doom/6.6.6", map["user_agent"]);
37+
AreEqual("127.0.0.1", map["user_ip"]);
38+
}
39+
}

0 commit comments

Comments
 (0)