/
LanguageUnitTests.cs
178 lines (172 loc) · 9.16 KB
/
LanguageUnitTests.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using InstallerLib;
using System.IO;
using dotNetUnitTestsRunner;
using System.Threading;
using System.Xml;
using System.Globalization;
namespace dotNetInstallerUnitTests
{
[TestFixture]
public class LanguageUnitTests
{
[Test]
public void TestComponentLcid()
{
// a configuration with one component
ConfigFile configFile = new ConfigFile();
SetupConfiguration setupConfiguration = new SetupConfiguration();
configFile.Children.Add(setupConfiguration);
// current lcid
string currentLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdCurrentLcid = new ComponentCmd();
cmdCurrentLcid.os_filter_lcid = CultureInfo.CurrentCulture.LCID.ToString();
Console.WriteLine("Current lcid: {0}", cmdCurrentLcid.os_filter_lcid);
cmdCurrentLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", currentLcidFilename);
cmdCurrentLcid.required_install = true;
setupConfiguration.Children.Add(cmdCurrentLcid);
// empty lcid
string emptyLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdEmptyLcid = new ComponentCmd();
cmdEmptyLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", emptyLcidFilename);
cmdEmptyLcid.required_install = true;
setupConfiguration.Children.Add(cmdEmptyLcid);
// another lcid
string anotherLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdAnotherLcid = new ComponentCmd();
cmdAnotherLcid.os_filter_lcid = (CultureInfo.CurrentCulture.LCID + 1).ToString();
Console.WriteLine("Another lcid: {0}", cmdAnotherLcid.os_filter_lcid);
cmdAnotherLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", anotherLcidFilename);
cmdAnotherLcid.required_install = true;
setupConfiguration.Children.Add(cmdAnotherLcid);
// save config file
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
// execute dotNetInstaller
Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
Assert.IsTrue(File.Exists(currentLcidFilename));
Assert.IsTrue(File.Exists(emptyLcidFilename));
Assert.IsFalse(File.Exists(anotherLcidFilename));
File.Delete(currentLcidFilename);
File.Delete(emptyLcidFilename);
File.Delete(configFilename);
}
[Test]
public void TestConfigurationLcid()
{
// a configuration with one component
ConfigFile configFile = new ConfigFile();
// current lcid setup configuration
SetupConfiguration currentLcidConfiguration = new SetupConfiguration();
currentLcidConfiguration.lcid_filter = CultureInfo.CurrentCulture.LCID.ToString();
configFile.Children.Add(currentLcidConfiguration);
string currentLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdCurrentLcid = new ComponentCmd();
Console.WriteLine("Current lcid: {0}", currentLcidConfiguration.lcid_filter);
cmdCurrentLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", currentLcidFilename);
cmdCurrentLcid.required_install = true;
currentLcidConfiguration.Children.Add(cmdCurrentLcid);
// empty lcid setup configuration
SetupConfiguration emptyLcidConfiguration = new SetupConfiguration();
configFile.Children.Add(emptyLcidConfiguration);
string emptyLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdEmptyLcid = new ComponentCmd();
cmdEmptyLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", emptyLcidFilename);
cmdEmptyLcid.required_install = true;
emptyLcidConfiguration.Children.Add(cmdEmptyLcid);
// another lcid setup configuration
SetupConfiguration anotherLcidConfiguration = new SetupConfiguration();
anotherLcidConfiguration.lcid_filter = (CultureInfo.CurrentCulture.LCID + 1).ToString();
configFile.Children.Add(anotherLcidConfiguration);
string anotherLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
ComponentCmd cmdAnotherLcid = new ComponentCmd();
Console.WriteLine("Another lcid: {0}", anotherLcidConfiguration.lcid_filter);
cmdAnotherLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", anotherLcidFilename);
cmdAnotherLcid.required_install = true;
anotherLcidConfiguration.Children.Add(cmdAnotherLcid);
// save config file
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
// execute dotNetInstaller
Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
Assert.IsTrue(File.Exists(currentLcidFilename));
Assert.IsTrue(File.Exists(emptyLcidFilename));
Assert.IsFalse(File.Exists(anotherLcidFilename));
File.Delete(currentLcidFilename);
File.Delete(emptyLcidFilename);
File.Delete(configFilename);
}
[Test]
public void TestOsLangID()
{
ConfigFile configFile = new ConfigFile();
SetupConfiguration configuration = new SetupConfiguration();
configFile.Children.Add(configuration);
ComponentCmd cmd = new ComponentCmd();
cmd.command = "cmd.exe /C exit /b #OSLANGID";
cmd.required_install = true;
configuration.Children.Add(cmd);
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
Assert.AreEqual(CultureInfo.CurrentCulture.LCID, dotNetInstallerExeUtils.Run(configFilename));
File.Delete(configFilename);
}
[Test]
public void TestConfigNoLangID()
{
ConfigFile configFile = new ConfigFile();
SetupConfiguration configuration = new SetupConfiguration();
configFile.Children.Add(configuration);
ComponentCmd cmd = new ComponentCmd();
cmd.command = "cmd.exe /C exit /b #LANGID";
cmd.required_install = true;
configuration.Children.Add(cmd);
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
Assert.AreEqual(CultureInfo.CurrentCulture.LCID, dotNetInstallerExeUtils.Run(configFilename));
File.Delete(configFilename);
}
[Test]
public void TestConfigLangID()
{
ConfigFile configFile = new ConfigFile();
SetupConfiguration configuration = new SetupConfiguration();
configFile.Children.Add(configuration);
ComponentCmd cmd = new ComponentCmd();
cmd.command = "cmd.exe /C exit /b #LANGID";
cmd.required_install = true;
configuration.language_id = "1234";
configuration.Children.Add(cmd);
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
Assert.AreEqual(1234, dotNetInstallerExeUtils.Run(configFilename));
File.Delete(configFilename);
}
[Test]
public void TestConfigLanguage()
{
ConfigFile configFile = new ConfigFile();
SetupConfiguration configuration = new SetupConfiguration();
configFile.Children.Add(configuration);
ComponentCmd cmd = new ComponentCmd();
cmd.command = "cmd.exe /C exit /b #LANGUAGE";
cmd.required_install = true;
configuration.language_id = "1234";
configuration.language = "3456";
configuration.Children.Add(cmd);
string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFilename);
configFile.SaveAs(configFilename);
Assert.AreEqual(3456, dotNetInstallerExeUtils.Run(configFilename));
File.Delete(configFilename);
}
}
}