| | 1 | | using ValidateLib.Encoding.Detection; |
| | 2 | |
|
| | 3 | | namespace EncodingDetectorTests |
| | 4 | | { |
| | 5 | | public class EncodingTests |
| | 6 | | { |
| | 7 | | private readonly string testFilesPath; |
| | 8 | |
|
| 1 | 9 | | public EncodingTests() |
| 1 | 10 | | { |
| 1 | 11 | | string projectDirectory = GetProjectDirectory(); |
| 1 | 12 | | testFilesPath = Path.Combine(projectDirectory, "TestFiles"); |
| 1 | 13 | | } |
| | 14 | | static string GetProjectDirectory() |
| 1 | 15 | | { |
| 1 | 16 | | string? currentDirectory = Directory.GetCurrentDirectory(); |
| | 17 | |
|
| 1 | 18 | | while (!string.IsNullOrEmpty(currentDirectory)) |
| 1 | 19 | | { |
| 1 | 20 | | string[] projectFiles = Directory.GetFiles(currentDirectory, "*.csproj"); |
| | 21 | |
|
| 1 | 22 | | if (projectFiles.Length > 0) |
| 1 | 23 | | return currentDirectory; |
| 1 | 24 | | currentDirectory = Directory.GetParent(currentDirectory)?.FullName; |
| 1 | 25 | | } |
| | 26 | |
|
| 0 | 27 | | throw new Exception("Could not find project directory."); |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | |
|
| | 31 | | [Fact] |
| | 32 | | public void IsUtf8ShouldPass() |
| 1 | 33 | | { |
| | 34 | |
|
| 1 | 35 | | string testFilePath = Path.Combine(testFilesPath, "Utf8.txt"); |
| 1 | 36 | | Assert.True(EncodingDetector.IsUtf8(testFilePath)); |
| | 37 | |
|
| 1 | 38 | | } |
| | 39 | |
|
| | 40 | | [Fact] |
| | 41 | | public void IsNotUtf8ShouldNotPass() |
| 1 | 42 | | { |
| | 43 | |
|
| 1 | 44 | | string testFilePath = Path.Combine(testFilesPath, "NotUtf8.txt"); |
| 1 | 45 | | Assert.False(EncodingDetector.IsUtf8(testFilePath)); |
| | 46 | |
|
| 1 | 47 | | } |
| | 48 | | } |
| | 49 | | } |