Skip to content

Commit e03cfd2

Browse files
committed
added unit tests for AppOptions.HttpClientFactory configuration
1 parent 9d9f883 commit e03cfd2

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/FirebaseAppTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Threading.Tasks;
1717
using FirebaseAdmin;
1818
using Google.Apis.Auth.OAuth2;
19+
using Google.Apis.Http;
1920
using Xunit;
2021

2122
namespace FirebaseAdmin.Tests
@@ -93,6 +94,7 @@ public void CreateAppOptions()
9394
Credential = credential,
9495
ProjectId = "test-project",
9596
ServiceAccountId = "[email protected]",
97+
HttpClientFactory = new MockHttpClientFactory(new MockMessageHandler()),
9698
};
9799
var app = FirebaseApp.Create(options);
98100
Assert.Equal("[DEFAULT]", app.Name);
@@ -102,6 +104,28 @@ public void CreateAppOptions()
102104
Assert.Same(credential, copy.Credential);
103105
Assert.Equal("test-project", copy.ProjectId);
104106
Assert.Equal("[email protected]", copy.ServiceAccountId);
107+
Assert.Equal(typeof(MockHttpClientFactory), copy.HttpClientFactory.GetType());
108+
}
109+
110+
[Fact]
111+
public void CreateAppOptionsNoClientFactory()
112+
{
113+
var credential = GoogleCredential.FromAccessToken("token");
114+
var options = new AppOptions()
115+
{
116+
Credential = credential,
117+
ProjectId = "test-project",
118+
ServiceAccountId = "[email protected]",
119+
};
120+
var app = FirebaseApp.Create(options);
121+
Assert.Equal("[DEFAULT]", app.Name);
122+
123+
var copy = app.Options;
124+
Assert.NotSame(options, copy);
125+
Assert.Same(credential, copy.Credential);
126+
Assert.Equal("test-project", copy.ProjectId);
127+
Assert.Equal("[email protected]", copy.ServiceAccountId);
128+
Assert.Equal(typeof(HttpClientFactory), copy.HttpClientFactory.GetType());
105129
}
106130

107131
[Fact]

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/FirebaseMessagingTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
using System;
1616
using System.Threading;
1717
using System.Threading.Tasks;
18-
using FirebaseAdmin.Tests;
1918
using Google.Apis.Auth.OAuth2;
19+
using Google.Apis.Http;
2020
using Xunit;
2121

2222
namespace FirebaseAdmin.Messaging.Tests
@@ -54,6 +54,17 @@ public void GetMessaging()
5454
Assert.Throws<InvalidOperationException>(() => FirebaseMessaging.GetMessaging(app));
5555
}
5656

57+
[Fact]
58+
public void GetMessagingWithClientFactory()
59+
{
60+
var app = FirebaseApp.Create(new AppOptions() { Credential = MockCredential, HttpClientFactory = new HttpClientFactory() }, "MyApp");
61+
FirebaseMessaging messaging = FirebaseMessaging.GetMessaging(app);
62+
Assert.NotNull(messaging);
63+
Assert.Same(messaging, FirebaseMessaging.GetMessaging(app));
64+
app.Delete();
65+
Assert.Throws<InvalidOperationException>(() => FirebaseMessaging.GetMessaging(app));
66+
}
67+
5768
[Fact]
5869
public async Task UseAfterDelete()
5970
{
@@ -76,6 +87,18 @@ await Assert.ThrowsAsync<OperationCanceledException>(
7687
new Message() { Topic = "test-topic" }, canceller.Token));
7788
}
7889

90+
[Fact]
91+
public async Task SendMessageCancelWithClientFactory()
92+
{
93+
var cred = GoogleCredential.FromFile("./resources/service_account.json");
94+
FirebaseApp.Create(new AppOptions() { Credential = cred, HttpClientFactory = new HttpClientFactory() });
95+
var canceller = new CancellationTokenSource();
96+
canceller.Cancel();
97+
await Assert.ThrowsAsync<OperationCanceledException>(
98+
async () => await FirebaseMessaging.DefaultInstance.SendAsync(
99+
new Message() { Topic = "test-topic" }, canceller.Token));
100+
}
101+
79102
public void Dispose()
80103
{
81104
FirebaseApp.DeleteAll();

0 commit comments

Comments
 (0)