Skip to content

Commit

Permalink
Merge pull request #806 from clement911/charge-test-fix
Browse files Browse the repository at this point in the history
Fix for Charge.test serialization
  • Loading branch information
clement911 authored Nov 11, 2022
2 parents 52fdbef + ebebc47 commit 7528eb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions ShopifySharp.Tests/FalseToNullConverter_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ShopifySharp.Converters;
using ShopifySharp.Infrastructure;
using Xunit;

namespace ShopifySharp.Tests
Expand All @@ -12,6 +14,25 @@ public FalseToNullConverter_Tests()

}

[Fact]
public void SerializeChargeTest()
{
var charge = Serializer.Deserialize<RecurringCharge>("{ \"test\" : true }");
Assert.True(charge.Test);

charge = Serializer.Deserialize<RecurringCharge>("{ \"test\" : null }");
Assert.False(charge.Test);

charge = Serializer.Deserialize<RecurringCharge>("{ \"test\" : false }");
Assert.False(charge.Test);

Assert.True(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = true })).Value<bool?>("test"));

Assert.Null(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = false })).Value<bool?>("test"));

Assert.Null(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = null })).Value<bool?>("test"));
}

[Fact]
public void SerializeTrue()
{
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp/Entities/Charge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Charge : ShopifyObject
/// States whether or not the application charge is a test transaction.
/// </summary>
/// <remarks>Valid values are 'true' or null. Needs a special converter to convert null to false and vice-versa.</remarks>
[JsonProperty("test"), JsonConverter(typeof(FalseToNullConverter))]
[JsonProperty("test", NullValueHandling = NullValueHandling.Include), JsonConverter(typeof(FalseToNullConverter))]
public bool? Test { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ShopifySharp/Entities/RecurringCharge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class RecurringCharge : ShopifyObject
/// States whether or not the application charge is a test transaction.
/// </summary>
/// <remarks>Valid values are 'true' or null. Needs a special converter to convert null to false and vice-versa.</remarks>
[JsonProperty("test"), JsonConverter(typeof(FalseToNullConverter))]
[JsonProperty("test", NullValueHandling = NullValueHandling.Include), JsonConverter(typeof(FalseToNullConverter))]
public bool? Test { get; set; }

/// <summary>
Expand Down

0 comments on commit 7528eb5

Please sign in to comment.