|
1 | 1 | namespace Seam.Test; |
2 | 2 |
|
| 3 | +using Newtonsoft.Json; |
3 | 4 | using Seam.Client; |
4 | 5 | using Seam.Model; |
5 | 6 |
|
@@ -123,4 +124,57 @@ public async void TestDeleteAsync() |
123 | 124 |
|
124 | 125 | Assert.NotEqual(device.DeviceId, device2.DeviceId); |
125 | 126 | } |
| 127 | + |
| 128 | + [Fact] |
| 129 | + public void TestUnknownEnumValue() |
| 130 | + { |
| 131 | + var json = |
| 132 | + @"{ |
| 133 | + ""device_type"": ""unknown_device_type"", |
| 134 | + ""device_id"": ""test"", |
| 135 | + ""capabilities_supported"": [""unknown_capability"", ""access_code""], |
| 136 | + ""properties"": { |
| 137 | + ""available_fan_mode_settings"": [""unknown_mode"", ""auto""] |
| 138 | + }, |
| 139 | + connected_account_id: ""test"", |
| 140 | + created_at: ""test"", |
| 141 | + device_id: ""test"", |
| 142 | + device_type: ""unknown_device_type"", |
| 143 | + display_name: ""test"", |
| 144 | + errors: [], |
| 145 | + is_managed: false, |
| 146 | + warnings: [], |
| 147 | + workspace_id: ""test"", |
| 148 | + properties: { |
| 149 | + ""available_fan_mode_settings"": [""unknown_mode"", ""auto""] |
| 150 | + }, |
| 151 | + custom_metadata: {} |
| 152 | + }"; |
| 153 | + |
| 154 | + var settings = new JsonSerializerSettings |
| 155 | + { |
| 156 | + Converters = new List<JsonConverter> { new SafeStringEnumConverter() }, |
| 157 | + }; |
| 158 | + var device = JsonConvert.DeserializeObject<Device>(json, settings); |
| 159 | + |
| 160 | + // Unknown values should be mapped to first enum value (Unrecognized = 0) |
| 161 | + Assert.NotNull(device); |
| 162 | + Assert.Equal(Device.DeviceTypeEnum.Unrecognized, device.DeviceType); |
| 163 | + Assert.Equal( |
| 164 | + Device.CapabilitiesSupportedEnum.Unrecognized, |
| 165 | + device.CapabilitiesSupported[0] |
| 166 | + ); |
| 167 | + Assert.NotNull(device.Properties.AvailableFanModeSettings); |
| 168 | + Assert.Equal( |
| 169 | + DeviceProperties.AvailableFanModeSettingsEnum.Unrecognized, |
| 170 | + device.Properties.AvailableFanModeSettings[0] |
| 171 | + ); |
| 172 | + |
| 173 | + // Known values should still work |
| 174 | + Assert.Equal(Device.CapabilitiesSupportedEnum.AccessCode, device.CapabilitiesSupported[1]); |
| 175 | + Assert.Equal( |
| 176 | + DeviceProperties.AvailableFanModeSettingsEnum.Auto, |
| 177 | + device.Properties.AvailableFanModeSettings[1] |
| 178 | + ); |
| 179 | + } |
126 | 180 | } |
0 commit comments