You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides a detailed guide for AI agents to understand and contribute to the Firebase Admin DotNet SDK. Adhering to these guidelines is crucial for maintaining code quality, consistency, and idiomatic C# practices.
1
+
This document provides a detailed guide for AI agents to understand and contribute to the Firebase Admin .NET SDK. Adhering to these guidelines is crucial for maintaining code quality, consistency, and idiomatic C# practices.
2
2
3
3
## High-Level Overview
4
4
5
-
The Firebase Admin DotNet SDK provides C# developers with access to Firebase services on privileged environments. Its design emphasizes idiomatic C#, thread-safety, and a consistent, predictable API surface.
5
+
The Firebase Admin .NET SDK provides C# developers with access to Firebase services on privileged environments. Its design emphasizes idiomatic C#, thread-safety, and a consistent, predictable API surface.
6
6
7
7
## Directory Structure
8
8
@@ -11,7 +11,7 @@ The Firebase Admin DotNet SDK provides C# developers with access to Firebase ser
11
11
-**`FirebaseAdmin/FirebaseAdmin/FirebaseApp.cs`**: The main entry point and initialization class for the SDK.
12
12
-**`FirebaseAdmin/FirebaseAdmin/Auth/`**: Source code for the Authentication service.
13
13
-**`FirebaseAdmin/FirebaseAdmin/Messaging/`**: Source code for the Firebase Cloud Messaging (FCM) service.
14
-
-**`FirebaseAdmin/FirebaseAdmin/Internal/`**: Internal utilities and classes not meant for public consumption. Direct use of this code in public APIs is strictly forbidden.
14
+
-**`FirebaseAdmin/FirebaseAdmin/Util/`**: Internal helper utilities and classes used across services (e.g. Wrapping low level http exceptions as a `FirebaseException`).
15
15
-**`FirebaseAdmin/FirebaseAdmin.Tests/`**: Unit tests for the SDK.
-**`FirebaseAdmin/FirebaseAdmin.Snippets/`**: Code snippets used in documentation.
@@ -28,15 +28,30 @@ The Firebase Admin DotNet SDK provides C# developers with access to Firebase ser
28
28
29
29
-**Formatting**: Code style is enforced using `stylecop`. Run `dotnet format` to apply the rules.
30
30
-**Naming**:
31
-
- Classes and public methods use `PascalCase`.
32
-
- Private members are not explicitly prefixed, but it is preferred to prefix them with an underscore (`_`).
33
-
- Constants are `PascalCase`.
31
+
- Constants, classes and public methods use `PascalCase`.
32
+
- Private members are not explicitly prefixed.
34
33
35
34
## Testing Philosophy
36
35
37
-
-**Unit Tests**: Located in `FirebaseAdmin.Tests/`, with a file naming pattern of `*Test.cs`. `xunit` is the testing framework. Moq is the preferred library for mocking dependencies.
36
+
-**Unit Tests**: Located in `FirebaseAdmin.Tests/`, with a file naming pattern of `*Test.cs`. `xunit` is the testing framework.
38
37
-**Integration Tests**: Located in `FirebaseAdmin.IntegrationTests/`. These tests interact with live Firebase services and require a configured service account.
39
38
39
+
### How to Run Tests
40
+
41
+
The unit tests can be run using the `dotnet test` command. Ensure that the required .NET frameworks (net462 and net6.0) are installed in your environment.
42
+
43
+
To run the tests for a specific framework, use the `--framework` flag:
44
+
```bash
45
+
# Run tests for .NET 6.0
46
+
dotnet test FirebaseAdmin/FirebaseAdmin.Tests --framework net6.0
47
+
48
+
# Run tests for .NET 4.6.2
49
+
dotnet test FirebaseAdmin/FirebaseAdmin.Tests --framework net462
50
+
```
51
+
52
+
**Note on Integration Tests:** The integration tests require a configured service account and other setup that is not available in all environments. It is recommended to rely on the CI for running integration tests.
53
+
54
+
40
55
## Dependency Management
41
56
42
57
-**Manager**: Dependencies are managed using NuGet.
@@ -45,25 +60,25 @@ The Firebase Admin DotNet SDK provides C# developers with access to Firebase ser
45
60
46
61
## Critical Developer Journeys
47
62
48
-
### Journey 1: How to Add a New API Method
63
+
### Journey 1: How to Add/Update a New API Method
49
64
50
-
1.**Public Method**: Define the new public method in the relevant service class (e.g., `FirebaseAuth.cs`).
51
-
2.**Internal Logic**: Implement the core logic as a private method.
52
-
3.**HTTP Client**: Use the internal `HttpClient` to make the API call.
65
+
1.**Public Method**: Define the new public method or changes in the relevant service class (e.g., `FirebaseAuth.cs`).
66
+
2.**Internal Logic**: Implement the core logic as a private method.
67
+
3.**HTTP Client**: Use the existing HTTP Client implementation for that service to make the API call.
53
68
4.**Error Handling**: Wrap API calls in `try-catch` blocks and throw appropriate `FirebaseException` subtypes.
54
-
5.**Testing**: Add a unit test in the corresponding `*Test.cs` file and an integration test in `FirebaseAdmin.IntegrationTests/`.
55
-
6.**Snippet**: Add a code snippet in `FirebaseAdmin.Snippets/` to demonstrate the new feature.
69
+
5.**Testing**: Add a unit test in the corresponding `*Test.cs` file and an integration test in `FirebaseAdmin.IntegrationTests/` where appropriate. This should be thorough and update any tests where the new changes would affect.
70
+
6.**Snippet**: Add or update code snippet in `FirebaseAdmin.Snippets/` to demonstrate the new feature.
56
71
57
-
### Journey 2: How to Add a New Field to an Existing API Response
72
+
### Journey 2: How to Deprecate a Field/Method in an Existing API
58
73
59
-
1.**Data Model**: Locate and modify the relevant data model class in the service's directory.
60
-
2.**Testing**: Update unit and integration tests to verify the presence and correctness of the new field.
74
+
1.**Add Deprecation Note**: Locate where the deprecated object is defined and add a deprecation warning with a note (e.g. [Obsolete("Use X instead")]).
75
+
2.**Remove Releted Tests and Update Snippets**: Because `Obsolete` warnings result in build errors, tests and snippets where the object is used should be removed or updated not no longer used the deprecated object.
61
76
62
77
## Critical Do's and Don'ts
63
78
64
79
-**DO**: Use the centralized `HttpClient` for all API calls.
65
80
-**DO**: Follow the established `async`/`await` patterns for asynchronous code.
66
-
-**DON'T**: Expose types from the `FirebaseAdmin/FirebaseAdmin/Internal/` directory in any public API.
81
+
-**DON'T**: Expose types from the `FirebaseAdmin/FirebaseAdmin/Utils/` directory in any public API.
67
82
-**DON'T**: Introduce new third-party dependencies without a compelling reason and discussion with the maintainers.
68
83
69
84
## Commit and Pull Request Generation
@@ -72,7 +87,7 @@ After implementing and testing a change, you must create a commit and Pull Reque
72
87
73
88
**1. Commit Message Format**: The commit message is critical and is used to generate the Pull Request. It MUST follow this structure:
74
89
-**Title**: Use the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification: `type(scope): subject`.
75
-
-`scope` should be the service package changed (e.g., `auth`, `db`, `deps`).
90
+
-`scope` should be the service package changed (e.g., `auth`, `rtdb`, `deps`).
76
91
-**Note on Scopes**: Some services use specific abbreviations. Use the abbreviation if one exists. Common abbreviations include:
77
92
-`messaging` -> `fcm`
78
93
-`dataconnect` -> `fdc`
@@ -83,19 +98,22 @@ After implementing and testing a change, you must create a commit and Pull Reque
83
98
-**Body**: The body is separated from the title by a blank line and MUST contain the following, in order:
84
99
1. A brief explanation of the problem and the solution.
85
100
2. A summary of the testing strategy (e.g., "Added a new unit test to verify the fix.").
86
-
3. A **Context Sources** section that lists the `id` and repository path of every `AGENTS.md` file you used.
101
+
3. A **Context Sources** section that lists the `id` and repository path of every `AGENTS.md` file you used to verify context usage.
87
102
88
103
**2. Example Commit Message**:
89
104
```
90
105
feat(fcm): Add support for multicast messages
91
106
92
-
This change introduces a new `SendMulticast` method to the messaging client, allowing developers to send a single message to multiple tokens efficiently.
107
+
This change introduces a new `SendEachForMulticastAsync` method to the messaging client, allowing developers to send a single message to multiple tokens efficiently.
93
108
94
-
Testing: Added unit tests in `messaging_test.cs` with a mock server and an integration test in `integration/messaging_test.cs`.
109
+
Testing: Added unit tests with a mock server and an integration test in `FirebaseAdmin.IntegrationTests/MessagingTest.cs`.
0 commit comments