@@ -69,5 +69,71 @@ public void QueryGreetingWithErrorsResponse()
69
69
Assert . AreEqual ( ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 200 ) , context . ResponseData . StatusCode ) ;
70
70
}
71
71
72
+ /// <summary>
73
+ /// Parses simple XML errors
74
+ /// </summary>
75
+ [ TestMethod ]
76
+ [ TestCategory ( "ProtocolTest" ) ]
77
+ [ TestCategory ( "ErrorTest" ) ]
78
+ [ TestCategory ( "AwsQuery" ) ]
79
+ public void QueryInvalidGreetingErrorErrorResponse ( )
80
+ {
81
+ // Arrange
82
+ var webResponseData = new WebResponseData ( ) ;
83
+ webResponseData . StatusCode = ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ;
84
+ webResponseData . Headers [ "Content-Type" ] = "text/xml" ;
85
+ byte [ ] bytes = Encoding . ASCII . GetBytes ( "<ErrorResponse>\n <Error>\n <Type>Sender</Type>\n <Code>InvalidGreeting</Code>\n <Message>Hi</Message>\n </Error>\n <RequestId>foo-id</RequestId>\n </ErrorResponse>\n " ) ;
86
+ var stream = new MemoryStream ( bytes ) ;
87
+ var context = new XmlUnmarshallerContext ( stream , true , webResponseData ) ;
88
+ // Act
89
+ var errorResponse = new GreetingWithErrorsResponseUnmarshaller ( ) . UnmarshallException ( context , null , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ) ;
90
+ // Assert
91
+ Assert . IsInstanceOfType ( errorResponse , typeof ( InvalidGreetingException ) ) ;
92
+ Assert . AreEqual ( errorResponse . StatusCode , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ) ;
93
+ }
94
+
95
+ /// <summary>
96
+ /// Parses customized XML errors
97
+ /// </summary>
98
+ [ TestMethod ]
99
+ [ TestCategory ( "ProtocolTest" ) ]
100
+ [ TestCategory ( "ErrorTest" ) ]
101
+ [ TestCategory ( "AwsQuery" ) ]
102
+ public void QueryCustomizedErrorErrorResponse ( )
103
+ {
104
+ // Arrange
105
+ var webResponseData = new WebResponseData ( ) ;
106
+ webResponseData . StatusCode = ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 402 ) ;
107
+ webResponseData . Headers [ "Content-Type" ] = "text/xml" ;
108
+ byte [ ] bytes = Encoding . ASCII . GetBytes ( "<ErrorResponse>\n <Error>\n <Type>Sender</Type>\n <Code>Customized</Code>\n <Message>Hi</Message>\n </Error>\n <RequestId>foo-id</RequestId>\n </ErrorResponse>\n " ) ;
109
+ var stream = new MemoryStream ( bytes ) ;
110
+ var context = new XmlUnmarshallerContext ( stream , true , webResponseData ) ;
111
+ // Act
112
+ var errorResponse = new GreetingWithErrorsResponseUnmarshaller ( ) . UnmarshallException ( context , null , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 402 ) ) ;
113
+ // Assert
114
+ Assert . IsInstanceOfType ( errorResponse , typeof ( CustomCodeErrorException ) ) ;
115
+ Assert . AreEqual ( errorResponse . StatusCode , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 402 ) ) ;
116
+ }
117
+
118
+ [ TestMethod ]
119
+ [ TestCategory ( "ProtocolTest" ) ]
120
+ [ TestCategory ( "ErrorTest" ) ]
121
+ [ TestCategory ( "AwsQuery" ) ]
122
+ public void QueryComplexErrorErrorResponse ( )
123
+ {
124
+ // Arrange
125
+ var webResponseData = new WebResponseData ( ) ;
126
+ webResponseData . StatusCode = ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ;
127
+ webResponseData . Headers [ "Content-Type" ] = "text/xml" ;
128
+ byte [ ] bytes = Encoding . ASCII . GetBytes ( "<ErrorResponse>\n <Error>\n <Type>Sender</Type>\n <Code>ComplexError</Code>\n <TopLevel>Top level</TopLevel>\n <Nested>\n <Foo>bar</Foo>\n </Nested>\n </Error>\n <RequestId>foo-id</RequestId>\n </ErrorResponse>\n " ) ;
129
+ var stream = new MemoryStream ( bytes ) ;
130
+ var context = new XmlUnmarshallerContext ( stream , true , webResponseData ) ;
131
+ // Act
132
+ var errorResponse = new GreetingWithErrorsResponseUnmarshaller ( ) . UnmarshallException ( context , null , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ) ;
133
+ // Assert
134
+ Assert . IsInstanceOfType ( errorResponse , typeof ( ComplexErrorException ) ) ;
135
+ Assert . AreEqual ( errorResponse . StatusCode , ( HttpStatusCode ) Enum . ToObject ( typeof ( HttpStatusCode ) , 400 ) ) ;
136
+ }
137
+
72
138
}
73
139
}
0 commit comments