Skip to content

Commit 24bb391

Browse files
committed
Make partial the default
1 parent 8a8bfa7 commit 24bb391

2 files changed

Lines changed: 45 additions & 20 deletions

File tree

src/AppInstallerCLICore/Commands/DscUserSettingsFileResource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace AppInstaller::CLI
1616
namespace
1717
{
1818
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(SettingsProperty, Json::Value, Settings, "settings", DscComposablePropertyFlag::Required | DscComposablePropertyFlag::CopyToOutput, Resource::String::DscResourcePropertyDescriptionUserSettingsFileSettings);
19-
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_FULL);
19+
WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(ActionProperty, std::string, Action, "action", Resource::String::DscResourcePropertyDescriptionUserSettingsFileAction, ({ ACTION_PARTIAL, ACTION_FULL }), ACTION_PARTIAL);
2020

2121
using UserSettingsFileResourceObject = DscComposableObject<StandardInDesiredStateProperty, SettingsProperty, ActionProperty>;
2222

@@ -38,7 +38,7 @@ namespace AppInstaller::CLI
3838

3939
void Get()
4040
{
41-
Output.Action(ACTION_FULL);
41+
Output.Action(ACTION_PARTIAL);
4242
Output.Settings(GetUserSettings());
4343
}
4444

src/AppInstallerCLIE2ETests/DSCv3UserSettingsFileResourceCommand.cs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Setup()
6161
}
6262

6363
/// <summary>
64-
/// Calls `get` on the `user-settings` resource.
64+
/// Calls `get` on the `user-settings-file` resource.
6565
/// </summary>
6666
[Test]
6767
public void UserSettingsFile_Get()
@@ -70,12 +70,12 @@ public void UserSettingsFile_Get()
7070
var getOutput = Get(new ());
7171

7272
Assert.IsNotNull(getOutput);
73-
Assert.AreEqual(ActionPropertyValueFull, getOutput.Action);
73+
Assert.AreEqual(ActionPropertyValuePartial, getOutput.Action);
7474
AssertSettingsAreEqual(expected, getOutput.Settings);
7575
}
7676

7777
/// <summary>
78-
/// Calls `set` on the `user-settings` resource with no diff.
78+
/// Calls `set` on the `user-settings-file` resource with no diff.
7979
/// </summary>
8080
/// <param name="action">The action value.</param>
8181
[Test]
@@ -90,13 +90,13 @@ public void UserSettingsFile_Set_NoDiff(string action)
9090
var expected = GetCurrentUserSettings();
9191

9292
Assert.IsNotNull(setOutput);
93-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
93+
Assert.AreEqual(ActionPropertyValuePartial, setOutput.Action);
9494
AssertSettingsAreEqual(expected, setOutput.Settings);
9595
AssertDiffState(setDiff, []);
9696
}
9797

9898
/// <summary>
99-
/// Calls `set` on the `user-settings` resource to add fields.
99+
/// Calls `set` on the `user-settings-file` resource to add fields.
100100
/// </summary>
101101
/// <param name="action">The action value.</param>
102102
[Test]
@@ -114,14 +114,38 @@ public void UserSettingsFile_Set_AddFields(string action)
114114

115115
// Assert that the settings are added
116116
Assert.IsNotNull(setOutput);
117-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
117+
Assert.AreEqual(ActionPropertyValuePartial, setOutput.Action);
118118
AssertMockProperties(setOutput.Settings, "mock");
119119
AssertSettingsAreEqual(expected, setOutput.Settings);
120120
AssertDiffState(setDiff, [ SettingsPropertyName ]);
121121
}
122122

123123
/// <summary>
124-
/// Calls `set` on the `user-settings` resource to update fields.
124+
/// Calls `set` on the `user-settings-file` resource to ensure action is partial by default.
125+
/// </summary>
126+
[Test]
127+
public void UserSettingsFile_Set_ActionIsPartialByDefault()
128+
{
129+
// Call `set` to add mock properties to the settings
130+
var setSettings = GetSettingsArg(ActionPropertyValuePartial);
131+
AddOrModifyMockProperties(setSettings, "mock");
132+
133+
var expected = GetCurrentUserSettings();
134+
AddOrModifyMockProperties(expected, "mock");
135+
136+
(var setOutput, var setDiff) = Set(new () { Settings = setSettings });
137+
138+
139+
// Assert that the settings are added
140+
Assert.IsNotNull(setOutput);
141+
Assert.AreEqual(ActionPropertyValuePartial, setOutput.Action);
142+
AssertMockProperties(setOutput.Settings, "mock");
143+
AssertSettingsAreEqual(expected, setOutput.Settings);
144+
AssertDiffState(setDiff, [ SettingsPropertyName ]);
145+
}
146+
147+
/// <summary>
148+
/// Calls `set` on the `user-settings-file` resource to update fields.
125149
/// </summary>
126150
/// <param name="action">The action value.</param>
127151
[Test]
@@ -144,14 +168,14 @@ public void UserSettingsFile_Set_UpdateFields(string action)
144168

