44using EventLogExpert . Eventing . Models ;
55using EventLogExpert . UI . Models ;
66using EventLogExpert . UI . Tests . TestUtils ;
7+ using EventLogExpert . UI . Tests . TestUtils . Constants ;
78using System . Linq . Dynamic . Core . Exceptions ;
89
910namespace EventLogExpert . UI . Tests . Models ;
@@ -14,10 +15,10 @@ public sealed class FilterComparisonTests
1415 public void Expression_WhenCompoundCondition_ShouldMatchCorrectEvent ( )
1516 {
1617 // Arrange
17- FilterComparison model = new ( ) { Value = "Id == 100 && Level == \" Error \" " } ;
18- DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( 100 , level : "Error" ) ;
19- DisplayEventModel nonMatchingIdEvent = EventUtils . CreateTestEvent ( 200 , level : "Error" ) ;
20- DisplayEventModel nonMatchingLevelEvent = EventUtils . CreateTestEvent ( 100 , level : "Information" ) ;
18+ FilterComparison model = new ( ) { Value = Constants . FilterIdEquals100AndLevelError } ;
19+ DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( 100 , level : Constants . EventLevelError ) ;
20+ DisplayEventModel nonMatchingIdEvent = EventUtils . CreateTestEvent ( 200 , level : Constants . EventLevelError ) ;
21+ DisplayEventModel nonMatchingLevelEvent = EventUtils . CreateTestEvent ( 100 , level : Constants . EventLevelInformation ) ;
2122
2223 // Act
2324 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -34,9 +35,9 @@ public void Expression_WhenCompoundCondition_ShouldMatchCorrectEvent()
3435 public void Expression_WhenComputerNameEquals_ShouldMatchCorrectEvent ( )
3536 {
3637 // Arrange
37- FilterComparison model = new ( ) { Value = "ComputerName == \" SERVER01 \" " } ;
38- DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( computerName : "SERVER01" ) ;
39- DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( computerName : "SERVER02" ) ;
38+ FilterComparison model = new ( ) { Value = Constants . FilterComputerNameEqualsServer01 } ;
39+ DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( computerName : Constants . EventComputerServer01 ) ;
40+ DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( computerName : Constants . EventComputerServer02 ) ;
4041
4142 // Act
4243 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -51,13 +52,13 @@ public void Expression_WhenComputerNameEquals_ShouldMatchCorrectEvent()
5152 public void Expression_WhenDescriptionContains_ShouldMatchCorrectEvent ( )
5253 {
5354 // Arrange
54- FilterComparison model = new ( ) { Value = "Description.Contains( \" error occurred \" )" } ;
55+ FilterComparison model = new ( ) { Value = Constants . FilterDescriptionContainsErrorOccurred } ;
5556
5657 DisplayEventModel matchingEvent =
57- EventUtils . CreateTestEvent ( description : "An error occurred in the application" ) ;
58+ EventUtils . CreateTestEvent ( description : Constants . EventDescriptionErrorOccurred ) ;
5859
5960 DisplayEventModel nonMatchingEvent =
60- EventUtils . CreateTestEvent ( description : "Operation completed successfully" ) ;
61+ EventUtils . CreateTestEvent ( description : Constants . EventDescriptionSuccess ) ;
6162
6263 // Act
6364 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -72,7 +73,7 @@ public void Expression_WhenDescriptionContains_ShouldMatchCorrectEvent()
7273 public void Expression_WhenIdEquals_ShouldMatchCorrectEvent ( )
7374 {
7475 // Arrange
75- FilterComparison model = new ( ) { Value = "Id == 100" } ;
76+ FilterComparison model = new ( ) { Value = Constants . FilterIdEquals100 } ;
7677 DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( 100 ) ;
7778 DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( 200 ) ;
7879
@@ -89,7 +90,7 @@ public void Expression_WhenIdEquals_ShouldMatchCorrectEvent()
8990 public void Expression_WhenIdGreaterThan_ShouldMatchCorrectEvent ( )
9091 {
9192 // Arrange
92- FilterComparison model = new ( ) { Value = "Id > 100" } ;
93+ FilterComparison model = new ( ) { Value = Constants . FilterIdGreaterThan100 } ;
9394 DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( 150 ) ;
9495 DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( 50 ) ;
9596
@@ -106,7 +107,7 @@ public void Expression_WhenIdGreaterThan_ShouldMatchCorrectEvent()
106107 public void Expression_WhenIdNotEquals_ShouldMatchCorrectEvent ( )
107108 {
108109 // Arrange
109- FilterComparison model = new ( ) { Value = "Id != 100" } ;
110+ FilterComparison model = new ( ) { Value = Constants . FilterIdNotEquals100 } ;
110111 DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( 200 ) ;
111112 DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( 100 ) ;
112113
@@ -123,9 +124,9 @@ public void Expression_WhenIdNotEquals_ShouldMatchCorrectEvent()
123124 public void Expression_WhenLevelEquals_ShouldMatchCorrectEvent ( )
124125 {
125126 // Arrange
126- FilterComparison model = new ( ) { Value = "Level == \" Error \" " } ;
127- DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( level : "Error" ) ;
128- DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( level : "Information" ) ;
127+ FilterComparison model = new ( ) { Value = Constants . FilterLevelEqualsError } ;
128+ DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( level : Constants . EventLevelError ) ;
129+ DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( level : Constants . EventLevelInformation ) ;
129130
130131 // Act
131132 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -140,7 +141,7 @@ public void Expression_WhenLevelEquals_ShouldMatchCorrectEvent()
140141 public void Expression_WhenOrCondition_ShouldMatchCorrectEvent ( )
141142 {
142143 // Arrange
143- FilterComparison model = new ( ) { Value = "Id == 100 || Id == 200" } ;
144+ FilterComparison model = new ( ) { Value = Constants . FilterIdEquals100Or200 } ;
144145 DisplayEventModel matchingEvent1 = EventUtils . CreateTestEvent ( 100 ) ;
145146 DisplayEventModel matchingEvent2 = EventUtils . CreateTestEvent ( 200 ) ;
146147 DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( 300 ) ;
@@ -160,9 +161,9 @@ public void Expression_WhenOrCondition_ShouldMatchCorrectEvent()
160161 public void Expression_WhenSourceContains_ShouldMatchCorrectEvent ( )
161162 {
162163 // Arrange
163- FilterComparison model = new ( ) { Value = "Source.Contains( \" Test \" )" } ;
164- DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( source : "TestSource" ) ;
165- DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( source : "OtherSource" ) ;
164+ FilterComparison model = new ( ) { Value = Constants . FilterSourceContainsTest } ;
165+ DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( source : Constants . EventSourceTestSource ) ;
166+ DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( source : Constants . EventSourceOtherSource ) ;
166167
167168 // Act
168169 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -177,9 +178,9 @@ public void Expression_WhenSourceContains_ShouldMatchCorrectEvent()
177178 public void Expression_WhenTaskCategoryContains_ShouldMatchCorrectEvent ( )
178179 {
179180 // Arrange
180- FilterComparison model = new ( ) { Value = "TaskCategory.Contains( \" Security \" )" } ;
181- DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( taskCategory : "Security Audit" ) ;
182- DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( taskCategory : "System" ) ;
181+ FilterComparison model = new ( ) { Value = Constants . FilterTaskCategoryContainsSecurity } ;
182+ DisplayEventModel matchingEvent = EventUtils . CreateTestEvent ( taskCategory : Constants . EventTaskCategorySecurity ) ;
183+ DisplayEventModel nonMatchingEvent = EventUtils . CreateTestEvent ( taskCategory : Constants . EventTaskCategorySystem ) ;
183184
184185 // Act
185186 bool matchResult = model . Expression ( matchingEvent ) ;
@@ -197,7 +198,7 @@ public void Expression_WhenValidValue_ShouldContainFunc()
197198 FilterComparison model = new ( ) ;
198199
199200 // Act
200- model . Value = "Id == 100" ;
201+ model . Value = Constants . FilterIdEquals100 ;
201202
202203 // Assert
203204 Assert . NotNull ( model . Expression ) ;
@@ -207,14 +208,14 @@ public void Expression_WhenValidValue_ShouldContainFunc()
207208 public void Expression_WhenValueUpdated_ShouldUpdateExpression ( )
208209 {
209210 // Arrange
210- FilterComparison model = new ( ) { Value = "Id == 100" } ;
211+ FilterComparison model = new ( ) { Value = Constants . FilterIdEquals100 } ;
211212 DisplayEventModel event100 = EventUtils . CreateTestEvent ( 100 ) ;
212213 DisplayEventModel event200 = EventUtils . CreateTestEvent ( 200 ) ;
213214
214215 // Act
215216 bool initialMatch100 = model . Expression ( event100 ) ;
216217 bool initialMatch200 = model . Expression ( event200 ) ;
217- model . Value = "Id == 200" ;
218+ model . Value = Constants . FilterIdEquals200 ;
218219 bool updatedMatch100 = model . Expression ( event100 ) ;
219220 bool updatedMatch200 = model . Expression ( event200 ) ;
220221
@@ -242,7 +243,7 @@ public void Value_WhenInvalidPropertyName_ShouldThrow()
242243 FilterComparison model = new ( ) ;
243244
244245 // Act & Assert
245- Assert . Throws < ParseException > ( ( ) => model . Value = "InvalidProperty == 100" ) ;
246+ Assert . Throws < ParseException > ( ( ) => model . Value = Constants . FilterInvalidProperty ) ;
246247 }
247248
248249 [ Fact ]
@@ -252,6 +253,6 @@ public void Value_WhenNotValid_ShouldThrow()
252253 FilterComparison model = new ( ) ;
253254
254255 // Act & Assert
255- Assert . Throws < ParseException > ( ( ) => model . Value = "Id == invalid" ) ;
256+ Assert . Throws < ParseException > ( ( ) => model . Value = Constants . FilterInvalidValue ) ;
256257 }
257258}
0 commit comments