-
Notifications
You must be signed in to change notification settings - Fork 143
Implementation of InstanceIdClient to allow subscribe/unsubscribe to topic #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
497f8c4
Compiles, ready for test
949a109
Before removal
bcdca8e
Integration tests working as expected
b668b38
Fixing some renames
b00db83
Improve docs, add missing dispose
4675f21
PR comment resolutions
a62c04f
Improve integation tests
186b96d
changes part 1
c69b430
Refactored and tests pass
b22734a
HTTP status code tests
1ccd27a
Fix broken test
3576351
Testing and refactoring
0724927
Test fixes
ea9e351
PR requetc changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
FirebaseAdmin/FirebaseAdmin.Tests/Messaging/InstanceIdClientTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Google.Apis.Auth.OAuth2; | ||
| using Google.Apis.Http; | ||
| using Xunit; | ||
|
|
||
| namespace FirebaseAdmin.Tests.Messaging | ||
| { | ||
| public class InstanceIdClientTest | ||
| { | ||
| private static readonly GoogleCredential MockCredential = | ||
| GoogleCredential.FromAccessToken("test-token"); | ||
|
|
||
| [Fact] | ||
| public void InstanceIdClientThrowsOnNoProjectId() | ||
| { | ||
| var clientFactory = new HttpClientFactory(); | ||
| Assert.Throws<ArgumentException>( | ||
| () => new InstanceIdClient(clientFactory, MockCredential, null)); | ||
| Assert.Throws<ArgumentException>( | ||
| () => new InstanceIdClient(clientFactory, MockCredential, string.Empty)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InstanceIdClientThrowsOnNoCredential() | ||
Leo-Mepham marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| var clientFactory = new HttpClientFactory(); | ||
| Assert.Throws<ArgumentNullException>( | ||
| () => new InstanceIdClient(clientFactory, null, "test-project")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InstanceIdClientThrowsOnNoClientFactory() | ||
| { | ||
| var clientFactory = new HttpClientFactory(); | ||
| Assert.Throws<ArgumentNullException>( | ||
| () => new InstanceIdClient(null, MockCredential, "test-project")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task InstanceIdClientSubscribesToTopic() | ||
| { | ||
| var handler = new MockMessageHandler() | ||
| { | ||
| Response = @"{""results"":[{}]}", | ||
| }; | ||
| var factory = new MockHttpClientFactory(handler); | ||
|
|
||
| var client = new InstanceIdClient(factory, MockCredential, "test-project"); | ||
|
|
||
| var result = await client.SubscribeToTopicAsync("test-topic", new List<string> { "abc123" }); | ||
|
|
||
| Assert.Equal(1, result.SuccessCount); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task InstanceIdClientUnsubscribesFromTopic() | ||
| { | ||
| var handler = new MockMessageHandler() | ||
| { | ||
| Response = @"{""results"":[{}]}", | ||
| }; | ||
| var factory = new MockHttpClientFactory(handler); | ||
|
|
||
| var client = new InstanceIdClient(factory, MockCredential, "test-project"); | ||
|
|
||
| var result = await client.UnsubscribeFromTopicAsync("test-topic", new List<string> { "abc123" }); | ||
|
|
||
| Assert.Equal(1, result.SuccessCount); | ||
| } | ||
| } | ||
Leo-Mepham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
85 changes: 85 additions & 0 deletions
85
FirebaseAdmin/FirebaseAdmin.Tests/Messaging/TopicManagementResponseTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Newtonsoft.Json.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace FirebaseAdmin.Tests.Messaging | ||
| { | ||
| public class TopicManagementResponseTest | ||
| { | ||
| [Fact] | ||
| public void SuccessfulTopicManagementResponse() | ||
Leo-Mepham marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| var json = @"[{}, {}]"; | ||
| var jObjects = JArray.Parse(json).ToObject<List<JObject>>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
|
|
||
| Assert.Equal(0, response.FailureCount); | ||
Leo-Mepham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assert.Equal(2, response.SuccessCount); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UnsuccessfulTopicManagementResponse() | ||
| { | ||
| var json = @"[{}, {""error"":""NOT_FOUND""}]"; | ||
| var jObjects = JArray.Parse(json).ToObject<List<JObject>>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
|
|
||
| Assert.Equal(1, response.FailureCount); | ||
| Assert.Equal(1, response.SuccessCount); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TopicManagementResponseCannotBeNull() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => | ||
| { | ||
| List<JObject> jObjects = null; | ||
| var response = new TopicManagementResponse(jObjects); | ||
Leo-Mepham marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TopicManagementResponseCannotBeEmptyArray() | ||
| { | ||
| Assert.Throws<ArgumentException>(() => | ||
| { | ||
| List<JObject> jObjects = new List<JObject>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TopicManagementResponseHandlesUnknownErrors() | ||
| { | ||
| var json = @"[{""error"":""NOT_A_REAL_ERROR_CODE""}]"; | ||
| var jObjects = JArray.Parse(json).ToObject<List<JObject>>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
|
|
||
| Assert.Equal(1, response.FailureCount); | ||
| Assert.Equal(0, response.SuccessCount); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TopicManagementResponseHandlesUnexpectedResponse() | ||
| { | ||
| var json = @"[{""unexpected"":""NOT_A_REAL_CODE""}]"; | ||
| var jObjects = JArray.Parse(json).ToObject<List<JObject>>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
|
|
||
| Assert.Equal(0, response.FailureCount); | ||
| Assert.Equal(1, response.SuccessCount); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TopicManagementResponseCountsSuccessAndErrors() | ||
| { | ||
| var json = @"[{""error"": ""NOT_FOUND""}, {}, {""error"": ""NOT_FOUND""}, {}, {}]"; | ||
| var jObjects = JArray.Parse(json).ToObject<List<JObject>>(); | ||
| var response = new TopicManagementResponse(jObjects); | ||
|
|
||
| Assert.Equal(2, response.FailureCount); | ||
| Assert.Equal(3, response.SuccessCount); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.