Skip to content

Commit

Permalink
Unit test formatting and the fix for ubuntu newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
loxsmoke committed Jun 16, 2024
1 parent 7de94ee commit 690f944
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Release;Coverage</Configurations>
</PropertyGroup>

Expand Down
2 changes: 0 additions & 2 deletions test/DocXmlUnitTests/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ public class BaseTestClass
{
public DocXmlReader Reader { get; set; }
public DocXmlReader MultiAssemblyReader { get; set; }
public Type MyClass_Type;

public void Setup()
{
Reader = new DocXmlReader("DocXmlUnitTests.xml");
MultiAssemblyReader = new DocXmlReader((a) => Path.GetFileNameWithoutExtension(a.Location) + ".xml");
MyClass_Type = typeof(MyClass);
}

public void AssertParam(MethodComments comments, int paramIndex, string name, string text)
Expand Down
4 changes: 2 additions & 2 deletions test/DocXmlUnitTests/DocXmlReaderUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ First paragraph.
</para>
<para>
Second paragraph.
</para>",
summary);
</para>".ReplaceLineEndings(),
summary.ReplaceLineEndings());
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion test/DocXmlUnitTests/DocXmlUnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down
83 changes: 46 additions & 37 deletions test/DocXmlUnitTests/EnumCommentsUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,36 @@ void AssertBigEnumComment(BigInteger expectedValue, string expectedName, string
[TestMethod]
public void GetEnumComments_NotEnumType()
{
Assert.ThrowsException<ArgumentException>(() => Reader.GetEnumComments(MyClass_Type));
Assert.ThrowsException<ArgumentException>(() => Reader.GetEnumComments(typeof(MyClass)));
}

[TestMethod]
public void GetEnumComments()
{
var mm = Reader.GetEnumComments(typeof(TestEnum2));
Assert.AreEqual("Enum 2 type description", mm.Summary);
Assert.AreEqual(0, mm.ValueComments.Count);
var comments = Reader.GetEnumComments(typeof(TestEnum2));

Assert.AreEqual("Enum 2 type description", comments.Summary);
Assert.AreEqual(0, comments.ValueComments.Count);
}

[TestMethod]
public void GetEnumComments_NoComment()
{
var mm = Reader.GetEnumComments(typeof(MyNoCommentClass.TestEnumNoComments));
Assert.IsNull(mm.Summary);
Assert.AreEqual(0, mm.ValueComments.Count);
var comments = Reader.GetEnumComments(typeof(MyNoCommentClass.TestEnumNoComments));

Assert.IsNull(comments.Summary);
Assert.AreEqual(0, comments.ValueComments.Count);
}

[TestMethod]
public void GetEnumComments_Values_NoComments()
{
var mm = Reader.GetEnumComments(typeof(TestEnum2), true);
Assert.AreEqual("Enum 2 type description", mm.Summary);
Assert.AreEqual(2, mm.ValueComments.Count);
AssertEnumComment(0, "Value21", string.Empty, mm.ValueComments[0]);
AssertEnumComment(1, "Value22", string.Empty, mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnum2), true);

Assert.AreEqual("Enum 2 type description", comments.Summary);
Assert.AreEqual(2, comments.ValueComments.Count);
AssertEnumComment(0, "Value21", string.Empty, comments.ValueComments[0]);
AssertEnumComment(1, "Value22", string.Empty, comments.ValueComments[1]);
}

[TestMethod]
Expand All @@ -89,56 +92,62 @@ public void EnumValueComments_ToString()
[TestMethod]
public void GetEnumComments_WithValues_Comments()
{
var mm = Reader.GetEnumComments(typeof(TestEnumWithValueComments));
Assert.AreEqual("Enum type description", mm.Summary);
Assert.AreEqual(2, mm.ValueComments.Count);
AssertEnumComment(10, "Value1", "Enum value one", mm.ValueComments[0]);
AssertEnumComment(20, "Value2", "Enum value two", mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnumWithValueComments));

Assert.AreEqual("Enum type description", comments.Summary);
Assert.AreEqual(2, comments.ValueComments.Count);
AssertEnumComment(10, "Value1", "Enum value one", comments.ValueComments[0]);
AssertEnumComment(20, "Value2", "Enum value two", comments.ValueComments[1]);
}

