Skip to content

Commit cbfa73b

Browse files
committed
Change Serialization of GcmNotification Priority
This fixes Redth#679 where the priority was being serialized as a number instead of the text as per Google's docs
1 parent f407364 commit cbfa73b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

PushSharp.Google/GcmNotification.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.Serialization;
23
using Newtonsoft.Json.Linq;
34
using System.Collections.Generic;
45
using PushSharp.Core;
@@ -139,7 +140,7 @@ public bool IsDeviceRegistrationIdValid ()
139140
/// Corresponds to iOS APNS priorities (Normal is 5 and high is 10). Default is Normal.
140141
/// </summary>
141142
/// <value>The priority.</value>
142-
[JsonProperty ("priority")]
143+
[JsonProperty ("priority"), JsonConverter (typeof (Newtonsoft.Json.Converters.StringEnumConverter))]
143144
public GcmNotificationPriority? Priority { get; set; }
144145

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

164165
public enum GcmNotificationPriority
165166
{
167+
[EnumMember (Value="normal")]
166168
Normal = 5,
169+
[EnumMember (Value="high")]
167170
High = 10
168171
}
169172
}

PushSharp.Tests/GcmTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using NUnit.Framework;
3+
using PushSharp.Google;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json.Linq;
6+
7+
namespace PushSharp.Tests
8+
{
9+
[Category ("GCM")]
10+
[TestFixture]
11+
public class GcmTests
12+
{
13+
[Test]
14+
public void GcmNotification_Priority_Should_Serialize_As_String_High ()
15+
{
16+
var n = new GcmNotification ();
17+
n.Priority = GcmNotificationPriority.High;
18+
19+
var str = n.ToString ();
20+
21+
Assert.IsTrue (str.Contains ("high"));
22+
}
23+
24+
[Test]
25+
public void GcmNotification_Priority_Should_Serialize_As_String_Normal ()
26+
{
27+
var n = new GcmNotification ();
28+
n.Priority = GcmNotificationPriority.Normal;
29+
30+
var str = n.ToString ();
31+
32+
Assert.IsTrue (str.Contains ("normal"));
33+
}
34+
}
35+
}
36+

PushSharp.Tests/PushSharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Compile Include="BrokerTests.cs" />
4949
<Compile Include="ApnsRealTest.cs" />
5050
<Compile Include="WnsRealTests.cs" />
51+
<Compile Include="GcmTests.cs" />
5152
</ItemGroup>
5253
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5354
<ItemGroup>

0 commit comments

Comments
 (0)