1+ using System . Collections . Generic ;
2+ using System . Text . Json ;
3+ using Amazon . Extensions . Configuration . SystemsManager . Utils ;
4+ using Amazon . SimpleSystemsManagement . Model ;
5+ using Xunit ;
6+
7+ namespace Amazon . Extensions . Configuration . SystemsManager . Tests . Utils
8+ {
9+ public class ParameterProcessorUtilTests
10+ {
11+ [ Fact ]
12+ public void ParseJsonParameterSuccessfully ( )
13+ {
14+ var result = new Dictionary < string , string > ( ) ;
15+ var parameter = new Parameter { Value = "{\" key\" : \" value\" }" } ;
16+ var keyPrefix = "prefix" ;
17+
18+ ParameterProcessorUtil . ParseJsonParameter ( parameter , keyPrefix , result ) ;
19+
20+ Assert . Single ( result ) ;
21+ Assert . Contains ( "prefix:key" , result . Keys ) ;
22+ Assert . Equal ( "value" , result [ "prefix:key" ] ) ;
23+ }
24+
25+ [ Fact ]
26+ public void ParseJsonParameterWithDuplicateKeyThrowsException ( )
27+ {
28+ var result = new Dictionary < string , string > { { "prefix:key" , "value" } } ;
29+ var parameter = new Parameter { Value = "{\" key\" : \" newvalue\" }" } ;
30+ var keyPrefix = "prefix" ;
31+
32+ Assert . Throws < DuplicateParameterException > ( ( ) => ParameterProcessorUtil . ParseJsonParameter ( parameter , keyPrefix , result ) ) ;
33+ }
34+
35+ [ Fact ]
36+ public void ParseJsonParameterForInvalidJsonThrowsException ( )
37+ {
38+ var result = new Dictionary < string , string > ( ) ;
39+ var parameter = new Parameter { Value = "invalid json" } ;
40+ var keyPrefix = "" ;
41+
42+ Assert . ThrowsAny < JsonException > ( ( ) => ParameterProcessorUtil . ParseJsonParameter ( parameter , keyPrefix , result ) ) ;
43+ }
44+
45+ [ Fact ]
46+ public void ParseStringListParameterSuccessfully ( )
47+ {
48+ var result = new Dictionary < string , string > ( ) ;
49+ var parameter = new Parameter { Value = "value1,value2,value3" } ;
50+ var keyPrefix = "prefix" ;
51+
52+ ParameterProcessorUtil . ParseStringListParameter ( parameter , keyPrefix , result ) ;
53+
54+ Assert . Equal ( 3 , result . Count ) ;
55+ Assert . Contains ( "prefix:0" , result . Keys ) ;
56+ Assert . Contains ( "prefix:1" , result . Keys ) ;
57+ Assert . Contains ( "prefix:2" , result . Keys ) ;
58+ Assert . Equal ( "value1" , result [ "prefix:0" ] ) ;
59+ Assert . Equal ( "value2" , result [ "prefix:1" ] ) ;
60+ Assert . Equal ( "value3" , result [ "prefix:2" ] ) ;
61+ }
62+
63+ [ Fact ]
64+ public void ParseStringListParameterWithDuplicateKeyThrowsException ( )
65+ {
66+ var result = new Dictionary < string , string > { { "prefix:0" , "value" } } ;
67+ var parameter = new Parameter { Value = "value1,value2,value3" } ;
68+ var keyPrefix = "prefix" ;
69+
70+ Assert . Throws < DuplicateParameterException > ( ( ) => ParameterProcessorUtil . ParseStringListParameter ( parameter , keyPrefix , result ) ) ;
71+ }
72+
73+ [ Fact ]
74+ public void ParseStringParameterSuccessfully ( )
75+ {
76+ var result = new Dictionary < string , string > ( ) ;
77+ var parameter = new Parameter { Value = "stringValue" } ;
78+ var key = "myKey" ;
79+
80+ ParameterProcessorUtil . ParseStringParameter ( parameter , key , result ) ;
81+
82+ Assert . Single ( result ) ;
83+ Assert . Contains ( "myKey" , result . Keys ) ;
84+ Assert . Equal ( "stringValue" , result [ "myKey" ] ) ;
85+ }
86+
87+ [ Fact ]
88+ public void ParseStringParameterWithDuplicateKeyThrowsException ( )
89+ {
90+ var result = new Dictionary < string , string > { { "myKey" , "existingValue" } } ;
91+ var parameter = new Parameter { Value = "newValue" } ;
92+ var key = "myKey" ;
93+
94+ Assert . Throws < DuplicateParameterException > ( ( ) => ParameterProcessorUtil . ParseStringParameter ( parameter , key , result ) ) ;
95+ }
96+
97+ }
98+ }
0 commit comments