Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7921d3f

Browse files
authored
More tests (#147)
* Exception unit tests. * Test to verify that we do not backport inherited docs.
1 parent b6fcdd2 commit 7921d3f

File tree

1 file changed

+222
-1
lines changed

1 file changed

+222
-1
lines changed

src/PortToTripleSlash/tests/PortToTripleSlash/PortToTripleSlash.Strings.Tests.cs

Lines changed: 222 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Generic;
@@ -525,6 +525,55 @@ public class MyClass
525525
return TestWithStringsAsync(stringTestData);
526526
}
527527

528+
[Fact]
529+
public Task Class_Method_Exception()
530+
{
531+
string docId = "T:MyNamespace.MyClass";
532+
533+
string docFile = @"<Type Name=""MyClass"" FullName=""MyNamespace.MyClass"">
534+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyClass"" />
535+
<AssemblyInfo>
536+
<AssemblyName>MyAssembly</AssemblyName>
537+
</AssemblyInfo>
538+
<Docs>
539+
<summary>To be added.</summary>
540+
<remarks>To be added.</remarks>
541+
</Docs>
542+
<Members>
543+
<Member MemberName=""MyVoidMethod"">
544+
<MemberSignature Language=""DocId"" Value=""M:MyNamespace.MyClass.MyVoidMethod"" />
545+
<Docs>
546+
<summary>This is the MyVoidMethod summary.</summary>
547+
<remarks>These are the MyVoidMethod remarks.</remarks>
548+
<exception cref=""T:System.NullReferenceException"">The null reference exception thrown by MyVoidMethod.</exception>
549+
</Docs>
550+
</Member>
551+
</Members>
552+
</Type>";
553+
554+
string originalCode = @"namespace MyNamespace;
555+
public class MyClass
556+
{
557+
public void MyVoidMethod() { }
558+
}";
559+
560+
string expectedCode = @"namespace MyNamespace;
561+
public class MyClass
562+
{
563+
/// <summary>This is the MyVoidMethod summary.</summary>
564+
/// <exception cref=""System.NullReferenceException"">The null reference exception thrown by MyVoidMethod.</exception>
565+
/// <remarks>These are the MyVoidMethod remarks.</remarks>
566+
public void MyVoidMethod() { }
567+
}";
568+
569+
List<string> docFiles = new() { docFile };
570+
List<string> originalCodeFiles = new() { originalCode };
571+
Dictionary<string, string> expectedCodeFiles = new() { { docId, expectedCode } };
572+
StringTestData stringTestData = new(docFiles, originalCodeFiles, expectedCodeFiles, false);
573+
574+
return TestWithStringsAsync(stringTestData);
575+
}
576+
528577
[Fact]
529578
public Task Class_Field()
530579
{
@@ -722,6 +771,58 @@ public class MyClass
722771
return TestWithStringsAsync(stringTestData);
723772
}
724773

774+
[Fact]
775+
public Task Class_Property_Exception()
776+
{
777+
string docId = "T:MyNamespace.MyClass";
778+
779+
string docFile = @"<Type Name=""MyClass"" FullName=""MyNamespace.MyClass"">
780+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyClass"" />
781+
<AssemblyInfo>
782+
<AssemblyName>MyAssembly</AssemblyName>
783+
</AssemblyInfo>
784+
<Docs>
785+
<summary>To be added.</summary>
786+
<remarks>To be added.</remarks>
787+
</Docs>
788+
<Members>
789+
<Member MemberName=""MyGetSetProperty"">
790+
<MemberSignature Language=""DocId"" Value=""P:MyNamespace.MyClass.MyGetSetProperty"" />
791+
<MemberType>Property</MemberType>
792+
<Docs>
793+
<summary>This is the MyGetSetProperty summary.</summary>
794+
<value>This is the MyGetSetProperty value.</value>
795+
<remarks>These are the MyGetSetProperty remarks.</remarks>
796+
<exception cref=""T:System.NullReferenceException"">The null reference exception thrown by MyGetSetProperty.</exception>
797+
</Docs>
798+
</Member>
799+
</Members>
800+
</Type>";
801+
802+
string originalCode = @"namespace MyNamespace;
803+
public class MyClass
804+
{
805+
public double MyGetSetProperty { get; set; }
806+
}";
807+
808+
string expectedCode = @"namespace MyNamespace;
809+
public class MyClass
810+
{
811+
/// <summary>This is the MyGetSetProperty summary.</summary>
812+
/// <value>This is the MyGetSetProperty value.</value>
813+
/// <exception cref=""System.NullReferenceException"">The null reference exception thrown by MyGetSetProperty.</exception>
814+
/// <remarks>These are the MyGetSetProperty remarks.</remarks>
815+
public double MyGetSetProperty { get; set; }
816+
}";
817+
818+
List<string> docFiles = new() { docFile };
819+
List<string> originalCodeFiles = new() { originalCode };
820+
Dictionary<string, string> expectedCodeFiles = new() { { docId, expectedCode } };
821+
StringTestData stringTestData = new(docFiles, originalCodeFiles, expectedCodeFiles, false);
822+
823+
return TestWithStringsAsync(stringTestData);
824+
}
825+
725826
[Fact]
726827
public Task Class_Event()
727828
{
@@ -1015,6 +1116,124 @@ public class MyClass
10151116
return TestWithStringsAsync(stringTestData);
10161117
}
10171118

