diff --git a/FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs b/FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs index b496067d..518c8a4d 100644 --- a/FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs +++ b/FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs @@ -526,6 +526,82 @@ public void AndroidConfigFullSecondsTTL() this.AssertJsonEquals(expected, message); } + [Fact] + public void AndroidNotificationWithoutEventTimestamp() + { + var message = new Message() + { + Topic = "test-topic", + Android = new AndroidConfig() + { + Notification = new AndroidNotification() + { + Title = "title", + }, + }, + }; + var expected = new JObject() + { + { "topic", "test-topic" }, + { + "android", new JObject() + { + { + "notification", new JObject() + { + { "title", "title" }, + { "sticky", false }, + { "local_only", false }, + { "default_vibrate_timings", false }, + { "default_sound", false }, + { "default_light_settings", false }, + } + }, + } + }, + }; + this.AssertJsonEquals(expected, message); + } + + [Fact] + public void AndroidNotificationWithEventTimestamp() + { + var message = new Message() + { + Topic = "test-topic", + Android = new AndroidConfig() + { + Notification = new AndroidNotification() + { + Title = "title", + EventTimestamp = new DateTime(2020, 6, 27, 20, 29, 6, DateTimeKind.Utc), + }, + }, + }; + var expected = new JObject() + { + { "topic", "test-topic" }, + { + "android", new JObject() + { + { + "notification", new JObject() + { + { "title", "title" }, + { "sticky", false }, + { "local_only", false }, + { "default_vibrate_timings", false }, + { "default_sound", false }, + { "default_light_settings", false }, + { "event_time", "2020-06-27T20:29:06.000000000Z" }, + } + }, + } + }, + }; + this.AssertJsonEquals(expected, message); + } + [Fact] public void AndroidConfigDeserialization() { diff --git a/FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs b/FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs index 19084a05..a6e22f6b 100644 --- a/FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs +++ b/FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs @@ -139,7 +139,8 @@ public sealed class AndroidNotification /// /// Gets or sets the time that the event in the notification occurred for notifications /// that inform users about events with an absolute time reference. Notifications in the panel - /// are sorted by this time. + /// are sorted by this time. When left at its default value, the event time is not included + /// in the message. /// [JsonIgnore] public DateTime EventTimestamp { get; set; } @@ -371,6 +372,11 @@ private string EventTimeString { get { + if (this.EventTimestamp == default(DateTime)) + { + return null; + } + return this.EventTimestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.ffffff000'Z'", CultureInfo.InvariantCulture); }