-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tests.cs
100 lines (86 loc) · 4.09 KB
/
Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Manx_Search_Data.TestData;
using Manx_Search_Data.TestUtil;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace Manx_Search_Data
{
/// <summary>
/// These test the aggregate of all definitions
/// </summary>
[TestFixture]
public class Tests
{
readonly Document[] documents = Documents.AllDocuments.ToArray();
[Test]
public void AllCsvFilesAreUsed()
{
List<string> paths = FileListing.GetCsvPaths();
List<string> openSourcePaths = documents.OfType<OpenSourceDocument>().Select(x => x.FullCsvPath).ToList();
var unusedPaths = paths.Except(openSourcePaths);
Assert.That(unusedPaths, Is.Empty, "Some files were unused");
}
[Test]
public void AllNameAttributesAreDistinct()
{
List<string> names = documents.Select(x => x.Name).ToList();
List<string> distinctNames = names.Distinct().ToList();
CollectionAssert.AreEquivalent(names, distinctNames, $"All '{nameof(Document.Name)}s should be distinct");
}
[Test]
public void AllIdentifiersAreDistinct()
{
List<string> ids = documents.Select(x => x.Ident).ToList();
List<string> distinctIds = ids.Distinct().ToList();
CollectionAssert.AreEquivalent(ids, distinctIds, $"All '{nameof(Document.Ident)}s should be distinct");
}
[Test]
public void AllContentsAreDistinct()
{
// PERF: This is lazy - take the first 100 lines of each document, convert to string and hash
Dictionary<string, string> contents = new Dictionary<string, string>();
foreach (var d in Documents.GetOpenSourceDocuments().Cast<OpenSourceDocument>().Select(x => new { Doc = x, File = x.LoadLocalFile() }))
{
var content = string.Join("\n", d.File.Take(100).Select(x => x.English + "|" + x.Manx));
if (contents.ContainsKey(content))
{
Assert.Fail($"{d.Doc.FullCsvPath} and {contents[content]} have the same content");
}
else
{
contents.Add(content, d.Doc.FullCsvPath);
}
}
}
[Theory]
public void InvalidPathsAreCaught()
{
// #609
AssertInvalid("OpenData/secular printed material 1750-1900/O Yee gloyroil, Hood�s ta shin geam. /document.csv");
AssertValid("OpenData/secular printed material 1750-1900/O Yee gloyroil, Hood�s ta shin geam/document.csv");
AssertInvalid("OpenData/secular printed material 1750-1900/The Exiles of Mona; �Dy Darragh yn Laa� /document.csv");
AssertValid("OpenData/secular printed material 1750-1900/The Exiles of Mona �Dy Darragh yn Laa�/document.csv");
AssertInvalid("OpenData/secular printed material 1750-1900/Yn Arrane-Caggee-Anmormonagh /document.csv");
AssertValid("OpenData/secular printed material 1750-1900/Yn Arrane-Caggee-Anmormonagh/document.csv");
AssertInvalid("OpenData/secular printed material 1750-1900/Closing address to the Manx Readings and Concert./document.csv");
AssertValid("OpenData/secular printed material 1750-1900/Closing address to the Manx Readings and Concert/document.csv");
// #1083
AssertInvalid("OpenData/miscellaneous religious printed 1600 - 1900 /Carval Noo Paul/document.csv");
}
[Theory]
public void FilePathIsValidForWindows()
{
var paths = FileListing.GetJsonPaths();
var invalidPaths = paths.Where(x => !InvalidPathChecker.IsValid(x));
Assert.That(invalidPaths, Is.Empty);
}
private static void AssertInvalid(string path)
{
Assert.That(!InvalidPathChecker.IsValid(path), $"'{path}' should be invalid");
}
private static void AssertValid(string path)
{
Assert.That(InvalidPathChecker.IsValid(path), $"'{path}' should be valid");
}
}
}