Skip to content

Commit 9d30adb

Browse files
committed
add test for json serialize
1 parent 88f50b1 commit 9d30adb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ResourceQuantity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public override bool CanConvert(Type objectType)
8383
/// writing some sort of special handling code in the hopes that that will
8484
/// cause implementors to also use a fixed point implementation.
8585
/// </summary>
86-
[JsonConverter(typeof(IntOrStringConverter))]
86+
[JsonConverter(typeof(QuantityConverter))]
8787
public partial class ResourceQuantity
8888
{
8989
public enum SuffixFormat

tests/QuantityValueTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
using System;
22
using k8s.Models;
3+
using Newtonsoft.Json;
34
using Xunit;
45
using static k8s.Models.ResourceQuantity.SuffixFormat;
56

67
namespace k8s.Tests
78
{
89
public class QuantityValueTests
910
{
11+
[Fact]
12+
public void Deserialize()
13+
{
14+
{
15+
var q = JsonConvert.DeserializeObject<ResourceQuantity>("\"12k\"");
16+
Assert.Equal(new ResourceQuantity(12000, 0, DecimalSI), q);
17+
}
18+
}
19+
1020
[Fact]
1121
public void Parse()
1222
{
@@ -215,5 +225,14 @@ public void QuantityString()
215225
Assert.Equal(expect, new ResourceQuantity(alternate).ToString());
216226
}
217227
}
228+
229+
[Fact]
230+
public void Serialize()
231+
{
232+
{
233+
ResourceQuantity quantity = 12000;
234+
Assert.Equal("\"12e3\"", JsonConvert.SerializeObject(quantity));
235+
}
236+
}
218237
}
219238
}

0 commit comments

Comments
 (0)