From 26079a0ed3c2ed3a0035f7eaae9c7915c58889d4 Mon Sep 17 00:00:00 2001 From: John McPherson Date: Wed, 5 Feb 2025 14:47:05 -0800 Subject: [PATCH] Move test function to tests --- .../Extensions/ValueSetExtensions.cs | 58 --------------- .../Helpers/ValueSetExtensions.cs | 74 +++++++++++++++++++ 2 files changed, 74 insertions(+), 58 deletions(-) create mode 100644 src/Microsoft.Management.Configuration.UnitTests/Helpers/ValueSetExtensions.cs diff --git a/src/Microsoft.Management.Configuration.Processor/Extensions/ValueSetExtensions.cs b/src/Microsoft.Management.Configuration.Processor/Extensions/ValueSetExtensions.cs index b65c1db93b..baea81dc19 100644 --- a/src/Microsoft.Management.Configuration.Processor/Extensions/ValueSetExtensions.cs +++ b/src/Microsoft.Management.Configuration.Processor/Extensions/ValueSetExtensions.cs @@ -9,8 +9,6 @@ namespace Microsoft.Management.Configuration.Processor.Extensions using System; using System.Collections; using System.Collections.Generic; - using System.Text; - using System.Xml.Linq; using Windows.Foundation.Collections; /// @@ -177,61 +175,5 @@ public static bool ContentEquals(this ValueSet first, ValueSet second) return true; } - - /// - /// Converts the value set to YAML like output. - /// - /// The set to output. - /// The string. - 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(); - } - } - } } } diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/ValueSetExtensions.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/ValueSetExtensions.cs new file mode 100644 index 0000000000..f87f093157 --- /dev/null +++ b/src/Microsoft.Management.Configuration.UnitTests/Helpers/ValueSetExtensions.cs @@ -0,0 +1,74 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.Management.Configuration.UnitTests.Helpers +{ + using System; + using System.Text; + using Windows.Foundation.Collections; + + /// + /// Extensions for ValueSet. + /// + internal static class ValueSetExtensions + { + /// + /// Converts the value set to YAML like output. + /// + /// The set to output. + /// The string. + 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(); + } + } + } + } +}