Skip to content
Draft
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
46 changes: 38 additions & 8 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseMessagingSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class FirebaseMessagingSnippets
{
internal static async Task SendToTokenAsync()
{
#pragma warning disable CS0618
// [START send_to_token]
// This registration token comes from the client FCM SDKs.
var registrationToken = "YOUR_REGISTRATION_TOKEN";
Expand All @@ -35,9 +36,7 @@ internal static async Task SendToTokenAsync()
{ "score", "850" },
{ "time", "2:45" },
},
#pragma warning disable CS0618
Token = registrationToken,
#pragma warning restore CS0618
};

// Send a message to the device corresponding to the provided
Expand All @@ -46,6 +45,7 @@ internal static async Task SendToTokenAsync()
// Response is a message ID string.
Console.WriteLine("Successfully sent message: " + response);
// [END send_to_token]
#pragma warning restore CS0618
}

internal static async Task SendToTopicAsync()
Expand Down Expand Up @@ -124,6 +124,7 @@ internal static async Task SendDryRunAsync()
internal static async Task SendEachAsync()
{
var registrationToken = "YOUR_REGISTRATION_TOKEN";
#pragma warning disable CS0618
// [START send_all]
// Create a list containing up to 500 messages.
var messages = new List<Message>()
Expand All @@ -135,9 +136,7 @@ internal static async Task SendEachAsync()
Title = "Price drop",
Body = "5% off all electronics",
},
#pragma warning disable CS0618
Token = registrationToken,
#pragma warning restore CS0618
},
new Message()
{
Expand All @@ -155,10 +154,12 @@ internal static async Task SendEachAsync()
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");
// [END send_all]
#pragma warning restore CS0618
}

internal static async Task SendEachForMulticastAsync()
{
#pragma warning disable CS0618
// [START send_multicast]
// Create a list containing up to 500 registration tokens.
// These registration tokens come from the client FCM SDKs.
Expand All @@ -170,9 +171,7 @@ internal static async Task SendEachForMulticastAsync()
};
var message = new MulticastMessage()
{
#pragma warning disable CS0618
Tokens = registrationTokens,
#pragma warning restore CS0618
Data = new Dictionary<string, string>()
{
{ "score", "850" },
Expand All @@ -185,10 +184,12 @@ internal static async Task SendEachForMulticastAsync()
// for the contents of response.
Console.WriteLine($"{response.SuccessCount} messages were sent successfully");
// [END send_multicast]
#pragma warning restore CS0618
}

internal static async Task SendEachForMulticastAndHandleErrorsAsync()
{
#pragma warning disable CS0618
// [START send_multicast_error]
// These registration tokens come from the client FCM SDKs.
var registrationTokens = new List<string>()
Expand All @@ -199,9 +200,7 @@ internal static async Task SendEachForMulticastAndHandleErrorsAsync()
};
var message = new MulticastMessage()
{
#pragma warning disable CS0618
Tokens = registrationTokens,
#pragma warning restore CS0618
Data = new Dictionary<string, string>()
{
{ "score", "850" },
Expand All @@ -226,10 +225,12 @@ internal static async Task SendEachForMulticastAndHandleErrorsAsync()
}

// [END send_multicast_error]
#pragma warning restore CS0618
}

internal static Message CreateAndroidMessage()
{
#pragma warning disable CS0618
// [START android_message]
var message = new Message
{
Expand All @@ -248,6 +249,33 @@ internal static Message CreateAndroidMessage()
Topic = "industry-tech",
};
// [END android_message]
#pragma warning restore CS0618
return message;
}

internal static Message CreateAndroidV2Message()
{
// [START android_v2_message]
var message = new Message
{
AndroidV2 = new AndroidConfigV2()
{
TimeToLive = TimeSpan.FromHours(1),
RemoteNotification = new AndroidRemoteNotification()
{
MutableContent = true,
Notification = new AndroidNotificationV2()
{
Title = "$GOOG up 1.43% on the day",
Body = "$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.",
Icon = "stock_ticker_update",
Color = "#f45342",
},
},
},
Topic = "industry-tech",
};
// [END android_v2_message]
return message;
}

Expand Down Expand Up @@ -301,6 +329,7 @@ internal static Message CreateWebpushMessage()

internal static Message CreateMultiPlatformsMessage()
{
#pragma warning disable CS0618
// [START multi_platforms_message]
var message = new Message
{
Expand Down Expand Up @@ -328,6 +357,7 @@ internal static Message CreateMultiPlatformsMessage()
Topic = "industry-tech",
};
// [END multi_platforms_message]
#pragma warning restore CS0618
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public async Task SendMessageCancel()
var canceller = new CancellationTokenSource();
canceller.Cancel();

#if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
await Assert.ThrowsAsync<TaskCanceledException>(
async () => await FirebaseMessaging.DefaultInstance.SendAsync(
new Message() { Topic = "test-topic" }, canceller.Token));
#else
#else
await Assert.ThrowsAsync<OperationCanceledException>(
async () => await FirebaseMessaging.DefaultInstance.SendAsync(
new Message() { Topic = "test-topic" }, canceller.Token));
#endif
#endif
}

[Fact]
Expand All @@ -122,15 +122,15 @@ public async Task SendMessageCancelWithClientFactory()
var canceller = new CancellationTokenSource();
canceller.Cancel();

#if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
await Assert.ThrowsAsync<TaskCanceledException>(
async () => await FirebaseMessaging.DefaultInstance.SendAsync(
new Message() { Topic = "test-topic" }, canceller.Token));
#else
#else
await Assert.ThrowsAsync<OperationCanceledException>(
async () => await FirebaseMessaging.DefaultInstance.SendAsync(
new Message() { Topic = "test-topic" }, canceller.Token));
#endif
#endif
}

[Fact]
Expand Down
Loading
Loading