-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update configuration environment behavior (#5182)
## Change In response to some other discussions, update the configuration environment behavior: 1. Add an environment at the set level 2. Don't inherit environment data into child units, and don't promote environment data when serializing Updated the one consumer of environment (dynamic factory) to be responsible for the flow of the security context from the set to the immediate child units. Also improved serialization of groups to output the non-resource properties.
- Loading branch information
Showing
12 changed files
with
243 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/Microsoft.Management.Configuration.UnitTests/Helpers/ValueSetExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ----------------------------------------------------------------------------- | ||
// <copyright file="ValueSetExtensions.cs" company="Microsoft Corporation"> | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Management.Configuration.UnitTests.Helpers | ||
{ | ||
using System; | ||
using System.Text; | ||
using Windows.Foundation.Collections; | ||
|
||
/// <summary> | ||
/// Extensions for ValueSet. | ||
/// </summary> | ||
internal static class ValueSetExtensions | ||
{ | ||
/// <summary> | ||
/// Converts the value set to YAML like output. | ||
/// </summary> | ||
/// <param name="set">The set to output.</param> | ||
/// <returns>The string.</returns> | ||
public static string ToYaml(this ValueSet set) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
ToYaml(set, sb); | ||
return sb.ToString(); | ||
} | ||
|
||
private static void ToYaml(ValueSet set, StringBuilder sb, int indentation = 0) | ||
{ | ||
foreach (var keyValuePair in set) | ||
{ | ||
bool addLine = true; | ||
|
||
sb.Append(' ', indentation); | ||
sb.Append(keyValuePair.Key); | ||
sb.Append(": "); | ||
|
||
if (keyValuePair.Value == null) | ||
{ | ||
sb.Append("null"); | ||
} | ||
else | ||
{ | ||
switch (keyValuePair.Value) | ||
{ | ||
case int i: | ||
sb.Append(i); | ||
break; | ||
case string s: | ||
sb.Append(s); | ||
break; | ||
case bool b: | ||
sb.Append(b); | ||
break; | ||
case ValueSet v: | ||
sb.AppendLine(); | ||
ToYaml(v, sb, indentation + 2); | ||
addLine = false; | ||
break; | ||
default: | ||
throw new NotImplementedException($"Add ToYaml type `{keyValuePair.Value.GetType().Name}`"); | ||
} | ||
} | ||
|
||
if (addLine) | ||
{ | ||
sb.AppendLine(); | ||
} | ||
} | ||
} | ||
} | ||
} |
141 changes: 104 additions & 37 deletions
141
src/Microsoft.Management.Configuration.UnitTests/Tests/OpenConfigurationSetTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.