Skip to content

Commit

Permalink
Change Serialization of GcmNotification Priority
Browse files Browse the repository at this point in the history
This fixes Redth#679 where the priority was being serialized as  a number instead of the text as per Google's docs
  • Loading branch information
Redth committed Apr 7, 2016
1 parent f407364 commit cbfa73b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion PushSharp.Google/GcmNotification.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using PushSharp.Core;
Expand Down Expand Up @@ -139,7 +140,7 @@ public bool IsDeviceRegistrationIdValid ()
/// Corresponds to iOS APNS priorities (Normal is 5 and high is 10). Default is Normal.
/// </summary>
/// <value>The priority.</value>
[JsonProperty ("priority")]
[JsonProperty ("priority"), JsonConverter (typeof (Newtonsoft.Json.Converters.StringEnumConverter))]
public GcmNotificationPriority? Priority { get; set; }

internal string GetJson ()
Expand All @@ -163,7 +164,9 @@ public override string ToString ()

public enum GcmNotificationPriority
{
[EnumMember (Value="normal")]
Normal = 5,
[EnumMember (Value="high")]
High = 10
}
}
36 changes: 36 additions & 0 deletions PushSharp.Tests/GcmTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using NUnit.Framework;
using PushSharp.Google;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace PushSharp.Tests
{
[Category ("GCM")]
[TestFixture]
public class GcmTests
{
[Test]
public void GcmNotification_Priority_Should_Serialize_As_String_High ()
{
var n = new GcmNotification ();
n.Priority = GcmNotificationPriority.High;

var str = n.ToString ();

Assert.IsTrue (str.Contains ("high"));
}

[Test]
public void GcmNotification_Priority_Should_Serialize_As_String_Normal ()
{
var n = new GcmNotification ();
n.Priority = GcmNotificationPriority.Normal;

var str = n.ToString ();

Assert.IsTrue (str.Contains ("normal"));
}
}
}

1 change: 1 addition & 0 deletions PushSharp.Tests/PushSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="BrokerTests.cs" />
<Compile Include="ApnsRealTest.cs" />
<Compile Include="WnsRealTests.cs" />
<Compile Include="GcmTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down

0 comments on commit cbfa73b

Please sign in to comment.