public void TestJsonDeserializeSPI(string actionString, SystemParametersInfo.Action action, bool?sendChange, bool?updateUserProfile, bool success) { var options = new JsonSerializerOptions(); options.Converters.Add(new JsonElementInferredTypeConverter()); options.Converters.Add(new SettingFinalizerDescription.JsonConverter()); var json = JsonSerializer.Serialize(new Dictionary <string, object>() { { "type", "com.microsoft.windows.systemParametersInfo" }, { "action", actionString }, { "send_change", sendChange }, { "update_user_profile", updateUserProfile } }); var finalizer = JsonSerializer.Deserialize <SettingFinalizerDescription>(json, options); Assert.NotNull(finalizer); if (success) { Assert.Equal(SettingFinalizerDescription.HandlerKind.SystemParametersInfo, finalizer.Kind); Assert.IsType <SystemParametersInfoSettingFinalizerDescription>(finalizer); SystemParametersInfoSettingFinalizerDescription spi = (SystemParametersInfoSettingFinalizerDescription)finalizer; Assert.Equal(action, spi.Action); if (sendChange != null) { Assert.Equal(sendChange, spi.SendChange); } if (updateUserProfile != null) { Assert.Equal(updateUserProfile, spi.UpdateUserProfile); } //test equals operator SystemParametersInfoSettingFinalizerDescription other = new SystemParametersInfoSettingFinalizerDescription(action); other.SendChange = spi.SendChange; other.UpdateUserProfile = spi.UpdateUserProfile; Assert.Equal(other, spi); } else { Assert.Equal(SettingFinalizerDescription.HandlerKind.Unknown, finalizer.Kind); } }
/// <summary> /// Create a new SPI handler /// </summary> /// <param name="description"></param> /// <param name="systemParametersInfo"></param> /// <param name="logger"></param> public SystemParametersInfoSettingsFinalizer(SystemParametersInfoSettingFinalizerDescription description, ISystemParametersInfo systemParametersInfo, ILogger <SystemParametersInfoSettingsFinalizer> logger) { Description = description; this.logger = logger; this.systemParametersInfo = systemParametersInfo; }