using NUnit.Framework; using Strata.RxNorm.Biz.Utilities; using System.Collections.Generic; using System.Text.Json; namespace Strata.RxNorm.Biz.Test.Unit.Utilities { [TestFixture] public class LogUtilsExtensionsTests { [TestCaseSource(nameof(TestCases))] public void Test(object input, object expected) { var dictionary = LogUtilsExtensions.ToDictionary(input); var expectedStr = JsonSerializer.Serialize(expected); var actualStr = JsonSerializer.Serialize(dictionary); Assert.That(actualStr, Is.EqualTo(expectedStr)); } public static IEnumerable TestCases() { yield return new TestCaseData(new { a = 1, b = "test" }, new Dictionary { { "a", 1 }, { "b", "test" } }); yield return new TestCaseData(new { a = 1, b = (string)null }, new Dictionary { { "a", 1 }, { "b", null } }); yield return new TestCaseData(new { a = 1, b = new { c = 2 } }, new Dictionary { { "a", 1 }, { "b", new Dictionary { { "c", 2 } } } }); yield return new TestCaseData(123, new Dictionary { { "object", 123 } }); yield return new TestCaseData("test", new Dictionary { { "object", "test" } }); } } }