145169
// Assert that the settings are updated
146170
Assert.IsNotNull(setOutput);
147-
Assert.AreEqual(ActionPropertyValueFull, setOutput.Action);
171+
Assert.AreEqual(ActionPropertyValuePartial, setOutput.Action);
148172
AssertMockProperties(setOutput.Settings, "mock_new");
149173
AssertSettingsAreEqual(expected, setOutput.Settings);
150174
AssertDiffState(setDiff, [ SettingsPropertyName ]);
151175
}
152176

153177
/// <summary>
154-
/// Calls `test` on the `user-settings` resource to check if the settings are in desired state.
178+
/// Calls `test` on the `user-settings-file` resource to check if the settings are in desired state.
155179
/// </summary>
156180
/// <param name="action">The action value.</param>
157181
[Test]
@@ -174,15 +198,15 @@ public void UserSettingsFile_Test_InDesiredState(string action)
174198

175199
// Assert that the settings are in desired state
176200
Assert.IsNotNull(testOutput);
177-
Assert.AreEqual(ActionPropertyValueFull, testOutput.Action);
201+
Assert.AreEqual(ActionPropertyValuePartial, testOutput.Action);
178202
AssertMockProperties(testOutput.Settings, "mock");
179203
AssertSettingsAreEqual(expected, testOutput.Settings);
180204
Assert.IsTrue(testOutput.InDesiredState);
181205
AssertDiffState(testDiff, []);
182206
}
183207

184208
/// <summary>
185-
/// Calls `test` on the `user-settings` resource to check if the settings are not in desired state.
209+
/// Calls `test` on the `user-settings-file` resource to check if the settings are not in desired state.
186210
/// </summary>
187211
/// <param name="action">The action value.</param>
188212
[Test]
@@ -205,15 +229,15 @@ public void UserSettingsFile_Test_NotInDesiredState(string action)
205229

206230
// Assert that the settings are not in desired state
207231
Assert.IsNotNull(testOutput);
208-
Assert.AreEqual(ActionPropertyValueFull, testOutput.Action);
232+
Assert.AreEqual(ActionPropertyValuePartial, testOutput.Action);
209233
AssertMockProperties(testOutput.Settings, "mock_set");
210234
AssertSettingsAreEqual(expected, testOutput.Settings);
211235
Assert.IsFalse(testOutput.InDesiredState);
212236
AssertDiffState(testDiff, [ SettingsPropertyName ]);
213237
}
214238

215239
/// <summary>
216-
/// Calls `export` on the `user-settings` resource to export the settings.
240+
/// Calls `export` on the `user-settings-file` resource to export the settings.
217241
/// </summary>
218242
[Test]
219243
public void UserSettingsFile_Export()
@@ -222,12 +246,12 @@ public void UserSettingsFile_Export()
222246
var exportOutput = Export(new ());
223247

224248
Assert.IsNotNull(exportOutput);
225-
Assert.AreEqual(ActionPropertyValueFull, exportOutput.Action);
249+
Assert.AreEqual(ActionPropertyValuePartial, exportOutput.Action);
226250
AssertSettingsAreEqual(expected, exportOutput.Settings);
227251
}
228252

229253
/// <summary>
230-
/// Calls `get` on the `user-settings` resource.
254+
/// Calls `get` on the `user-settings-file` resource.
231255
/// </summary>
232256
/// <param name="resourceData">The input resource data.</param>
233257
/// <returns>The output resource data.</returns>
@@ -239,7 +263,7 @@ private static UserSettingsFileResourceData Get(UserSettingsFileResourceData res
239263
}
240264

241265
/// <summary>
242-
/// Calls `set` on the `user-settings` resource.
266+
/// Calls `set` on the `user-settings-file` resource.
243267
/// </summary>
244268
/// <param name="resourceData">The input resource data.</param>
245269
/// <returns>The output resource data and the diff.</returns>
@@ -251,7 +275,7 @@ private static (UserSettingsFileResourceData, List<string>) Set(UserSettingsFile
251275
}
252276

253277
/// <summary>
254-
/// Calls `test` on the `user-settings` resource.
278+
/// Calls `test` on the `user-settings-file` resource.
255279
/// </summary>
256280
/// <param name="resourceData">The input resource data.</param>
257281
/// <returns>The output resource data and the diff.</returns>
@@ -263,7 +287,7 @@ private static (UserSettingsFileResourceData, List<string>) Test(UserSettingsFil
263287
}
264288

265289
/// <summary>
266-
/// Calls `export` on the `user-settings` resource.
290+
/// Calls `export` on the `user-settings-file` resource.
267291
/// </summary>
268292
/// <param name="resourceData">The input resource data.</param>
269293
/// <returns>The output resource data.</returns>
@@ -333,6 +357,7 @@ private class UserSettingsFileResourceData
333357
[JsonPropertyName(InDesiredStatePropertyName)]
334358
public bool? InDesiredState { get; set; }
335359

360+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
336361
public string Action { get; set; }
337362

338363
public JsonObject Settings { get; set; }

0 commit comments

Comments
 (0)