diff --git a/src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp b/src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp index 27a44e4ad7..1dfa846070 100644 --- a/src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp +++ b/src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp @@ -4,6 +4,7 @@ #include "DscUserSettingsFileResource.h" #include "DscComposableObject.h" #include "Resources.h" +#include "AppInstallerStrings.h" using namespace AppInstaller::Utility::literals; using namespace AppInstaller::Settings; @@ -16,7 +17,7 @@ namespace AppInstaller::CLI namespace { WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(SettingsProperty, Json::Value, Settings, "settings", DscComposablePropertyFlag::Required | DscComposablePropertyFlag::CopyToOutput, Resource::String::DscResourcePropertyDescriptionUserSettingsFileSettings); - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_FULL); + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_PARTIAL); using UserSettingsFileResourceObject = DscComposableObject; @@ -38,7 +39,6 @@ namespace AppInstaller::CLI void Get() { - Output.Action(ACTION_FULL); Output.Settings(GetUserSettings()); } @@ -64,12 +64,14 @@ namespace AppInstaller::CLI THROW_HR_IF(E_UNEXPECTED, !Input.Settings().has_value()); if (!_resolvedInputUserSettings) { - if(Input.Action() == ACTION_FULL) + if(Input.Action().has_value() && Utility::CaseInsensitiveEquals(Input.Action().value(), ACTION_FULL)) { + Output.Action(ACTION_FULL); _resolvedInputUserSettings = Input.Settings(); } else { + Output.Action(ACTION_PARTIAL); _resolvedInputUserSettings = MergeUserSettingsFiles(*Input.Settings()); } } diff --git a/src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs b/src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs index b798243759..c3f86c2692 100644 --- a/src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs +++ b/src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs @@ -61,7 +61,7 @@ public void Setup() } /// - /// Calls `get` on the `user-settings` resource. + /// Calls `get` on the `user-settings-file` resource. /// [Test] public void UserSettingsFile_Get() @@ -70,12 +70,12 @@ public void UserSettingsFile_Get() var getOutput = Get(new ()); Assert.IsNotNull(getOutput); - Assert.AreEqual(ActionPropertyValueFull, getOutput.Action); + Assert.IsNull(getOutput.Action); AssertSettingsAreEqual(expected, getOutput.Settings); } /// - /// Calls `set` on the `user-settings` resource with no diff. + /// Calls `set` on the `user-settings-file` resource with no diff. /// /// The action value. [Test] @@ -90,13 +90,13 @@ public void UserSettingsFile_Set_NoDiff(string action) var expected = GetCurrentUserSettings(); Assert.IsNotNull(setOutput); - Assert.AreEqual(ActionPropertyValueFull, setOutput.Action); + Assert.AreEqual(action, setOutput.Action); AssertSettingsAreEqual(expected, setOutput.Settings); AssertDiffState(setDiff, []); } /// - /// Calls `set` on the `user-settings` resource to add fields. + /// Calls `set` on the `user-settings-file` resource to add fields. /// /// The action value. [Test] @@ -114,14 +114,37 @@ public void UserSettingsFile_Set_AddFields(string action) // Assert that the settings are added Assert.IsNotNull(setOutput); - Assert.AreEqual(ActionPropertyValueFull, setOutput.Action); + Assert.AreEqual(action, setOutput.Action); AssertMockProperties(setOutput.Settings, "mock"); AssertSettingsAreEqual(expected, setOutput.Settings); AssertDiffState(setDiff, [ SettingsPropertyName ]); } /// - /// Calls `set` on the `user-settings` resource to update fields. + /// Calls `set` on the `user-settings-file` resource to ensure action is partial by default. + /// + [Test] + public void UserSettingsFile_Set_ActionIsPartialByDefault() + { + // Call `set` to add mock properties to the settings + var setSettings = GetSettingsArg(ActionPropertyValuePartial); + AddOrModifyMockProperties(setSettings, "mock"); + + var expected = GetCurrentUserSettings(); + AddOrModifyMockProperties(expected, "mock"); + + (var setOutput, var setDiff) = Set(new () { Settings = setSettings }); + + // Assert that the settings are added + Assert.IsNotNull(setOutput); + Assert.AreEqual(setOutput.Action, ActionPropertyValuePartial); + AssertMockProperties(setOutput.Settings, "mock"); + AssertSettingsAreEqual(expected, setOutput.Settings); + AssertDiffState(setDiff, [ SettingsPropertyName ]); + } + + /// + /// Calls `set` on the `user-settings-file` resource to update fields. /// /// The action value. [Test] @@ -144,14 +167,14 @@ public void UserSettingsFile_Set_UpdateFields(string action) // Assert that the settings are updated Assert.IsNotNull(setOutput); - Assert.AreEqual(ActionPropertyValueFull, setOutput.Action); + Assert.AreEqual(action, setOutput.Action); AssertMockProperties(setOutput.Settings, "mock_new"); AssertSettingsAreEqual(expected, setOutput.Settings); AssertDiffState(setDiff, [ SettingsPropertyName ]); } /// - /// Calls `test` on the `user-settings` resource to check if the settings are in desired state. + /// Calls `test` on the `user-settings-file` resource to check if the settings are in desired state. /// /// The action value. [Test] @@ -174,7 +197,7 @@ public void UserSettingsFile_Test_InDesiredState(string action) // Assert that the settings are in desired state Assert.IsNotNull(testOutput); - Assert.AreEqual(ActionPropertyValueFull, testOutput.Action); + Assert.AreEqual(action, testOutput.Action); AssertMockProperties(testOutput.Settings, "mock"); AssertSettingsAreEqual(expected, testOutput.Settings); Assert.IsTrue(testOutput.InDesiredState); @@ -182,7 +205,7 @@ public void UserSettingsFile_Test_InDesiredState(string action) } /// - /// Calls `test` on the `user-settings` resource to check if the settings are not in desired state. + /// Calls `test` on the `user-settings-file` resource to check if the settings are not in desired state. /// /// The action value. [Test] @@ -205,7 +228,7 @@ public void UserSettingsFile_Test_NotInDesiredState(string action) // Assert that the settings are not in desired state Assert.IsNotNull(testOutput); - Assert.AreEqual(ActionPropertyValueFull, testOutput.Action); + Assert.AreEqual(action, testOutput.Action); AssertMockProperties(testOutput.Settings, "mock_set"); AssertSettingsAreEqual(expected, testOutput.Settings); Assert.IsFalse(testOutput.InDesiredState); @@ -213,7 +236,7 @@ public void UserSettingsFile_Test_NotInDesiredState(string action) } /// - /// Calls `export` on the `user-settings` resource to export the settings. + /// Calls `export` on the `user-settings-file` resource to export the settings. /// [Test] public void UserSettingsFile_Export() @@ -222,12 +245,12 @@ public void UserSettingsFile_Export() var exportOutput = Export(new ()); Assert.IsNotNull(exportOutput); - Assert.AreEqual(ActionPropertyValueFull, exportOutput.Action); + Assert.IsNull(exportOutput.Action); AssertSettingsAreEqual(expected, exportOutput.Settings); } /// - /// Calls `get` on the `user-settings` resource. + /// Calls `get` on the `user-settings-file` resource. /// /// The input resource data. /// The output resource data. @@ -239,7 +262,7 @@ private static UserSettingsFileResourceData Get(UserSettingsFileResourceData res } /// - /// Calls `set` on the `user-settings` resource. + /// Calls `set` on the `user-settings-file` resource. /// /// The input resource data. /// The output resource data and the diff. @@ -251,7 +274,7 @@ private static (UserSettingsFileResourceData, List) Set(UserSettingsFile } /// - /// Calls `test` on the `user-settings` resource. + /// Calls `test` on the `user-settings-file` resource. /// /// The input resource data. /// The output resource data and the diff. @@ -263,7 +286,7 @@ private static (UserSettingsFileResourceData, List) Test(UserSettingsFil } /// - /// Calls `export` on the `user-settings` resource. + /// Calls `export` on the `user-settings-file` resource. /// /// The input resource data. /// The output resource data. @@ -333,6 +356,7 @@ private class UserSettingsFileResourceData [JsonPropertyName(InDesiredStatePropertyName)] public bool? InDesiredState { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string Action { get; set; } public JsonObject Settings { get; set; }