Skip to content

Commit

Permalink
remove redundant ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed Feb 26, 2024
1 parent 5c18d93 commit 963a931
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 57 deletions.
48 changes: 0 additions & 48 deletions src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,54 +40,6 @@ public AsyncApiAny(object obj)
this.node = JsonNode.Parse(JsonSerializer.Serialize(obj, this.options));
}

/// <summary>
/// Initializes a new instance of the <see cref="AsyncApiAny"/> class.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
public AsyncApiAny(Dictionary<string, AsyncApiAny> dictionary)
{
var jsonObject = new JsonObject();
foreach (var kvp in dictionary)
{
jsonObject.Add(kvp.Key, kvp.Value.node);
}

this.node = jsonObject;
}

/// <summary>
/// Initializes a new instance of the <see cref="AsyncApiAny"/> class.
/// </summary>
/// <param name="list">The list.</param>
public AsyncApiAny(List<object> 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;
}

/// <summary>
/// Initializes a new instance of the <see cref="AsyncApiAny"/> class.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
public AsyncApiAny(Dictionary<string, object> 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;
}


/// <summary>
/// Initializes a new instance of the <see cref="AsyncApiAny"/> class.
/// </summary>
Expand Down
19 changes: 10 additions & 9 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LEGO.AsyncAPI.Tests
{
Expand All @@ -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<string>() { "test", "test2"});
var g = new AsyncApiAny(new List<MyType>() { new MyType("test") });
var h = new AsyncApiAny(new Dictionary<string, int>() { { "t", 2 } });
var i = new AsyncApiAny(new Dictionary<string, MyType>() { { "t", new MyType("test") } });
var g = new AsyncApiAny(new List<string>() { "test", "test2"}.AsEnumerable());
var h = new AsyncApiAny(new List<MyType>() { new MyType("test") });
var i = new AsyncApiAny(new Dictionary<string, int>() { { "t", 2 } });
var j = new AsyncApiAny(new Dictionary<string, MyType>() { { "t", new MyType("test") } });

// Assert
Assert.AreEqual("string", a.GetValue<string>());
Expand All @@ -34,10 +33,12 @@ public void GetValue_ReturnsCorrectConversions()
Assert.NotNull(e.GetValue<MyType>());
Assert.IsNotEmpty(f.GetValue<List<string>>());
Assert.IsNotEmpty(f.GetValue<IEnumerable<string>>());
Assert.IsNotEmpty(g.GetValue<List<MyType>>());
Assert.IsNotEmpty(g.GetValue<IEnumerable<MyType>>());
Assert.IsNotEmpty(h.GetValue<Dictionary<string, int>>());
Assert.IsNotEmpty(i.GetValue<Dictionary<string, MyType>>());
Assert.IsNotEmpty(g.GetValue<List<string>>());
Assert.IsNotEmpty(g.GetValue<IEnumerable<string>>());
Assert.IsNotEmpty(h.GetValue<List<MyType>>());
Assert.IsNotEmpty(h.GetValue<IEnumerable<MyType>>());
Assert.IsNotEmpty(i.GetValue<Dictionary<string, int>>());
Assert.IsNotEmpty(j.GetValue<Dictionary<string, MyType>>());
}

class MyType
Expand Down

0 comments on commit 963a931

Please sign in to comment.