1- using System ;
2- using System . IO ;
3- using System . Threading . Tasks ;
4- using NUnit . Framework ;
51using NJsonSchema ;
2+ using NUnit . Framework ;
63using YamlDotNet . Serialization ;
74using YamlDotNet . Serialization . NamingConventions ;
85
@@ -21,15 +18,15 @@ public async Task OneTimeSetUp()
2118 // Load schema once for all tests
2219 string schemaPath = Path . Combine ( TestContext . CurrentContext . TestDirectory , "config.schema.json" ) ;
2320 Assert . That ( File . Exists ( schemaPath ) , Is . True , $ "Schema file not found at: { schemaPath } ") ;
24-
21+
2522 string schemaJson = await File . ReadAllTextAsync ( schemaPath ) ;
2623 _schema = await JsonSchema . FromJsonAsync ( schemaJson ) ;
27-
24+
2825 // Setup YAML processors
2926 _yamlDeserializer = new DeserializerBuilder ( )
3027 . WithNamingConvention ( UnderscoredNamingConvention . Instance )
3128 . Build ( ) ;
32-
29+
3330 _yamlSerializer = new SerializerBuilder ( )
3431 . WithNamingConvention ( UnderscoredNamingConvention . Instance )
3532 . JsonCompatible ( )
@@ -42,16 +39,16 @@ public async Task TestConfigurationValidation_WithValidYaml_ShouldPassValidation
4239 // Arrange
4340 string yamlPath = Path . Combine ( TestContext . CurrentContext . TestDirectory , "test-config.yaml" ) ;
4441 Assert . That ( File . Exists ( yamlPath ) , Is . True , $ "Test YAML file not found at: { yamlPath } ") ;
45-
42+
4643 string yamlContent = await File . ReadAllTextAsync ( yamlPath ) ;
47-
44+
4845 // Act
49- var config = _yamlDeserializer . Deserialize < object > ( yamlContent ) ;
46+ object config = _yamlDeserializer . Deserialize < object > ( yamlContent ) ;
5047 string configJson = _yamlSerializer . Serialize ( config ) ;
51- var validationResults = _schema ! . Validate ( configJson ) ;
52-
48+ ICollection < NJsonSchema . Validation . ValidationError > validationResults = _schema ! . Validate ( configJson ) ;
49+
5350 // Assert
54- Assert . That ( validationResults . Count , Is . EqualTo ( 0 ) ,
51+ Assert . That ( validationResults . Count , Is . EqualTo ( 0 ) ,
5552 $ "Validation should pass but found { validationResults . Count } errors: { string . Join ( ", " , validationResults ) } ") ;
5653 }
5754
@@ -60,10 +57,10 @@ public void TestCidrExpansion_With24Subnet_ShouldReturn254IPs()
6057 {
6158 // Arrange
6259 string cidr = "10.18.8.0/24" ;
63-
60+
6461 // Act
65- var expandedIPs = ExpandCidrForTesting ( cidr ) ;
66-
62+ List < string > expandedIPs = ExpandCidrForTesting ( cidr ) ;
63+
6764 // Assert
6865 Assert . That ( expandedIPs . Count , Is . EqualTo ( 254 ) , "CIDR /24 should expand to 254 IPs (skip .0 and .255)" ) ;
6966 Assert . That ( expandedIPs [ 0 ] , Is . EqualTo ( "10.18.8.1" ) , "First IP should be .1" ) ;
@@ -75,10 +72,10 @@ public void TestCidrExpansion_With30Subnet_ShouldReturn2IPs()
7572 {
7673 // Arrange
7774 string cidr = "192.168.1.0/30" ;
78-
75+
7976 // Act
80- var expandedIPs = ExpandCidrForTesting ( cidr ) ;
81-
77+ List < string > expandedIPs = ExpandCidrForTesting ( cidr ) ;
78+
8279 // Assert
8380 Assert . That ( expandedIPs . Count , Is . EqualTo ( 2 ) , "CIDR /30 should expand to 2 IPs" ) ;
8481 Assert . That ( expandedIPs [ 0 ] , Is . EqualTo ( "192.168.1.1" ) ) ;
@@ -90,9 +87,9 @@ public void TestCidrExpansion_WithInvalidFormat_ShouldReturnEmpty()
9087 {
9188 // Arrange
9289 string invalidCidr = "invalid-cidr" ;
93-
90+
9491 // Act & Assert
95- var expandedIPs = ExpandCidrForTesting ( invalidCidr ) ;
92+ List < string > expandedIPs = ExpandCidrForTesting ( invalidCidr ) ;
9693 Assert . That ( expandedIPs . Count , Is . EqualTo ( 0 ) , "Invalid CIDR should return empty list" ) ;
9794 }
9895
@@ -103,21 +100,21 @@ public async Task TestConfigurationValidation_WithMinimalYaml_ShouldFailWithOldS
103100 // Arrange
104101 string yamlPath = Path . Combine ( TestContext . CurrentContext . TestDirectory , "test-config-minimal.yaml" ) ;
105102 Assert . That ( File . Exists ( yamlPath ) , Is . True , $ "Minimal test YAML file not found at: { yamlPath } ") ;
106-
103+
107104 string yamlContent = await File . ReadAllTextAsync ( yamlPath ) ;
108-
105+
109106 // Act
110- var config = _yamlDeserializer . Deserialize < object > ( yamlContent ) ;
107+ object config = _yamlDeserializer . Deserialize < object > ( yamlContent ) ;
111108 string configJson = _yamlSerializer . Serialize ( config ) ;
112-
109+
113110 // Show what the JSON looks like with null values
114111 TestContext . WriteLine ( $ "Generated JSON with nulls: { configJson } ") ;
115-
116- var validationResults = _schema ! . Validate ( configJson ) ;
117-
112+
113+ ICollection < NJsonSchema . Validation . ValidationError > validationResults = _schema ! . Validate ( configJson ) ;
114+
118115 // Assert - With the current fixed schema, this should now pass
119116 // But originally this would have failed due to null values
120- Assert . That ( validationResults . Count , Is . EqualTo ( 0 ) ,
117+ Assert . That ( validationResults . Count , Is . EqualTo ( 0 ) ,
121118 "With fixed schema, even minimal config with nulls should validate" ) ;
122119 }
123120
@@ -128,30 +125,30 @@ public async Task TestConfigurationValidation_WithMinimalYaml_ShouldFailWithOldS
128125 private List < string > ExpandCidrForTesting ( string cidr )
129126 {
130127 var result = new List < string > ( ) ;
131-
128+
132129 try
133130 {
134- var parts = cidr . Split ( '/' ) ;
131+ string [ ] parts = cidr . Split ( '/' ) ;
135132 if ( parts . Length != 2 ) return result ;
136-
133+
137134 string baseIp = parts [ 0 ] ;
138135 if ( ! int . TryParse ( parts [ 1 ] , out int prefixLength ) ) return result ;
139-
136+
140137 if ( prefixLength < 0 || prefixLength > 32 ) return result ;
141-
142- if ( ! System . Net . IPAddress . TryParse ( baseIp , out var ipAddress ) ) return result ;
143-
138+
139+ if ( ! System . Net . IPAddress . TryParse ( baseIp , out System . Net . IPAddress ? ipAddress ) ) return result ;
140+
144141 byte [ ] addressBytes = ipAddress . GetAddressBytes ( ) ;
145142 uint addressInt = BitConverter . ToUInt32 ( addressBytes . Reverse ( ) . ToArray ( ) , 0 ) ;
146-
143+
147144 int hostBits = 32 - prefixLength ;
148145 uint hostCount = ( uint ) ( 1 << hostBits ) ;
149146 uint networkAddress = addressInt & ( 0xFFFFFFFF << hostBits ) ;
150-
147+
151148 // Skip network and broadcast addresses for practical use
152149 uint startAddress = networkAddress + 1 ;
153150 uint endAddress = networkAddress + hostCount - 1 ;
154-
151+
155152 for ( uint address = startAddress ; address < endAddress && address > networkAddress ; address ++ )
156153 {
157154 byte [ ] bytes = BitConverter . GetBytes ( address ) . Reverse ( ) . ToArray ( ) ;
@@ -163,7 +160,7 @@ private List<string> ExpandCidrForTesting(string cidr)
163160 {
164161 // Return empty list on any error
165162 }
166-
163+
167164 return result ;
168165 }
169166}
0 commit comments