Skip to content

Commit 639838a

Browse files
committed
Release 0.6.0
1 parent 0c00024 commit 639838a

File tree

727 files changed

+26311
-3484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

727 files changed

+26311
-3484
lines changed

.editorconfig

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
root = true
2+
3+
[*.cs]
4+
resharper_arrange_object_creation_when_type_evident_highlighting = hint
5+
resharper_auto_property_can_be_made_get_only_global_highlighting = hint
6+
resharper_check_namespace_highlighting = hint
7+
resharper_class_never_instantiated_global_highlighting = hint
8+
resharper_class_never_instantiated_local_highlighting = hint
9+
resharper_collection_never_updated_global_highlighting = hint
10+
resharper_convert_type_check_pattern_to_null_check_highlighting = hint
11+
resharper_inconsistent_naming_highlighting = hint
12+
resharper_member_can_be_private_global_highlighting = hint
13+
resharper_member_hides_static_from_outer_class_highlighting = hint
14+
resharper_not_accessed_field_local_highlighting = hint
15+
resharper_nullable_warning_suppression_is_used_highlighting = suggestion
16+
resharper_partial_type_with_single_part_highlighting = hint
17+
resharper_prefer_concrete_value_over_default_highlighting = none
18+
resharper_private_field_can_be_converted_to_local_variable_highlighting = hint
19+
resharper_property_can_be_made_init_only_global_highlighting = hint
20+
resharper_property_can_be_made_init_only_local_highlighting = hint
21+
resharper_redundant_name_qualifier_highlighting = none
22+
resharper_redundant_using_directive_highlighting = hint
23+
resharper_replace_slice_with_range_indexer_highlighting = none
24+
resharper_unused_auto_property_accessor_global_highlighting = hint
25+
resharper_unused_auto_property_accessor_local_highlighting = hint
26+
resharper_unused_member_global_highlighting = hint
27+
resharper_unused_type_global_highlighting = hint
28+
resharper_use_string_interpolation_highlighting = hint
29+
dotnet_diagnostic.CS1591.severity = suggestion
30+
31+
[src/**/Types/*.cs]
32+
resharper_check_namespace_highlighting = none
33+
34+
[src/**/Core/Public/*.cs]
35+
resharper_check_namespace_highlighting = none
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using NUnit.Framework;
2+
using Vapi.Net.Core;
3+
4+
namespace Vapi.Net.Test.Core.Json;
5+
6+
[TestFixture]
7+
public class DateOnlyJsonTests
8+
{
9+
[Test]
10+
public void SerializeDateOnly_ShouldMatchExpectedFormat()
11+
{
12+
(DateOnly dateOnly, string expected)[] testCases =
13+
[
14+
(new DateOnly(2023, 10, 5), "\"2023-10-05\""),
15+
(new DateOnly(2023, 1, 1), "\"2023-01-01\""),
16+
(new DateOnly(2023, 12, 31), "\"2023-12-31\""),
17+
(new DateOnly(2023, 6, 15), "\"2023-06-15\""),
18+
(new DateOnly(2023, 3, 10), "\"2023-03-10\""),
19+
];
20+
foreach (var (dateOnly, expected) in testCases)
21+
{
22+
var json = JsonUtils.Serialize(dateOnly);
23+
Assert.That(json, Is.EqualTo(expected));
24+
}
25+
}
26+
27+
[Test]
28+
public void DeserializeDateOnly_ShouldMatchExpectedDateOnly()
29+
{
30+
(DateOnly expected, string json)[] testCases =
31+
[
32+
(new DateOnly(2023, 10, 5), "\"2023-10-05\""),
33+
(new DateOnly(2023, 1, 1), "\"2023-01-01\""),
34+
(new DateOnly(2023, 12, 31), "\"2023-12-31\""),
35+
(new DateOnly(2023, 6, 15), "\"2023-06-15\""),
36+
(new DateOnly(2023, 3, 10), "\"2023-03-10\""),
37+
];
38+
39+
foreach (var (expected, json) in testCases)
40+
{
41+
var dateOnly = JsonUtils.Deserialize<DateOnly>(json);
42+
Assert.That(dateOnly, Is.EqualTo(expected));
43+
}
44+
}
45+
46+
[Test]
47+
public void SerializeNullableDateOnly_ShouldMatchExpectedFormat()
48+
{
49+
(DateOnly? dateOnly, string expected)[] testCases =
50+
[
51+
(new DateOnly(2023, 10, 5), "\"2023-10-05\""),
52+
(null, "null"),
53+
];
54+
foreach (var (dateOnly, expected) in testCases)
55+
{
56+
var json = JsonUtils.Serialize(dateOnly);
57+
Assert.That(json, Is.EqualTo(expected));
58+
}
59+
}
60+
61+
[Test]
62+
public void DeserializeNullableDateOnly_ShouldMatchExpectedDateOnly()
63+
{
64+
(DateOnly? expected, string json)[] testCases =
65+
[
66+
(new DateOnly(2023, 10, 5), "\"2023-10-05\""),
67+
(null, "null"),
68+
];
69+
70+
foreach (var (expected, json) in testCases)
71+
{
72+
var dateOnly = JsonUtils.Deserialize<DateOnly?>(json);
73+
Assert.That(dateOnly, Is.EqualTo(expected));
74+
}
75+
}
76+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using NUnit.Framework;
2+
using Vapi.Net.Core;
3+
4+
namespace Vapi.Net.Test.Core.Json;
5+
6+
[TestFixture]
7+
public class DateTimeJsonTests
8+
{
9+
[Test]
10+
public void SerializeDateTime_ShouldMatchExpectedFormat()
11+
{
12+
(DateTime dateTime, string expected)[] testCases =
13+
[
14+
(
15+
new DateTime(2023, 10, 5, 14, 30, 0, DateTimeKind.Utc),
16+
"\"2023-10-05T14:30:00.000Z\""
17+
),
18+
(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), "\"2023-01-01T00:00:00.000Z\""),
19+
(
20+
new DateTime(2023, 12, 31, 23, 59, 59, DateTimeKind.Utc),
21+
"\"2023-12-31T23:59:59.000Z\""
22+
),
23+
(new DateTime(2023, 6, 15, 12, 0, 0, DateTimeKind.Utc), "\"2023-06-15T12:00:00.000Z\""),
24+
(
25+
new DateTime(2023, 3, 10, 8, 45, 30, DateTimeKind.Utc),
26+
"\"2023-03-10T08:45:30.000Z\""
27+
),
28+
(
29+
new DateTime(2023, 3, 10, 8, 45, 30, 123, DateTimeKind.Utc),
30+
"\"2023-03-10T08:45:30.123Z\""
31+
),
32+
];
33+
foreach (var (dateTime, expected) in testCases)
34+
{
35+
var json = JsonUtils.Serialize(dateTime);
36+
Assert.That(json, Is.EqualTo(expected));
37+
}
38+
}
39+
40+
[Test]
41+
public void DeserializeDateTime_ShouldMatchExpectedDateTime()
42+
{
43+
(DateTime expected, string json)[] testCases =
44+
[
45+
(
46+
new DateTime(2023, 10, 5, 14, 30, 0, DateTimeKind.Utc),
47+
"\"2023-10-05T14:30:00.000Z\""
48+
),
49+
(new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), "\"2023-01-01T00:00:00.000Z\""),
50+
(
51+
new DateTime(2023, 12, 31, 23, 59, 59, DateTimeKind.Utc),
52+
"\"2023-12-31T23:59:59.000Z\""
53+
),
54+
(new DateTime(2023, 6, 15, 12, 0, 0, DateTimeKind.Utc), "\"2023-06-15T12:00:00.000Z\""),
55+
(
56+
new DateTime(2023, 3, 10, 8, 45, 30, DateTimeKind.Utc),
57+
"\"2023-03-10T08:45:30.000Z\""
58+
),
59+
(new DateTime(2023, 3, 10, 8, 45, 30, DateTimeKind.Utc), "\"2023-03-10T08:45:30Z\""),
60+
(
61+
new DateTime(2023, 3, 10, 8, 45, 30, 123, DateTimeKind.Utc),
62+
"\"2023-03-10T08:45:30.123Z\""
63+
),
64+
];
65+
66+
foreach (var (expected, json) in testCases)
67+
{
68+
var dateTime = JsonUtils.Deserialize<DateTime>(json);
69+
Assert.That(dateTime, Is.EqualTo(expected));
70+
}
71+
}
72+
73+
[Test]
74+
public void SerializeNullableDateTime_ShouldMatchExpectedFormat()
75+
{
76+
(DateTime? expected, string json)[] testCases =
77+
[
78+
(
79+
new DateTime(2023, 10, 5, 14, 30, 0, DateTimeKind.Utc),
80+
"\"2023-10-05T14:30:00.000Z\""
81+
),
82+
(null, "null"),
83+
];
84+
85+
foreach (var (expected, json) in testCases)
86+
{
87+
var dateTime = JsonUtils.Deserialize<DateTime?>(json);
88+
Assert.That(dateTime, Is.EqualTo(expected));
89+
}
90+
}
91+
92+
[Test]
93+
public void DeserializeNullableDateTime_ShouldMatchExpectedDateTime()
94+
{
95+
(DateTime? expected, string json)[] testCases =
96+
[
97+
(
98+
new DateTime(2023, 10, 5, 14, 30, 0, DateTimeKind.Utc),
99+
"\"2023-10-05T14:30:00.000Z\""
100+
),
101+
(null, "null"),
102+
];
103+
104+
foreach (var (expected, json) in testCases)
105+
{
106+
var dateTime = JsonUtils.Deserialize<DateTime?>(json);
107+
Assert.That(dateTime, Is.EqualTo(expected));
108+
}
109+
}
110+
}

src/Vapi.Net.Test/Core/EnumSerializerTests.cs renamed to src/Vapi.Net.Test/Core/Json/EnumSerializerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using NUnit.Framework;
55
using Vapi.Net.Core;
66

7-
namespace Vapi.Net.Test.Core;
7+
namespace Vapi.Net.Test.Core.Json;
88

99
[TestFixture]
1010
[Parallelizable(ParallelScope.All)]
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
using global::System.Text.Json.Serialization;
2+
using NUnit.Framework;
3+
using Vapi.Net.Core;
4+
5+
namespace Vapi.Net.Test.Core.Json;
6+
7+
[TestFixture]
8+
public class JsonAccessAttributeTests
9+
{
10+
private class MyClass
11+
{
12+
[JsonPropertyName("read_only_prop")]
13+
[JsonAccess(JsonAccessType.ReadOnly)]
14+
public string? ReadOnlyProp { get; set; }
15+
16+
[JsonPropertyName("write_only_prop")]
17+
[JsonAccess(JsonAccessType.WriteOnly)]
18+
public string? WriteOnlyProp { get; set; }
19+
20+
[JsonPropertyName("normal_prop")]
21+
public string? NormalProp { get; set; }
22+
23+
[JsonPropertyName("read_only_nullable_list")]
24+
[JsonAccess(JsonAccessType.ReadOnly)]
25+
public IEnumerable<string>? ReadOnlyNullableList { get; set; }
26+
27+
[JsonPropertyName("read_only_list")]
28+
[JsonAccess(JsonAccessType.ReadOnly)]
29+
public IEnumerable<string> ReadOnlyList { get; set; } = [];
30+
31+
[JsonPropertyName("write_only_nullable_list")]
32+
[JsonAccess(JsonAccessType.WriteOnly)]
33+
public IEnumerable<string>? WriteOnlyNullableList { get; set; }
34+
35+
[JsonPropertyName("write_only_list")]
36+
[JsonAccess(JsonAccessType.WriteOnly)]
37+
public IEnumerable<string> WriteOnlyList { get; set; } = [];
38+
39+
[JsonPropertyName("normal_list")]
40+
public IEnumerable<string> NormalList { get; set; } = [];
41+
42+
[JsonPropertyName("normal_nullable_list")]
43+
public IEnumerable<string>? NullableNormalList { get; set; }
44+
}
45+
46+
[Test]
47+
public void JsonAccessAttribute_ShouldWorkAsExpected()
48+
{
49+
const string json = """
50+
{
51+
"read_only_prop": "read",
52+
"write_only_prop": "write",
53+
"normal_prop": "normal_prop",
54+
"read_only_nullable_list": ["item1", "item2"],
55+
"read_only_list": ["item3", "item4"],
56+
"write_only_nullable_list": ["item5", "item6"],
57+
"write_only_list": ["item7", "item8"],
58+
"normal_list": ["normal1", "normal2"],
59+
"normal_nullable_list": ["normal1", "normal2"]
60+
}
61+
""";
62+
var obj = JsonUtils.Deserialize<MyClass>(json);
63+
64+
Assert.Multiple(() =>
65+
{
66+
// String properties
67+
Assert.That(obj.ReadOnlyProp, Is.EqualTo("read"));
68+
Assert.That(obj.WriteOnlyProp, Is.Null);
69+
Assert.That(obj.NormalProp, Is.EqualTo("normal_prop"));
70+
71+
// List properties - read only
72+
var nullableReadOnlyList = obj.ReadOnlyNullableList?.ToArray();
73+
Assert.That(nullableReadOnlyList, Is.Not.Null);
74+
Assert.That(nullableReadOnlyList, Has.Length.EqualTo(2));
75+
Assert.That(nullableReadOnlyList[0], Is.EqualTo("item1"));
76+
Assert.That(nullableReadOnlyList[1], Is.EqualTo("item2"));
77+
78+
var readOnlyList = obj.ReadOnlyList.ToArray();
79+
Assert.That(readOnlyList, Is.Not.Null);
80+
Assert.That(readOnlyList, Has.Length.EqualTo(2));
81+
Assert.That(readOnlyList[0], Is.EqualTo("item3"));
82+
Assert.That(readOnlyList[1], Is.EqualTo("item4"));
83+
84+
// List properties - write only
85+
Assert.That(obj.WriteOnlyNullableList, Is.Null);
86+
Assert.That(obj.WriteOnlyList, Is.Not.Null);
87+
Assert.That(obj.WriteOnlyList, Is.Empty);
88+
89+
// Normal list property
90+
var normalList = obj.NormalList.ToArray();
91+
Assert.That(normalList, Is.Not.Null);
92+
Assert.That(normalList, Has.Length.EqualTo(2));
93+
Assert.That(normalList[0], Is.EqualTo("normal1"));
94+
Assert.That(normalList[1], Is.EqualTo("normal2"));
95+
});
96+
97+
// Set up values for serialization
98+
obj.WriteOnlyProp = "write";
99+
obj.NormalProp = "new_value";
100+
obj.WriteOnlyNullableList = new List<string> { "write1", "write2" };
101+
obj.WriteOnlyList = new List<string> { "write3", "write4" };
102+
obj.NormalList = new List<string> { "new_normal" };
103+
obj.NullableNormalList = new List<string> { "new_normal" };
104+
105+
var serializedJson = JsonUtils.Serialize(obj);
106+
const string expectedJson = """
107+
{
108+
"write_only_prop": "write",
109+
"normal_prop": "new_value",
110+
"write_only_nullable_list": [
111+
"write1",
112+
"write2"
113+
],
114+
"write_only_list": [
115+
"write3",
116+
"write4"
117+
],
118+
"normal_list": [
119+
"new_normal"
120+
],
121+
"normal_nullable_list": [
122+
"new_normal"
123+
]
124+
}
125+
""";
126+
Assert.That(serializedJson, Is.EqualTo(expectedJson).IgnoreWhiteSpace);
127+
}
128+
129+
[Test]
130+
public void JsonAccessAttribute_WithNullListsInJson_ShouldWorkAsExpected()
131+
{
132+
const string json = """
133+
{
134+
"read_only_prop": "read",
135+
"normal_prop": "normal_prop",
136+
"read_only_nullable_list": null,
137+
"read_only_list": []
138+
}
139+
""";
140+
var obj = JsonUtils.Deserialize<MyClass>(json);
141+
142+
Assert.Multiple(() =>
143+
{
144+
// Read-only nullable list should be null when JSON contains null
145+
var nullableReadOnlyList = obj.ReadOnlyNullableList?.ToArray();
146+
Assert.That(nullableReadOnlyList, Is.Null);
147+
148+
// Read-only non-nullable list should never be null, but empty when JSON contains null
149+
var readOnlyList = obj.ReadOnlyList.ToArray(); // This should be initialized to an empty list by default
150+
Assert.That(readOnlyList, Is.Not.Null);
151+
Assert.That(readOnlyList, Is.Empty);
152+
});
153+
154+
// Serialize and verify read-only lists are not included
155+
var serializedJson = JsonUtils.Serialize(obj);
156+
Assert.That(serializedJson, Does.Not.Contain("read_only_prop"));
157+
Assert.That(serializedJson, Does.Not.Contain("read_only_nullable_list"));
158+
Assert.That(serializedJson, Does.Not.Contain("read_only_list"));
159+
}
160+
}

0 commit comments

Comments
 (0)