@@ -47,19 +47,19 @@ public AndConstraint<CommandResultAssertions> HaveStdOut()
47
47
48
48
public AndConstraint < CommandResultAssertions > HaveStdOut ( string expectedOutput )
49
49
{
50
- Execute . Assertion . ForCondition ( _commandResult . StdOut . Equals ( expectedOutput , StringComparison . Ordinal ) )
50
+ Execute . Assertion . ForCondition ( _commandResult . StdOut is not null && _commandResult . StdOut . Equals ( expectedOutput , StringComparison . Ordinal ) )
51
51
. FailWith ( AppendDiagnosticsTo ( $ "Command did not output with Expected Output. Expected: { expectedOutput } ") ) ;
52
52
return new AndConstraint < CommandResultAssertions > ( this ) ;
53
53
}
54
54
55
55
public AndConstraint < CommandResultAssertions > HaveStdOutContaining ( string pattern )
56
56
{
57
- Execute . Assertion . ForCondition ( _commandResult . StdOut . Contains ( pattern ) )
57
+ Execute . Assertion . ForCondition ( _commandResult . StdOut is not null && _commandResult . StdOut . Contains ( pattern ) )
58
58
. FailWith ( AppendDiagnosticsTo ( $ "The command output did not contain expected result: { pattern } { Environment . NewLine } ") ) ;
59
59
return new AndConstraint < CommandResultAssertions > ( this ) ;
60
60
}
61
61
62
- public AndConstraint < CommandResultAssertions > HaveStdOutContaining ( Func < string , bool > predicate , string description = "" )
62
+ public AndConstraint < CommandResultAssertions > HaveStdOutContaining ( Func < string ? , bool > predicate , string description = "" )
63
63
{
64
64
Execute . Assertion . ForCondition ( predicate ( _commandResult . StdOut ) )
65
65
. FailWith ( AppendDiagnosticsTo ( $ "The command output did not contain expected result: { description } { Environment . NewLine } ") ) ;
@@ -68,7 +68,7 @@ public AndConstraint<CommandResultAssertions> HaveStdOutContaining(Func<string,
68
68
69
69
public AndConstraint < CommandResultAssertions > NotHaveStdOutContaining ( string pattern , string [ ] ? ignoredPatterns = null )
70
70
{
71
- string filteredStdOut = _commandResult . StdOut ;
71
+ string filteredStdOut = _commandResult . StdOut ?? string . Empty ;
72
72
if ( ignoredPatterns != null && ignoredPatterns . Length > 0 )
73
73
{
74
74
foreach ( var ignoredPattern in ignoredPatterns )
@@ -88,7 +88,7 @@ public AndConstraint<CommandResultAssertions> NotHaveStdOutContaining(string pat
88
88
89
89
public AndConstraint < CommandResultAssertions > HaveStdOutContainingIgnoreSpaces ( string pattern )
90
90
{
91
- string commandResultNoSpaces = _commandResult . StdOut . Replace ( " " , "" ) ;
91
+ string commandResultNoSpaces = _commandResult . StdOut ? . Replace ( " " , "" ) ?? string . Empty ;
92
92
93
93
Execute . Assertion
94
94
. ForCondition ( commandResultNoSpaces . Contains ( pattern ) )
@@ -99,21 +99,21 @@ public AndConstraint<CommandResultAssertions> HaveStdOutContainingIgnoreSpaces(s
99
99
100
100
public AndConstraint < CommandResultAssertions > HaveStdOutContainingIgnoreCase ( string pattern )
101
101
{
102
- Execute . Assertion . ForCondition ( _commandResult . StdOut . IndexOf ( pattern , StringComparison . OrdinalIgnoreCase ) >= 0 )
102
+ Execute . Assertion . ForCondition ( _commandResult . StdOut is not null && _commandResult . StdOut . IndexOf ( pattern , StringComparison . OrdinalIgnoreCase ) >= 0 )
103
103
. FailWith ( AppendDiagnosticsTo ( $ "The command output did not contain expected result (ignoring case): { pattern } { Environment . NewLine } ") ) ;
104
104
return new AndConstraint < CommandResultAssertions > ( this ) ;
105
105
}
106
106
107
107
public AndConstraint < CommandResultAssertions > HaveStdOutMatching ( string pattern , RegexOptions options = RegexOptions . None )
108
108
{
109
- Execute . Assertion . ForCondition ( Regex . Match ( _commandResult . StdOut , pattern , options ) . Success )
109
+ Execute . Assertion . ForCondition ( Regex . Match ( _commandResult . StdOut ?? string . Empty , pattern , options ) . Success )
110
110
. FailWith ( AppendDiagnosticsTo ( $ "Matching the command output failed. Pattern: { pattern } { Environment . NewLine } ") ) ;
111
111
return new AndConstraint < CommandResultAssertions > ( this ) ;
112
112
}
113
113
114
114
public AndConstraint < CommandResultAssertions > NotHaveStdOutMatching ( string pattern , RegexOptions options = RegexOptions . None )
115
115
{
116
- Execute . Assertion . ForCondition ( ! Regex . Match ( _commandResult . StdOut , pattern , options ) . Success )
116
+ Execute . Assertion . ForCondition ( ! Regex . Match ( _commandResult . StdOut ?? string . Empty , pattern , options ) . Success )
117
117
. FailWith ( AppendDiagnosticsTo ( $ "The command output matched a pattern it should not have. Pattern: { pattern } { Environment . NewLine } ") ) ;
118
118
return new AndConstraint < CommandResultAssertions > ( this ) ;
119
119
}
@@ -127,22 +127,22 @@ public AndConstraint<CommandResultAssertions> HaveStdErr()
127
127
128
128
public AndConstraint < CommandResultAssertions > HaveStdErr ( string expectedOutput )
129
129
{
130
- Execute . Assertion . ForCondition ( _commandResult . StdErr . Equals ( expectedOutput , StringComparison . Ordinal ) )
130
+ Execute . Assertion . ForCondition ( _commandResult . StdErr is not null && _commandResult . StdErr . Equals ( expectedOutput , StringComparison . Ordinal ) )
131
131
. FailWith ( AppendDiagnosticsTo ( $ "Command did not output the expected output to StdErr.{ Environment . NewLine } Expected: { expectedOutput } { Environment . NewLine } Actual: { _commandResult . StdErr } ") ) ;
132
132
return new AndConstraint < CommandResultAssertions > ( this ) ;
133
133
}
134
134
135
135
public AndConstraint < CommandResultAssertions > HaveStdErrContaining ( string pattern )
136
136
{
137
- Execute . Assertion . ForCondition ( _commandResult . StdErr . Contains ( pattern ) )
137
+ Execute . Assertion . ForCondition ( _commandResult . StdErr is not null && _commandResult . StdErr . Contains ( pattern ) )
138
138
. FailWith ( AppendDiagnosticsTo ( $ "The command error output did not contain expected result: { pattern } { Environment . NewLine } ") ) ;
139
139
return new AndConstraint < CommandResultAssertions > ( this ) ;
140
140
}
141
141
142
142
public AndConstraint < CommandResultAssertions > HaveStdErrContainingOnce ( string pattern )
143
143
{
144
- var lines = _commandResult . StdErr . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
145
- var matchingLines = lines . Where ( line => line . Contains ( pattern ) ) . Count ( ) ;
144
+ var lines = _commandResult . StdErr ? . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
145
+ var matchingLines = lines ? . Where ( line => line . Contains ( pattern ) ) . Count ( ) ;
146
146
Execute . Assertion . ForCondition ( matchingLines == 0 )
147
147
. FailWith ( AppendDiagnosticsTo ( $ "The command error output did not contain expected result: { pattern } { Environment . NewLine } ") ) ;
148
148
Execute . Assertion . ForCondition ( matchingLines != 1 )
@@ -152,14 +152,14 @@ public AndConstraint<CommandResultAssertions> HaveStdErrContainingOnce(string pa
152
152
153
153
public AndConstraint < CommandResultAssertions > NotHaveStdErrContaining ( string pattern )
154
154
{
155
- Execute . Assertion . ForCondition ( ! _commandResult . StdErr . Contains ( pattern ) )
155
+ Execute . Assertion . ForCondition ( _commandResult . StdErr is not null && ! _commandResult . StdErr . Contains ( pattern ) )
156
156
. FailWith ( AppendDiagnosticsTo ( $ "The command error output contained a result it should not have contained: { pattern } { Environment . NewLine } ") ) ;
157
157
return new AndConstraint < CommandResultAssertions > ( this ) ;
158
158
}
159
159
160
160
public AndConstraint < CommandResultAssertions > HaveStdErrMatching ( string pattern , RegexOptions options = RegexOptions . None )
161
161
{
162
- Execute . Assertion . ForCondition ( Regex . Match ( _commandResult . StdErr , pattern , options ) . Success )
162
+ Execute . Assertion . ForCondition ( Regex . Match ( _commandResult . StdErr ?? string . Empty , pattern , options ) . Success )
163
163
. FailWith ( AppendDiagnosticsTo ( $ "Matching the command error output failed. Pattern: { pattern } { Environment . NewLine } ") ) ;
164
164
return new AndConstraint < CommandResultAssertions > ( this ) ;
165
165
}
0 commit comments