-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExecCommandConfigureWindowsTests.fs
More file actions
175 lines (158 loc) · 4.82 KB
/
ExecCommandConfigureWindowsTests.fs
File metadata and controls
175 lines (158 loc) · 4.82 KB
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
module Fli.Tests.ExecContext.ExecCommandConfigureWindowsTests
open NUnit.Framework
open FsUnit
open Fli
open System
open System.Collections.Generic
open System.Text
[<Test>]
[<Platform("Win")>]
let ``Check FileName in ProcessStartInfo Exec program`` () =
cli { Exec "cmd.exe" }
|> Command.buildProcess
|> _.FileName
|> should equal "cmd.exe"
[<Test>]
[<Platform("Win")>]
let ``Check Arguments in ProcessStartInfo with Arguments`` () =
cli {
Exec "cmd.exe"
Arguments "-c echo Hello World!"
}
|> Command.buildProcess
|> _.Arguments
|> should equal "-c echo Hello World!"
#if NET
[<Test>]
[<Platform("Win")>]
let ``Check Arguments in ProcessStartInfo with ArgumentList`` () =
cli {
Exec "cmd.exe"
Arguments [ "-c"; "echo Hello World!" ]
}
|> Command.buildProcess
|> _.ArgumentList
:> seq<_>
|> should
equal
(seq {
"-c"
"echo Hello World!"
})
#endif
[<Test>]
[<Platform("Win")>]
let ``Check WorkingDirectory in ProcessStartInfo with WorkingDirectory`` () =
cli {
Exec "cmd.exe"
WorkingDirectory @"C:\Users"
}
|> Command.buildProcess
|> _.WorkingDirectory
|> should equal @"C:\Users"
[<Test>]
[<Platform("Win")>]
let ``Check WindowStyle in ProcessStartInfo with WorkingDirectory`` () =
cli {
Exec "cmd.exe"
WindowStyle Normal
}
|> Command.buildProcess
|> _.WindowStyle
|> should equal Diagnostics.ProcessWindowStyle.Normal
[<Test>]
[<Platform("Win")>]
let ``Check Verb in ProcessStartInfo with Verb`` () =
cli {
Exec "cmd.exe"
Verb "open"
}
|> Command.buildProcess
|> _.Verb
|> should equal "open"
[<Test>]
[<Platform("Win")>]
let ``Check UserName in ProcessStartInfo with Username`` () =
cli {
Exec "cmd.exe"
Username "admin"
}
|> Command.buildProcess
|> _.UserName
|> should equal "admin"
[<Test>]
[<Platform("Win")>]
let ``Check Domain, UserName, Password in ProcessStartInfo with Credentials for windows (overwrites Username)`` () =
let config =
cli {
Exec "cmd.exe"
Username "admin"
Credentials("domain", "user", "password")
}
|> Command.buildProcess
config.Domain |> should equal "domain"
config.UserName |> should equal "user"
config.Password |> should not' (equal "password") // stored as SecureString
[<Test>]
[<Platform("Win")>]
let ``Check Environment in ProcessStartInfo with single environment variable`` () =
cli {
Exec "cmd.exe"
EnvironmentVariable("Fli", "test")
}
|> Command.buildProcess
|> _.Environment.Contains(KeyValuePair("Fli", "test"))
|> should be True
[<Test>]
[<Platform("Win")>]
let ``Check Environment in ProcessStartInfo with multiple environment variables`` () =
let config =
cli {
Exec "cmd.exe"
EnvironmentVariables [ ("Fli", "test"); ("Fli.Test", "test") ]
}
|> Command.buildProcess
config.Environment.Contains(KeyValuePair("Fli", "test")) |> should be True
config.Environment.Contains(KeyValuePair("Fli.Test", "test")) |> should be True
[<Test>]
[<Platform("Win")>]
let ``Check StandardOutputEncoding & StandardErrorEncoding with setting Encoding`` () =
let config =
cli {
Exec "cmd.exe"
Encoding Encoding.UTF8
}
|> Command.buildProcess
config.StandardOutputEncoding |> should equal Encoding.UTF8
config.StandardErrorEncoding |> should equal Encoding.UTF8
[<Test>]
[<Platform("Win")>]
let ``Check all possible values in ProcessStartInfo for windows`` () =
let config =
cli {
Exec "cmd.exe"
Arguments "--help"
Input "Test"
Output @"C:\Users\test.txt"
WorkingDirectory @"C:\Users"
Verb "open"
Username "admin"
Credentials("domain", "admin", "password")
EnvironmentVariable("Fli", "test")
EnvironmentVariables [ ("Fli.Test", "test") ]
Encoding Encoding.UTF8
WindowStyle Normal
}
|> Command.buildProcess
config.FileName |> should equal "cmd.exe"
config.Arguments |> should equal "--help"
config.WorkingDirectory |> should equal @"C:\Users"
config.Verb |> should equal "open"
config.Domain |> should equal "domain"
config.UserName |> should equal "admin"
config.Password |> should not' (equal "password")
config.Environment.Contains(KeyValuePair("Fli", "test")) |> should be True
config.Environment.Contains(KeyValuePair("Fli.Test", "test")) |> should be True
config.StandardOutputEncoding |> should equal Encoding.UTF8
config.StandardErrorEncoding |> should equal Encoding.UTF8
config.WindowStyle |> should equal Diagnostics.ProcessWindowStyle.Normal