Skip to content

Commit

Permalink
Move test function to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS committed Feb 5, 2025
1 parent e182229 commit 26079a0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -177,61 +175,5 @@ public static bool ContentEquals(this ValueSet first, ValueSet second)

return true;
}

/// <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();
}
}
}
}
}
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();
}
}
}
}
}

0 comments on commit 26079a0

Please sign in to comment.