add test for json serialize

This commit is contained in:
Boshi LIAN
2017-12-01 04:39:39 +08:00
committed by Boshi Lian
parent 88f50b1496
commit 9d30adb349
2 changed files with 20 additions and 1 deletions

View File

@@ -83,7 +83,7 @@ namespace k8s.Models
/// writing some sort of special handling code in the hopes that that will
/// cause implementors to also use a fixed point implementation.
/// </summary>
[JsonConverter(typeof(IntOrStringConverter))]
[JsonConverter(typeof(QuantityConverter))]
public partial class ResourceQuantity
{
public enum SuffixFormat

View File

@@ -1,5 +1,6 @@
using System;
using k8s.Models;
using Newtonsoft.Json;
using Xunit;
using static k8s.Models.ResourceQuantity.SuffixFormat;
@@ -7,6 +8,15 @@ namespace k8s.Tests
{
public class QuantityValueTests
{
[Fact]
public void Deserialize()
{
{
var q = JsonConvert.DeserializeObject<ResourceQuantity>("\"12k\"");
Assert.Equal(new ResourceQuantity(12000, 0, DecimalSI), q);
}
}
[Fact]
public void Parse()
{
@@ -215,5 +225,14 @@ namespace k8s.Tests
Assert.Equal(expect, new ResourceQuantity(alternate).ToString());
}
}
[Fact]
public void Serialize()
{
{
ResourceQuantity quantity = 12000;
Assert.Equal("\"12e3\"", JsonConvert.SerializeObject(quantity));
}
}
}
}