From 963a9315908e264d6a2f382fb3672b5821b95223 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 11:58:54 +0100 Subject: [PATCH] remove redundant ctors --- src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 48 ------------------- .../Models/AsyncApiAnyTests.cs | 19 ++++---- 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index ea926853..c9c0c926 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -40,54 +40,6 @@ public AsyncApiAny(object obj) this.node = JsonNode.Parse(JsonSerializer.Serialize(obj, this.options)); } - /// - /// Initializes a new instance of the class. - /// - /// The dictionary. - public AsyncApiAny(Dictionary dictionary) - { - var jsonObject = new JsonObject(); - foreach (var kvp in dictionary) - { - jsonObject.Add(kvp.Key, kvp.Value.node); - } - - this.node = jsonObject; - } - - /// - /// Initializes a new instance of the class. - /// - /// The list. - public AsyncApiAny(List list) - { - var jsonArray = new JsonArray(); - foreach (var item in list) - { - string jsonString = JsonSerializer.Serialize(item, this.options); - jsonArray.Add(JsonNode.Parse(jsonString)); - } - - this.node = jsonArray; - } - - /// - /// Initializes a new instance of the class. - /// - /// The dictionary. - public AsyncApiAny(Dictionary dictionary) - { - var jsonObject = new JsonObject(); - foreach (var kvp in dictionary) - { - string jsonString = JsonSerializer.Serialize(kvp.Value, this.options); - jsonObject.Add(kvp.Key, JsonNode.Parse(jsonString)); - } - - this.node = jsonObject; - } - - /// /// Initializes a new instance of the class. /// diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs index e335b6b1..08f1682c 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LEGO.AsyncAPI.Tests { @@ -22,9 +20,10 @@ public void GetValue_ReturnsCorrectConversions() var d = new AsyncApiAny(true); var e = new AsyncApiAny(new MyType("test")); var f = new AsyncApiAny(new List() { "test", "test2"}); - var g = new AsyncApiAny(new List() { new MyType("test") }); - var h = new AsyncApiAny(new Dictionary() { { "t", 2 } }); - var i = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); + var g = new AsyncApiAny(new List() { "test", "test2"}.AsEnumerable()); + var h = new AsyncApiAny(new List() { new MyType("test") }); + var i = new AsyncApiAny(new Dictionary() { { "t", 2 } }); + var j = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); // Assert Assert.AreEqual("string", a.GetValue()); @@ -34,10 +33,12 @@ public void GetValue_ReturnsCorrectConversions() Assert.NotNull(e.GetValue()); Assert.IsNotEmpty(f.GetValue>()); Assert.IsNotEmpty(f.GetValue>()); - Assert.IsNotEmpty(g.GetValue>()); - Assert.IsNotEmpty(g.GetValue>()); - Assert.IsNotEmpty(h.GetValue>()); - Assert.IsNotEmpty(i.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(h.GetValue>()); + Assert.IsNotEmpty(h.GetValue>()); + Assert.IsNotEmpty(i.GetValue>()); + Assert.IsNotEmpty(j.GetValue>()); } class MyType