Skip to content

Commit df0cfe8

Browse files
committed
[XmlDocUtils] Tests
1 parent 81fb66e commit df0cfe8

File tree

4 files changed

+64
-31
lines changed

4 files changed

+64
-31
lines changed

src/10-Core/Wtq.UnitTest/Utils/SystemExtensionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public void ToSnakeCase(string inp, string expected)
3535
[TestMethod]
3636
public void ToSnakeCaseNull()
3737
{
38-
Assert.ThrowsException<ArgumentNullException>(() => ((string)null).ToSnakeCase());
38+
Assert.ThrowsExactly<ArgumentNullException>(() => ((string)null)!.ToSnakeCase());
3939
}
4040
}
Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,60 @@
1-
using Namotion.Reflection;
2-
using System.Linq;
1+
using System.Reflection;
32

43
namespace Wtq.Core.UnitTest.Utils;
54

65
[TestClass]
76
public class XmlDocUtilsTest
87
{
8+
[TestMethod]
9+
public void GetExample()
10+
{
11+
// Act
12+
var summary = TestClass.PropertyInfo.GetExample();
13+
14+
// Assert
15+
Assert.AreEqual(
16+
"""
17+
{
18+
"Name": "Value"
19+
}
20+
""",
21+
summary);
22+
}
23+
24+
[TestMethod]
25+
public void GetRemarks()
26+
{
27+
// Act
28+
var summary = TestClass.PropertyInfo.GetRemarks();
29+
30+
// Assert
31+
Assert.AreEqual(
32+
"""
33+
The Remarks.
34+
Another line.
35+
<p>With paragraph.</p>
36+
With <strong>strong</strong> words.
37+
""",
38+
summary);
39+
}
40+
41+
[TestMethod]
42+
public void GetSummary()
43+
{
44+
// Act
45+
var summary = TestClass.PropertyInfo.GetSummary();
46+
47+
// Assert
48+
Assert.AreEqual(
49+
"""
50+
The Summary.
51+
Another line.
52+
<p>With paragraph.</p>
53+
With <strong>strong</strong> words.
54+
""",
55+
summary);
56+
}
57+
958
private class TestClass
1059
{
1160
/// <summary>
@@ -28,27 +77,7 @@ private class TestClass
2877
/// </code>
2978
/// </example>
3079
public string? Property { get; set; }
31-
}
32-
33-
[TestMethod, Ignore]
34-
public void METHOD()
35-
{
36-
var classType = typeof(TestClass);
37-
var propType = classType.GetProperty(nameof(TestClass.Property));
38-
39-
var summary = propType.GetSummary();
40-
41-
Assert.AreEqual("""
42-
The Summary.
43-
Another line.
44-
<p>With <strong>strong</strong></p> words.
45-
""", summary);
46-
47-
// var doc = XmlDocUtils
48-
// .GetMemberDocElement(propType)
49-
// .Descendants("summary")
50-
// .FirstOrDefault();
5180

52-
var dbg = 2;
81+
public static PropertyInfo PropertyInfo => typeof(TestClass).GetProperty(nameof(Property))!;
5382
}
5483
}

src/10-Core/Wtq/Utils/SystemExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ public static TValue JsonDeepClone<TValue>(this TValue value)
1111
return JsonSerializer.Deserialize<TValue>(json)!;
1212
}
1313

14+
/// <summary>
15+
/// "" => null<br/>
16+
/// " " => null<br/>
17+
/// "\t" => null<br/>
18+
/// "\n" => null<br/>
19+
/// "not-null" => "not-null".<br/>
20+
/// </summary>
1421
public static string? EmptyOrWhiteSpaceToNull(this string? input) => string.IsNullOrWhiteSpace(input) ? null : input;
1522

1623
public static IEnumerable<ValidationResult> Validate(this IValidatableObject validatable)

src/10-Core/Wtq/Utils/XmlDocUtils.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Wtq.Utils;
55

66
public static class XmlDocUtils
77
{
8-
private static XmlDocsOptions _xmlDocsOptions = new()
8+
private static readonly XmlDocsOptions _xmlDocsOptions = new()
99
{
1010
FormattingMode = XmlDocsFormattingMode.Html,
1111
};
@@ -19,14 +19,11 @@ public static class XmlDocUtils
1919
public static string? GetSummary(this MemberInfo memberInfo) =>
2020
Guard.Against.Null(memberInfo).GetXmlDocsTag("summary", _xmlDocsOptions);
2121

22-
#region Enums
23-
2422
public static string? GetSummaryEnum(this object val, Type enumType)
2523
{
26-
var memb = enumType.GetMember(val.ToString()!).First();
24+
var member = enumType.GetMember(val.ToString()!).FirstOrDefault()
25+
?? throw new InvalidOperationException($"Could not get member info for enum type '{enumType.FullName}'.");
2726

28-
return GetSummary(memb);
27+
return GetSummary(member);
2928
}
30-
31-
#endregion
3229
}

0 commit comments

Comments
 (0)