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
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PKISharp.WACS.Configuration;
using PKISharp.WACS.Plugins.InstallationPlugins;
using PKISharp.WACS.Services;
using PKISharp.WACS.UnitTests.Mock.Services;
using System;
namespace PKISharp.WACS.UnitTests.Tests.InstallationPluginTests
{
[TestClass]
public class ArgumentParserTests
{
private Mock.Services.LogService log;
public ArgumentParserTests() => log = new Mock.Services.LogService(true);
private string? TestScript(string parameters)
{
log = new Mock.Services.LogService(true);
var argParser = new ArgumentsParser(log,
new MockPluginService(log),
$"--scriptparameters {parameters} --verbose".Split(' '));
var argService = new ArgumentsService(log, argParser);
var args = argService.GetArguments<ScriptArguments>();
return args?.ScriptParameters;
}
[TestMethod]
[ExpectedException(typeof(Exception))]
public void Illegal() => TestScript("hello nonsense");
[TestMethod]
public void SingleParam() => Assert.AreEqual("hello", TestScript("hello"));
[TestMethod]
public void SingleParamExtra() => Assert.AreEqual("hello", TestScript("hello --verbose"));
[TestMethod]
public void MultipleParams() => Assert.AreEqual("hello world", TestScript("\"hello world\""));
[TestMethod]
public void MultipleParamsExtra() => Assert.AreEqual("hello world", TestScript("\"hello world\" --test --verbose"));
[TestMethod]
public void MultipleParamsDoubleQuotes() => Assert.AreEqual("\"hello world\"", TestScript("\"\"hello world\"\""));
[TestMethod]
public void MultipleParamsDoubleQuotesExtra() => Assert.AreEqual("\"hello world\"", TestScript("\"\"hello world\"\" --test --verbose"));
[TestMethod]
public void MultipleParamsSingleQuotes() => Assert.AreEqual("'hello world'", TestScript("\"'hello world'\""));
[TestMethod]
public void EmbeddedKeySingle() => Assert.AreEqual("'hello --world'", TestScript("\"'hello --world'\""));
[TestMethod]
public void EmbeddedKeyDouble() => Assert.AreEqual("\"hello --world\"", TestScript("\"\"hello --world\"\""));
[TestMethod]
public void Real() => Assert.AreEqual("'{CertThumbprint}' 'IIS,SMTP,IMAP' '1' '{CacheFile}' '{CachePassword}' '{CertFriendlyName}'", TestScript("\"'{CertThumbprint}' 'IIS,SMTP,IMAP' '1' '{CacheFile}' '{CachePassword}' '{CertFriendlyName}'\""));
}
}
|