Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
8 changes: 7 additions & 1 deletion FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public sealed class AndroidNotification
/// <summary>
/// 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.
/// </summary>
[JsonIgnore]
public DateTime EventTimestamp { get; set; }
Expand Down Expand Up @@ -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);
}

Expand Down