18
18
using NUnit . Framework ;
19
19
using OptimizelySDK . AudienceConditions ;
20
20
using OptimizelySDK . Entity ;
21
+ using OptimizelySDK . Logger ;
21
22
22
23
namespace OptimizelySDK . Tests . AudienceConditionsTests
23
24
{
@@ -32,19 +33,26 @@ public class ConditionsTest
32
33
private ICondition FalseCondition ;
33
34
private ICondition NullCondition ;
34
35
36
+ private ILogger Logger ;
37
+ private Mock < ILogger > MockLogger ;
38
+
35
39
[ TestFixtureSetUp ]
36
40
public void Initialize ( )
37
41
{
38
42
TrueConditionMock = new Mock < ICondition > ( ) ;
39
- TrueConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) ) ) . Returns ( true ) ;
43
+ TrueConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) , It . IsAny < ILogger > ( ) ) ) . Returns ( true ) ;
40
44
FalseConditionMock = new Mock < ICondition > ( ) ;
41
- FalseConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) ) ) . Returns ( false ) ;
45
+ FalseConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) , It . IsAny < ILogger > ( ) ) ) . Returns ( false ) ;
42
46
NullConditionMock = new Mock < ICondition > ( ) ;
43
- NullConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) ) ) . Returns ( ( bool ? ) null ) ;
47
+ NullConditionMock . Setup ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) , It . IsAny < ILogger > ( ) ) ) . Returns ( ( bool ? ) null ) ;
44
48
45
49
TrueCondition = TrueConditionMock . Object ;
46
50
FalseCondition = FalseConditionMock . Object ;
47
51
NullCondition = NullConditionMock . Object ;
52
+
53
+ MockLogger = new Mock < ILogger > ( ) ;
54
+ MockLogger . Setup ( l => l . Log ( It . IsAny < LogLevel > ( ) , It . IsAny < string > ( ) ) ) ;
55
+ Logger = MockLogger . Object ;
48
56
}
49
57
50
58
#region AND Condition Tests
@@ -55,7 +63,7 @@ public void TestAndEvaluatorReturnsTrueWhenAllOperandsEvaluateToTrue()
55
63
ICondition [ ] conditions = new ICondition [ ] { TrueCondition , TrueCondition } ;
56
64
var andCondition = new AndCondition { Conditions = conditions } ;
57
65
58
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . True ) ;
66
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . True ) ;
59
67
}
60
68
61
69
[ Test ]
@@ -64,10 +72,10 @@ public void TestAndEvaluatorReturnsFalseWhenAnyOperandEvaluatesToFalse()
64
72
ICondition [ ] conditions = new ICondition [ ] { FalseCondition , TrueCondition } ;
65
73
var andCondition = new AndCondition { Conditions = conditions } ;
66
74
67
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . False ) ;
75
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . False ) ;
68
76
69
77
// Should not be called due to short circuiting.
70
- TrueConditionMock . Verify ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) ) , Times . Never ) ;
78
+ TrueConditionMock . Verify ( condition => condition . Evaluate ( It . IsAny < ProjectConfig > ( ) , It . IsAny < UserAttributes > ( ) , Logger ) , Times . Never ) ;
71
79
}
72
80
73
81
[ Test ]
@@ -76,7 +84,7 @@ public void TestAndEvaluatorReturnsNullWhenAllOperandsEvaluateToNull()
76
84
ICondition [ ] conditions = new ICondition [ ] { NullCondition , NullCondition } ;
77
85
var andCondition = new AndCondition { Conditions = conditions } ;
78
86
79
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . Null ) ;
87
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . Null ) ;
80
88
}
81
89
82
90
[ Test ]
@@ -85,7 +93,7 @@ public void TestAndEvaluatorReturnsNullWhenOperandsEvaluateToTrueAndNull()
85
93
ICondition [ ] conditions = new ICondition [ ] { TrueCondition , NullCondition , TrueCondition } ;
86
94
var andCondition = new AndCondition { Conditions = conditions } ;
87
95
88
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . Null ) ;
96
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . Null ) ;
89
97
}
90
98
91
99
[ Test ]
@@ -94,7 +102,7 @@ public void TestAndEvaluatorReturnsFalseWhenOperandsEvaluateToFalseAndNull()
94
102
ICondition [ ] conditions = new ICondition [ ] { NullCondition , FalseCondition , NullCondition } ;
95
103
var andCondition = new AndCondition { Conditions = conditions } ;
96
104
97
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . False ) ;
105
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . False ) ;
98
106
}
99
107
100
108
[ Test ]
@@ -103,7 +111,7 @@ public void TestAndEvaluatorReturnsFalseWhenOperandsEvaluateToTrueFalseAndNull()
103
111
ICondition [ ] conditions = new ICondition [ ] { TrueCondition , FalseCondition , NullCondition } ;
104
112
var andCondition = new AndCondition { Conditions = conditions } ;
105
113
106
- Assert . That ( andCondition . Evaluate ( null , null ) , Is . False ) ;
114
+ Assert . That ( andCondition . Evaluate ( null , null , Logger ) , Is . False ) ;
107
115
}
108
116
109
117
#endregion // AND Condition Tests
@@ -116,7 +124,7 @@ public void TestOrEvaluatorReturnsTrueWhenAnyOperandEvaluatesToTrue()
116
124
ICondition [ ] conditions = new ICondition [ ] { TrueCondition , FalseCondition , NullCondition } ;
117
125
var orCondition = new OrCondition { Conditions = conditions } ;
118
126
119
- Assert . That ( orCondition . Evaluate ( null , null ) , Is . True ) ;
127
+ Assert . That ( orCondition . Evaluate ( null , null , Logger ) , Is . True ) ;
120
128
}
121
129
122
130
[ Test ]
@@ -125,7 +133,7 @@ public void TestOrEvaluatorReturnsFalseWhenAllOperandsEvaluatesToFalse()
125
133
ICondition [ ] conditions = new ICondition [ ] { FalseCondition , FalseCondition } ;
126
134
var orCondition = new OrCondition { Conditions = conditions } ;
127
135
128
- Assert . That ( orCondition . Evaluate ( null , null ) , Is . False ) ;
136
+ Assert . That ( orCondition . Evaluate ( null , null , Logger ) , Is . False ) ;
129
137
}
130
138
131
139
[ Test ]
@@ -134,7 +142,7 @@ public void TestOrEvaluatorReturnsNullWhenOperandsEvaluateToFalseAndNull()
134
142
ICondition [ ] conditions = new ICondition [ ] { FalseCondition , NullCondition , FalseCondition } ;
135
143
var orCondition = new OrCondition { Conditions = conditions } ;
136
144
137
- Assert . That ( orCondition . Evaluate ( null , null ) , Is . Null ) ;
145
+ Assert . That ( orCondition . Evaluate ( null , null , Logger ) , Is . Null ) ;
138
146
}
139
147
140
148
[ Test ]
@@ -143,7 +151,7 @@ public void TestOrEvaluatorReturnsTrueWhenOperandsEvaluateToTrueAndNull()
143
151
ICondition [ ] conditions = new ICondition [ ] { TrueCondition , NullCondition , TrueCondition } ;
144
152
var orCondition = new OrCondition { Conditions = conditions } ;
145
153
146
- Assert . That ( orCondition . Evaluate ( null , null ) , Is . True ) ;
154
+ Assert . That ( orCondition . Evaluate ( null , null , Logger ) , Is . True ) ;
147
155
}
148
156
149
157
[ Test ]
@@ -152,7 +160,7 @@ public void TestOrEvaluatorReturnsTrueWhenOperandsEvaluateToFalseTrueAndNull()
152
160
ICondition [ ] conditions = new ICondition [ ] { FalseCondition , NullCondition , TrueCondition } ;
153
161
var orCondition = new OrCondition { Conditions = conditions } ;
154
162
155
- Assert . That ( orCondition . Evaluate ( null , null ) , Is . True ) ;
163
+ Assert . That ( orCondition . Evaluate ( null , null , Logger ) , Is . True ) ;
156
164
}
157
165
158
166
#endregion // OR Condition Tests
@@ -163,28 +171,28 @@ public void TestOrEvaluatorReturnsTrueWhenOperandsEvaluateToFalseTrueAndNull()
163
171
public void TestNotEvaluatorReturnsNullWhenOperandEvaluateToNull ( )
164
172
{
165
173
var notCondition = new NotCondition { Condition = NullCondition } ;
166
- Assert . That ( notCondition . Evaluate ( null , null ) , Is . Null ) ;
174
+ Assert . That ( notCondition . Evaluate ( null , null , Logger ) , Is . Null ) ;
167
175
}
168
176
169
177
[ Test ]
170
178
public void TestNotEvaluatorReturnsTrueWhenOperandEvaluateToFalse ( )
171
179
{
172
180
var notCondition = new NotCondition { Condition = FalseCondition } ;
173
- Assert . That ( notCondition . Evaluate ( null , null ) , Is . True ) ;
181
+ Assert . That ( notCondition . Evaluate ( null , null , Logger ) , Is . True ) ;
174
182
}
175
183
176
184
[ Test ]
177
185
public void TestNotEvaluatorReturnsFalseWhenOperandEvaluateToTrue ( )
178
186
{
179
187
var notCondition = new NotCondition { Condition = TrueCondition } ;
180
- Assert . That ( notCondition . Evaluate ( null , null ) , Is . False ) ;
188
+ Assert . That ( notCondition . Evaluate ( null , null , Logger ) , Is . False ) ;
181
189
}
182
190
183
191
[ Test ]
184
192
public void TestNotEvaluatorReturnsNullWhenConditionIsNull ( )
185
193
{
186
194
var notCondition = new NotCondition { Condition = null } ;
187
- Assert . That ( notCondition . Evaluate ( null , null ) , Is . Null ) ;
195
+ Assert . That ( notCondition . Evaluate ( null , null , Logger ) , Is . Null ) ;
188
196
}
189
197
190
198
#endregion // NOT Condition Tests
0 commit comments