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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task Send()
Body = "Body",
ImageUrl = "https://example.com/image.png",
},
#pragma warning disable CS0618
Android = new AndroidConfig()
{
Priority = Priority.Normal,
Expand All @@ -49,6 +50,7 @@ public async Task Send()
BandwidthConstrainedOk = true,
RestrictedSatelliteOk = true,
},
#pragma warning restore CS0618
};
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Assert.True(!string.IsNullOrEmpty(id));
Expand All @@ -67,6 +69,7 @@ public async Task SendEach()
Body = "Body",
ImageUrl = "https://example.com/image.png",
},
#pragma warning disable CS0618
Android = new AndroidConfig()
{
Priority = Priority.Normal,
Expand All @@ -76,6 +79,7 @@ public async Task SendEach()
BandwidthConstrainedOk = false,
RestrictedSatelliteOk = false,
},
#pragma warning restore CS0618
};
var message2 = new Message()
{
Expand All @@ -85,6 +89,7 @@ public async Task SendEach()
Title = "Title",
Body = "Body",
},
#pragma warning disable CS0618
Android = new AndroidConfig()
{
Priority = Priority.Normal,
Expand All @@ -94,6 +99,7 @@ public async Task SendEach()
BandwidthConstrainedOk = true,
RestrictedSatelliteOk = true,
},
#pragma warning restore CS0618
};
var response = await FirebaseMessaging.DefaultInstance.SendEachAsync(new[] { message1, message2 }, dryRun: true);
Assert.NotNull(response);
Expand All @@ -114,13 +120,13 @@ public async Task SendEachForMulticast()
Title = "Title",
Body = "Body",
},
#pragma warning disable CS0618
Android = new AndroidConfig()
{
Priority = Priority.Normal,
TimeToLive = TimeSpan.FromHours(1),
RestrictedPackageName = "com.google.firebase.testing",
},
#pragma warning disable CS0618
Tokens = new[]
{
"token1",
Expand All @@ -145,12 +151,14 @@ public async Task SendEachForMulticastFids()
Title = "Title",
Body = "Body",
},
#pragma warning disable CS0618
Android = new AndroidConfig()
{
Priority = Priority.Normal,
TimeToLive = TimeSpan.FromHours(1),
RestrictedPackageName = "com.google.firebase.testing",
},
#pragma warning restore CS0618
Fids = new[]
{
"fid1",
Expand Down Expand Up @@ -189,5 +197,192 @@ public async Task UnsubscribeFromTopic()
Assert.Equal("invalid-argument", response.Errors[1].Reason);
Assert.Equal(1, response.Errors[1].Index);
}

[Fact]
public async Task SendAndroidV2RemoteNotification()
{
var message = CreateAndroidV2RemoteNotificationMessage();
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Assert.True(!string.IsNullOrEmpty(id));
Assert.Matches(new Regex("^projects/.*/messages/.*$"), id);
}

[Fact]
public async Task SendAndroidV2MinimalRemoteNotification()
{
var message = CreateAndroidV2MinimalRemoteNotificationMessage();
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Assert.True(!string.IsNullOrEmpty(id));
Assert.Matches(new Regex("^projects/.*/messages/.*$"), id);
}

[Fact]
public async Task SendAndroidV2BackgroundSync()
{
var message = CreateAndroidV2BackgroundSyncMessage();
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Assert.True(!string.IsNullOrEmpty(id));
Assert.Matches(new Regex("^projects/.*/messages/.*$"), id);
}

[Fact]
public async Task SendAndroidV2MinimalBackgroundSync()
{
var message = CreateAndroidV2MinimalBackgroundSyncMessage();
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Assert.True(!string.IsNullOrEmpty(id));
Assert.Matches(new Regex("^projects/.*/messages/.*$"), id);
}

