-
Notifications
You must be signed in to change notification settings - Fork 2
/
ParatextDataConnectionTests.cs
101 lines (93 loc) · 3.45 KB
/
ParatextDataConnectionTests.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
101
using System.ComponentModel;
using System.Configuration;
using System.Reflection;
using Paranext.DataProvider.ParatextUtils;
using Paratext.Data;
using PtxUtils;
namespace TestParanextDataProvider
{
internal class ParatextDataConnectionTests
{
// Work around a known issue where NUnit doesn't pick up config files
// https://github.com/nunit/nunit3-vs-adapter/issues/356
private static void EnsureIcuConfigFileIsInPlace()
{
string appConfigFile = ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.None)
.FilePath;
string? appConfigDirectory = Path.GetDirectoryName(appConfigFile);
string icuConfigFile = Path.Join(appConfigDirectory, "icu.net.dll.config");
if (!File.Exists(icuConfigFile))
{
// It's a bit hacky to hard code the config file here, but there isn't a great
// source that we can reliably get to from within a test.
File.WriteAllText(
icuConfigFile,
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
<dllmap os=""!windows,osx"" dll=""libdl.so"" target=""libdl.so.2"" />
<dllmap os=""osx"" dll=""libdl.so"" target=""libdl.dylib""/>
</configuration>"
);
}
}
/// <summary>
/// This test is to try figure out if ParatextData will work on Linux and Mac.
/// It may be removed in the future for a more useful test.
/// </summary>
[Test]
public void LoadPackagedWEB_LoadsProject()
{
// This functionality doesn't work on macOS for now
if (OperatingSystem.IsMacOS())
return;
Alert.Implementation = new DummyAlert();
EnsureIcuConfigFileIsInPlace();
Console.WriteLine(Assembly.GetExecutingAssembly().Location);
ParatextGlobals.Initialize("assets");
ScrText scrText = ScrTextCollection.Find("WEB");
Assert.Multiple(() =>
{
Assert.That(scrText, Is.Not.Null);
Assert.That(scrText.Name, Is.EqualTo("WEB"));
Assert.That(scrText.Settings.BooksPresentSet.Count, Is.EqualTo(83));
});
}
#region DummyAlert class
private sealed class DummyAlert : Alert
{
protected override AlertResult ShowInternal(
IComponent? owner,
string text,
string caption,
AlertButtons alertButtons,
AlertLevel alertLevel,
AlertDefaultButton defaultButton,
bool showInTaskbar
)
{
if (text.Contains("unable to find a language definition file for English"))
return AlertResult.Positive;
Assert.Fail("Unexpected dialog box:\n" + text);
return AlertResult.Negative;
}
protected override void ShowLaterInternal(
string text,
string caption,
AlertLevel alertLevel
)
{
ShowInternal(
null,
text,
caption,
AlertButtons.Ok,
alertLevel,
AlertDefaultButton.Button1,
false
);
}
}
#endregion
}
}