[TestMethod]
public void GetEnumComments_WithValue_Comments_OtherAssembly()
{
var mm = new DocXmlReader().GetEnumComments(typeof(OtherEnum));
Assert.AreEqual("Other enum", mm.Summary);
Assert.AreEqual(1, mm.ValueComments.Count);
AssertEnumComment(1, "Value1", "Enum value one", mm.ValueComments[0]);
var comments = new DocXmlReader().GetEnumComments(typeof(OtherEnum));

Assert.AreEqual("Other enum", comments.Summary);
Assert.AreEqual(1, comments.ValueComments.Count);
AssertEnumComment(1, "Value1", "Enum value one", comments.ValueComments[0]);
}

[TestMethod]
public void GetEnumComments_WithValues_UInt8()
{
var mm = Reader.GetEnumComments(typeof(TestEnumUInt8));
Assert.AreEqual(2, mm.ValueComments.Count);
AssertEnumComment(10, "Value1", "Enum value one", mm.ValueComments[0]);
AssertEnumComment(20, "Value2", "Enum value two", mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnumUInt8));

Assert.AreEqual(2, comments.ValueComments.Count);
AssertEnumComment(10, "Value1", "Enum value one", comments.ValueComments[0]);
AssertEnumComment(20, "Value2", "Enum value two", comments.ValueComments[1]);
}

[TestMethod]
public void GetEnumComments_WithValues_UInt64()
{
var mm = Reader.GetEnumComments(typeof(TestEnumUInt64));
Assert.AreEqual(2, mm.ValueComments.Count);
AssertBigEnumComment(new BigInteger(10L), "Value1", "Enum value one", mm.ValueComments[0]);
AssertBigEnumComment(new BigInteger(20L), "Value2", "Enum value two", mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnumUInt64));

Assert.AreEqual(2, comments.ValueComments.Count);
AssertBigEnumComment(new BigInteger(10L), "Value1", "Enum value one", comments.ValueComments[0]);
AssertBigEnumComment(new BigInteger(20L), "Value2", "Enum value two", comments.ValueComments[1]);
}

[TestMethod]
public void GetEnumComments_WithValues_Int64()
{
var mm = Reader.GetEnumComments(typeof(TestEnumInt64));
Assert.AreEqual(2, mm.ValueComments.Count);
AssertBigEnumComment(new BigInteger(10L), "Value1", "Enum value one", mm.ValueComments[0]);
AssertBigEnumComment(new BigInteger(20L), "Value2", "Enum value two", mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnumInt64));

Assert.AreEqual(2, comments.ValueComments.Count);
AssertBigEnumComment(new BigInteger(10L), "Value1", "Enum value one", comments.ValueComments[0]);
AssertBigEnumComment(new BigInteger(20L), "Value2", "Enum value two", comments.ValueComments[1]);
}

[TestMethod]
public void GetEnumComments_WithNegativeValues()
{
var mm = Reader.GetEnumComments(typeof(TestEnumWithNegativeValues));
Assert.AreEqual(2, mm.ValueComments.Count);
AssertEnumComment(-20, "Value1", "Enum value one", mm.ValueComments[0]);
AssertEnumComment(-10, "Value2", "Enum value two", mm.ValueComments[1]);
var comments = Reader.GetEnumComments(typeof(TestEnumWithNegativeValues));

Assert.AreEqual(2, comments.ValueComments.Count);
AssertEnumComment(-20, "Value1", "Enum value one", comments.ValueComments[0]);
AssertEnumComment(-10, "Value2", "Enum value two", comments.ValueComments[1]);
}
}
}
4 changes: 3 additions & 1 deletion test/DocXmlUnitTests/MemberInfoUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public class MemberInfoUnitTests : BaseTestClass
[DataRow(nameof(MyClass.genericTypeField), "Generic field description")]
public void GetMemberComment(string memberName, string expectedComment)
{
var memberInfo = MyClass_Type.GetMember(memberName).First();
var memberInfo = typeof(MyClass).GetMember(memberName).First();

var comment = Reader.GetMemberComment(memberInfo);

Assert.AreEqual(expectedComment, comment);
}
}
Expand Down
Loading

0 comments on commit 690f944

Please sign in to comment.