[Fact]
public async Task SendEachAndroidV2()
{
var messages = new[]
{
CreateAndroidV2RemoteNotificationMessage(),
CreateAndroidV2MinimalRemoteNotificationMessage(),
CreateAndroidV2BackgroundSyncMessage(),
CreateAndroidV2MinimalBackgroundSyncMessage(),
};
var response = await FirebaseMessaging.DefaultInstance.SendEachAsync(messages, dryRun: true);
Assert.NotNull(response);
Assert.Equal(4, response.SuccessCount);
Assert.Equal(0, response.FailureCount);
Assert.Equal(4, response.Responses.Count);
foreach (var sendResponse in response.Responses)
{
Assert.True(sendResponse.IsSuccess);
Assert.Null(sendResponse.Exception);
Assert.Matches(new Regex("^projects/.*/messages/.*$"), sendResponse.MessageId);
}
}

private static AndroidNotificationV2 CreateFullAndroidNotificationV2()
{
return new AndroidNotificationV2()
{
Title = "Title",
Body = "Body",
Icon = "stock_ticker_update",
Color = "#f45342",
Sound = "default",
Tag = "test-tag",
ImageUrl = "https://example.com/image.png",
ClickAction = "TOP_STORY_ACTIVITY",
TitleLocKey = "title_loc_key",
TitleLocArgs = new List<string>() { "title_arg1", "title_arg2" },
BodyLocKey = "body_loc_key",
BodyLocArgs = new List<string>() { "body_arg1", "body_arg2" },
ChannelId = "test-channel-id",
Ticker = "test-ticker",
Sticky = true,
EventTimestamp = new DateTime(2026, 7, 8, 18, 0, 0, DateTimeKind.Utc),
LocalOnly = true,
Priority = NotificationPriority.HIGH,
VibrateTimingsMillis = new List<long>() { 100, 200, 300 },
DefaultVibrateTimings = false,
DefaultSound = true,
LightSettings = new LightSettings()
{
Color = "#1A73E8",
LightOnDurationMillis = 100,
LightOffDurationMillis = 200,
},
DefaultLightSettings = false,
Visibility = NotificationVisibility.PUBLIC,
NotificationCount = 42,
Id = 42,
};
}

private static Message CreateAndroidV2RemoteNotificationMessage()
{
return new Message()
{
Topic = "foo-bar",
AndroidV2 = new AndroidConfigV2()
{
CollapseKey = "test-collapse-key",
TimeToLive = TimeSpan.FromHours(1),
RestrictedPackageName = "com.google.firebase.testing",
Data = new Dictionary<string, string>()
{
{ "k1", "v1" },
{ "k2", "v2" },
},
DirectBootOk = true,
BandwidthConstrainedOk = true,
RestrictedSatelliteOk = true,
FcmOptions = new AndroidFcmOptions()
{
AnalyticsLabel = "test-analytics-label",
},
RemoteNotification = new AndroidRemoteNotification()
{
MutableContent = true,
UseAsV1DataMessage = false,
Notification = CreateFullAndroidNotificationV2(),
},
},
};
}

private static Message CreateAndroidV2MinimalRemoteNotificationMessage()
{
return new Message()
{
Topic = "foo-bar",
AndroidV2 = new AndroidConfigV2()
{
RemoteNotification = new AndroidRemoteNotification()
{
Notification = new AndroidNotificationV2()
{
Title = "Title",
Body = "Body",
},
},
},
};
}

private static Message CreateAndroidV2BackgroundSyncMessage()
{
return new Message()
{
Topic = "foo-bar",
AndroidV2 = new AndroidConfigV2()
{
CollapseKey = "test-collapse-key",
TimeToLive = TimeSpan.FromHours(1),
RestrictedPackageName = "com.google.firebase.testing",
Data = new Dictionary<string, string>()
{
{ "k1", "v1" },
{ "k2", "v2" },
},
DirectBootOk = true,
BandwidthConstrainedOk = true,
RestrictedSatelliteOk = true,
FcmOptions = new AndroidFcmOptions()
{
AnalyticsLabel = "test-analytics-label",
},
BackgroundSync = new AndroidBackgroundSyncMessage(),
},
};
}

private static Message CreateAndroidV2MinimalBackgroundSyncMessage()
{
return new Message()
{
Topic = "foo-bar",
AndroidV2 = new AndroidConfigV2()
{
BackgroundSync = new AndroidBackgroundSyncMessage(),
},
};
}
}
}
Loading
Loading