1119+
[Fact]
1120+
public Task Class_Do_Not_Backport_Inherited_Docs()
1121+
{
1122+
// In PortToDocs we find the base class and get the documentation if there's none in the child type.
1123+
// In PortToTripleSlash, we should not do that. We only backport what's found in the child type.
1124+
1125+
string interfaceDocId = "T:MyNamespace.MyInterface";
1126+
1127+
string classDocId = "T:MyNamespace.MyClass";
1128+
1129+
string interfaceDocFile = @"<Type Name=""MyInterface"" FullName=""MyNamespace.MyInterface"">
1130+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyInterface"" />
1131+
<AssemblyInfo>
1132+
<AssemblyName>MyAssembly</AssemblyName>
1133+
</AssemblyInfo>
1134+
<Docs>
1135+
<summary>This is the MyInterface summary.</summary>
1136+
<remarks>These are the MyInterface remarks.</remarks>
1137+
</Docs>
1138+
<Members>
1139+
<Member MemberName=""MyVoidMethod"">
1140+
<MemberSignature Language=""DocId"" Value=""M:MyNamespace.MyInterface.MyVoidMethod"" />
1141+
<Docs>
1142+
<summary>This is the MyInterface.MyVoidMethod summary.</summary>
1143+
<remarks>These are the MyInterface.MyVoidMethod remarks.</remarks>
1144+
</Docs>
1145+
</Member>
1146+
<Member MemberName=""MyGetSetProperty"">
1147+
<MemberSignature Language=""DocId"" Value=""P:MyNamespace.MyInterface.MyGetSetProperty"" />
1148+
<MemberType>Property</MemberType>
1149+
<Docs>
1150+
<summary>This is the MyInterface.MyGetSetProperty summary.</summary>
1151+
<value>This is the MyInterface.MyGetSetProperty value.</value>
1152+
<remarks>These are the MyInterface.MyGetSetProperty remarks.</remarks>
1153+
</Docs>
1154+
</Member>
1155+
</Members>
1156+
</Type>";
1157+
1158+
string classDocFile = @"<Type Name=""MyClass"" FullName=""MyNamespace.MyClass"">
1159+
<TypeSignature Language=""DocId"" Value=""T:MyNamespace.MyClass"" />
1160+
<AssemblyInfo>
1161+
<AssemblyName>MyAssembly</AssemblyName>
1162+
</AssemblyInfo>
1163+
<Base>
1164+
<BaseTypeName>MyNamespace.MyInterface</BaseTypeName>
1165+
</Base>
1166+
<Docs>
1167+
<summary>This is the MyClass summary.</summary>
1168+
<remarks>These are the MyClass remarks.</remarks>
1169+
</Docs>
1170+
<Members>
1171+
<Member MemberName=""MyVoidMethod"">
1172+
<MemberSignature Language=""DocId"" Value=""M:MyNamespace.MyClass.MyVoidMethod"" />
1173+
<Docs>
1174+
<summary>To be added.</summary>
1175+
<remarks>These are the MyClass.MyVoidMethod remarks.</remarks>
1176+
</Docs>
1177+
</Member>
1178+
<Member MemberName=""MyGetSetProperty"">
1179+
<MemberSignature Language=""DocId"" Value=""P:MyNamespace.MyClass.MyGetSetProperty"" />
1180+
<MemberType>Property</MemberType>
1181+
<Docs>
1182+
<summary>To be added.</summary>
1183+
<value>This is the MyClass.MyGetSetProperty value.</value>
1184+
<remarks>To be added.</remarks>
1185+
</Docs>
1186+
</Member>
1187+
</Members>
1188+
</Type>";
1189+
1190+
string interfaceOriginalCode = @"namespace MyNamespace;
1191+
public interface MyInterface
1192+
{
1193+
public void MyVoidMethod();
1194+
public double MyGetSetProperty { get; set; }
1195+
}";
1196+
1197+
string interfaceExpectedCode = @"namespace MyNamespace;
1198+
/// <summary>This is the MyInterface summary.</summary>
1199+
/// <remarks>These are the MyInterface remarks.</remarks>
1200+
public interface MyInterface
1201+
{
1202+
/// <summary>This is the MyInterface.MyVoidMethod summary.</summary>
1203+
/// <remarks>These are the MyInterface.MyVoidMethod remarks.</remarks>
1204+
public void MyVoidMethod();
1205+
/// <summary>This is the MyInterface.MyGetSetProperty summary.</summary>
1206+
/// <value>This is the MyInterface.MyGetSetProperty value.</value>
1207+
/// <remarks>These are the MyInterface.MyGetSetProperty remarks.</remarks>
1208+
public double MyGetSetProperty { get; set; }
1209+
}";
1210+
1211+
string classOriginalCode = @"namespace MyNamespace;
1212+
public class MyClass : MyInterface
1213+
{
1214+
public void MyVoidMethod() { }
1215+
public double MyGetSetProperty { get; set; }
1216+
}";
1217+
1218+
string classExpectedCode = @"namespace MyNamespace;
1219+
/// <summary>This is the MyClass summary.</summary>
1220+
/// <remarks>These are the MyClass remarks.</remarks>
1221+
public class MyClass : MyInterface
1222+
{
1223+
/// <remarks>These are the MyClass.MyVoidMethod remarks.</remarks>
1224+
public void MyVoidMethod() { }
1225+
/// <value>This is the MyClass.MyGetSetProperty value.</value>
1226+
public double MyGetSetProperty { get; set; }
1227+
}";
1228+
1229+
List<string> docFiles = new() { interfaceDocFile, classDocFile };
1230+
List<string> originalCodeFiles = new() { interfaceOriginalCode, classOriginalCode };
1231+
Dictionary<string, string> expectedCodeFiles = new() { { interfaceDocId, interfaceExpectedCode }, { classDocId, classExpectedCode } };
1232+
StringTestData data = new(docFiles, originalCodeFiles, expectedCodeFiles, false);
1233+
1234+
return TestWithStringsAsync(data);
1235+
}
1236+
10181237
[Fact]
10191238
public Task Full_Enum()
10201239
{
@@ -1107,6 +1326,7 @@ public Task Full_Class()
11071326
<Docs>
11081327
<summary>This is the MyVoidMethod summary.</summary>
11091328
<remarks>These are the MyVoidMethod remarks.</remarks>
1329+
<exception cref=""T:System.NullReferenceException"">The null reference exception thrown by MyVoidMethod.</exception>
11101330
</Docs>
11111331
</Member>
11121332
<Member MemberName=""MyIntMethod"">
@@ -1203,6 +1423,7 @@ public MyClass() { }
12031423
/// <remarks>These are the MyClass constructor remarks.</remarks>
12041424
public MyClass(int intParam) { }
12051425
/// <summary>This is the MyVoidMethod summary.</summary>
1426+
/// <exception cref=""System.NullReferenceException"">The null reference exception thrown by MyVoidMethod.</exception>
12061427
/// <remarks>These are the MyVoidMethod remarks.</remarks>
12071428
public void MyVoidMethod() { }
12081429
/// <summary>This is the MyIntMethod summary.</summary>

0 commit comments

Comments
 (0)