@@ -17,9 +17,10 @@ namespace UtfUnknown.Tests
1717
1818 public class CharsetDetectorTestBatch
1919 {
20+ private const string DIRECTORY_NAME = "TESTS" ;
2021 private static readonly string TESTS_ROOT = GetTestsPath ( ) ;
2122 private static readonly string DATA_ROOT = FindRootPath ( ) ;
22-
23+
2324 private StreamWriter _logWriter ;
2425
2526 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
@@ -47,12 +48,24 @@ private static string GetTestsPath()
4748 {
4849 var path = TestContext . CurrentContext . TestDirectory ;
4950
50- var directoryName = "TESTS" ;
51-
52- var index = path . IndexOf ( directoryName , StringComparison . CurrentCultureIgnoreCase ) ;
51+ if ( path . IndexOf ( DIRECTORY_NAME , StringComparison . CurrentCultureIgnoreCase ) >= 0 )
52+ {
53+ path = TruncatePath ( path ) ;
54+ }
55+ else
56+ {
57+ // fix for .netcoreapp2.1 - TestContext.CurrentContext.TestDirectory is bugged in NUnit under .netcoreapp2.1
58+ path = TestContext . CurrentContext . WorkDirectory ;
59+ path = TruncatePath ( path ) ;
60+ }
5361
54- path = path . Substring ( 0 , index + directoryName . Length ) ;
62+ return path ;
63+ }
5564
65+ private static string TruncatePath ( string path )
66+ {
67+ var index = path . IndexOf ( DIRECTORY_NAME , StringComparison . CurrentCultureIgnoreCase ) ;
68+ path = path . Substring ( 0 , index + DIRECTORY_NAME . Length ) ;
5669 return path ;
5770 }
5871
@@ -108,10 +121,8 @@ private void TestFile(string expectedCharset, string file)
108121 {
109122 var result = CharsetDetector . DetectFromFile ( file ) ;
110123 var detected = result . Detected ;
111- #if ! NETCOREAPP3_0
112- // because System.NotSupportedException in .net core 3.0 for Encoding
113- _logWriter . WriteLine ( string . Format ( "- {0} ({1}) -> {2}" , file , expectedCharset , JsonConvert . SerializeObject ( result ) ) ) ;
114- #endif // !NETCOREAPP3_0
124+
125+ _logWriter . WriteLine ( $ "- { file } ({ expectedCharset } ) -> { JsonConvert . SerializeObject ( result , Formatting . Indented , new EncodingJsonConverter ( ) ) } ") ;
115126 StringAssert . AreEqualIgnoringCase ( expectedCharset , detected . EncodingName ,
116127 $ "Charset detection failed for { file } . Expected: { expectedCharset } , detected: { detected . EncodingName } ({ detected . Confidence * 100.0f : 0.00############} % confidence)") ;
117128 Assert . NotNull ( detected . Encoding ) ;
0 commit comments