| | 1 | | using ValidateLib.Metadata.ParsingAndValidation; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.TableCompatibility; |
| | 4 | |
|
| | 5 | | namespace CompatibilityCheckerTests |
| | 6 | | { |
| | 7 | | public class PositiveTests |
| | 8 | | { |
| | 9 | | public readonly string testFilesDirectory; |
| 1 | 10 | | public PositiveTests() |
| 1 | 11 | | { |
| 1 | 12 | | testFilesDirectory = Path.Combine(GetProjectDirectory(), "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 | | [Fact] |
| | 30 | | public void SimpleTestNamesMatch() |
| 1 | 31 | | { |
| 1 | 32 | | var testNumber = "06"; |
| 1 | 33 | | var testFilePath1 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor1.json"); |
| 1 | 34 | | var testFilePath2 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor2.json"); |
| 1 | 35 | | var warnings = new List<Warning>(); |
| | 36 | |
|
| 1 | 37 | | var tableDescriptor1 = MetadataParserValidator.ProcessTable( |
| 1 | 38 | | warnings, |
| 1 | 39 | | testFilePath1 |
| 1 | 40 | | ); |
| | 41 | |
|
| 1 | 42 | | var tableDescriptor2 = MetadataParserValidator.ProcessTable( |
| 1 | 43 | | warnings, |
| 1 | 44 | | testFilePath2 |
| 1 | 45 | | ); |
| 1 | 46 | | CompatibilityChecker cc = new CompatibilityChecker(); |
| 1 | 47 | | bool result = cc.AreTableDescriptionsCompatible(tableDescriptor1, tableDescriptor2); |
| | 48 | |
|
| 1 | 49 | | Assert.True(result); |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | [Fact] |
| | 53 | | public void SimpleTestTitlesMatchUndLang() |
| 1 | 54 | | { |
| 1 | 55 | | var testNumber = "07"; |
| 1 | 56 | | var testFilePath1 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor1.json"); |
| 1 | 57 | | var testFilePath2 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor2.json"); |
| 1 | 58 | | var warnings = new List<Warning>(); |
| | 59 | |
|
| 1 | 60 | | var tableDescriptor1 = MetadataParserValidator.ProcessTable( |
| 1 | 61 | | warnings, |
| 1 | 62 | | testFilePath1 |
| 1 | 63 | | ); |
| | 64 | |
|
| 1 | 65 | | var tableDescriptor2 = MetadataParserValidator.ProcessTable( |
| 1 | 66 | | warnings, |
| 1 | 67 | | testFilePath2 |
| 1 | 68 | | ); |
| 1 | 69 | | CompatibilityChecker cc = new CompatibilityChecker(); |
| 1 | 70 | | bool result = cc.AreTableDescriptionsCompatible(tableDescriptor1, tableDescriptor2); |
| | 71 | |
|
| 1 | 72 | | Assert.True(result); |
| 1 | 73 | | } |
| | 74 | |
|
| | 75 | | [Fact] |
| | 76 | | public void SimpleTestTitlesMatchEnLang() |
| 1 | 77 | | { |
| 1 | 78 | | var testNumber = "08"; |
| 1 | 79 | | var testFilePath1 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor1.json"); |
| 1 | 80 | | var testFilePath2 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor2.json"); |
| 1 | 81 | | var warnings = new List<Warning>(); |
| | 82 | |
|
| 1 | 83 | | var tableDescriptor1 = MetadataParserValidator.ProcessTable( |
| 1 | 84 | | warnings, |
| 1 | 85 | | testFilePath1 |
| 1 | 86 | | ); |
| | 87 | |
|
| 1 | 88 | | var tableDescriptor2 = MetadataParserValidator.ProcessTable( |
| 1 | 89 | | warnings, |
| 1 | 90 | | testFilePath2 |
| 1 | 91 | | ); |
| 1 | 92 | | CompatibilityChecker cc = new CompatibilityChecker(); |
| 1 | 93 | | bool result = cc.AreTableDescriptionsCompatible(tableDescriptor1, tableDescriptor2); |
| | 94 | |
|
| 1 | 95 | | Assert.True(result); |
| 1 | 96 | | } |
| | 97 | |
|
| | 98 | | [Fact] |
| | 99 | | public void SimpleTestTitlesMatchUndMatchesAll() |
| 1 | 100 | | { |
| 1 | 101 | | var testNumber = "09"; |
| 1 | 102 | | var testFilePath1 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor1.json"); |
| 1 | 103 | | var testFilePath2 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor2.json"); |
| 1 | 104 | | var warnings = new List<Warning>(); |
| | 105 | |
|
| 1 | 106 | | var tableDescriptor1 = MetadataParserValidator.ProcessTable( |
| 1 | 107 | | warnings, |
| 1 | 108 | | testFilePath1 |
| 1 | 109 | | ); |
| | 110 | |
|
| 1 | 111 | | var tableDescriptor2 = MetadataParserValidator.ProcessTable( |
| 1 | 112 | | warnings, |
| 1 | 113 | | testFilePath2 |
| 1 | 114 | | ); |
| 1 | 115 | | CompatibilityChecker cc = new CompatibilityChecker(); |
| 1 | 116 | | bool result = cc.AreTableDescriptionsCompatible(tableDescriptor1, tableDescriptor2); |
| | 117 | |
|
| 1 | 118 | | Assert.True(result); |
| 1 | 119 | | } |
| | 120 | |
|
| | 121 | | [Fact] |
| | 122 | | public void FindingIntersectionInMoreComplexTitlesStructures() |
| 1 | 123 | | { |
| 1 | 124 | | var testNumber = "09"; |
| 1 | 125 | | var testFilePath1 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor1.json"); |
| 1 | 126 | | var testFilePath2 = Path.Combine(testFilesDirectory, "test" + testNumber, "descriptor2.json"); |
| 1 | 127 | | var warnings = new List<Warning>(); |
| | 128 | |
|
| 1 | 129 | | var tableDescriptor1 = MetadataParserValidator.ProcessTable( |
| 1 | 130 | | warnings, |
| 1 | 131 | | testFilePath1 |
| 1 | 132 | | ); |
| | 133 | |
|
| 1 | 134 | | var tableDescriptor2 = MetadataParserValidator.ProcessTable( |
| 1 | 135 | | warnings, |
| 1 | 136 | | testFilePath2 |
| 1 | 137 | | ); |
| 1 | 138 | | CompatibilityChecker cc = new CompatibilityChecker(); |
| 1 | 139 | | bool result = cc.AreTableDescriptionsCompatible(tableDescriptor1, tableDescriptor2); |
| | 140 | |
|
| 1 | 141 | | Assert.True(result); |
| 1 | 142 | | } |
| | 143 | | } |
| | 144 | | } |