@@ -141,4 +141,120 @@ public void TestUnknownEnumValue()
141141 device . Properties . AvailableFanModeSettings [ 1 ]
142142 ) ;
143143 }
144+
145+ [ Fact ]
146+ public void TestDiscriminatedUnionArrayWithUnknownTypes ( )
147+ {
148+ var json =
149+ @"{
150+ ""connected_account_id"": ""test-account-id"",
151+ ""account_type"": ""august"",
152+ ""account_type_display_name"": ""August Lock"",
153+ ""automatically_manage_new_devices"": true,
154+ ""created_at"": ""2024-01-15T10:00:00Z"",
155+ ""accepted_capabilities"": [],
156+ ""custom_metadata"": {},
157+ ""errors"": [
158+ {
159+ ""error_code"": ""unknown_error_type"",
160+ ""message"": ""An unknown error occurred"",
161+ ""created_at"": ""2024-01-15T10:00:00Z""
162+ }
163+ ],
164+ ""warnings"": [
165+ {
166+ ""warning_code"": ""unknown_warning_type"",
167+ ""message"": ""An unknown warning occurred"",
168+ ""created_at"": ""2024-01-15T10:00:00Z""
169+ }
170+ ]
171+ }" ;
172+
173+ var settings = new JsonSerializerSettings
174+ {
175+ Converters = new List < JsonConverter > { new SafeStringEnumConverter ( ) } ,
176+ MissingMemberHandling = MissingMemberHandling . Ignore ,
177+ } ;
178+
179+ // Unknown discriminated union types should fall back to unrecognized type
180+ var account = JsonConvert . DeserializeObject < ConnectedAccount > ( json , settings ) ;
181+
182+ Assert . NotNull ( account ) ;
183+ Assert . NotNull ( account . Errors ) ;
184+ Assert . Single ( account . Errors ) ;
185+
186+ // The unknown error type should fall back to an unrecognized error type
187+ var error = account . Errors [ 0 ] ;
188+ Assert . Equal ( "unrecognized" , error . ErrorCode ) ;
189+ Assert . Equal ( "An unknown error occurred" , error . Message ) ;
190+ }
191+
192+ [ Fact ]
193+ public void TestEventArrayWithUnknownTypes ( )
194+ {
195+ var json =
196+ @"[
197+ {
198+ ""event_id"": ""event-1"",
199+ ""event_type"": ""device.connected"",
200+ ""created_at"": ""2024-01-15T10:00:00Z"",
201+ ""occurred_at"": ""2024-01-15T10:00:00Z"",
202+ ""device_id"": ""device-123"",
203+ ""connected_account_id"": ""account-123"",
204+ ""workspace_id"": ""workspace-123""
205+ },
206+ {
207+ ""event_id"": ""event-2"",
208+ ""event_type"": ""unknown_event_type"",
209+ ""created_at"": ""2024-01-15T10:00:00Z"",
210+ ""custom_field"": ""custom_value""
211+ }
212+ ]" ;
213+
214+ var settings = new JsonSerializerSettings
215+ {
216+ Converters = new List < JsonConverter > { new SafeStringEnumConverter ( ) } ,
217+ MissingMemberHandling = MissingMemberHandling . Ignore ,
218+ } ;
219+
220+ // Unknown event types should fall back to unrecognized type
221+ var events = JsonConvert . DeserializeObject < List < Event > > ( json , settings ) ;
222+
223+ Assert . NotNull ( events ) ;
224+ Assert . Equal ( 2 , events . Count ) ;
225+
226+ // First event should deserialize normally
227+ Assert . IsType < EventDeviceConnected > ( events [ 0 ] ) ;
228+
229+ // Second event with unknown type should fall back to unrecognized
230+ var unknownEvent = events [ 1 ] ;
231+ Assert . IsType < EventUnrecognized > ( unknownEvent ) ;
232+ Assert . Equal ( "unrecognized" , unknownEvent . EventType ) ;
233+ }
234+
235+ [ Fact ]
236+ public void TestActionAttemptWithUnknownType ( )
237+ {
238+ // Test case for ActionAttempt with unknown action types
239+ var json =
240+ @"{
241+ ""action_attempt_id"": ""attempt-123"",
242+ ""action_type"": ""UNKNOWN_ACTION"",
243+ ""status"": ""success"",
244+ ""result"": {},
245+ ""error"": null
246+ }" ;
247+
248+ var settings = new JsonSerializerSettings
249+ {
250+ Converters = new List < JsonConverter > { new SafeStringEnumConverter ( ) } ,
251+ MissingMemberHandling = MissingMemberHandling . Ignore ,
252+ } ;
253+
254+ // Unknown action types should fall back to unrecognized type
255+ var actionAttempt = JsonConvert . DeserializeObject < ActionAttempt > ( json , settings ) ;
256+
257+ Assert . NotNull ( actionAttempt ) ;
258+ Assert . Equal ( "unrecognized" , actionAttempt . ActionType ) ;
259+ }
144260}
0 commit comments