add test for json serialize
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user