Skip to content

Commit 0e21598

Browse files
committed
Renamed UserID to UserId in the classes inside of GetAccountInfoResponse.
Converted ProviderUserInfo to be an internal class, with auto properties. Fixed the FirebaseUserManagerTest test so that it would fail when instantiating a UserRecord class with a uid that's longer than 128 characters.
1 parent cef5382 commit 0e21598

File tree

5 files changed

+25
-52
lines changed

5 files changed

+25
-52
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Auth/FirebaseUserManagerTest.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public void InvalidUidForUserRecord()
3535
Assert.Throws<ArgumentException>(() => new UserRecord((string)null));
3636
Assert.Throws<ArgumentException>(() => new UserRecord((GetAccountInfoResponse.User)null));
3737
Assert.Throws<ArgumentException>(() => new UserRecord(string.Empty));
38-
39-
// The constructor for UserRecord should not throw an exception when initialized with a valid string.
40-
var userRecord = new UserRecord(new string('a', 129));
38+
Assert.Throws<ArgumentException>(() => new UserRecord(new string('a', 129)));
4139
}
4240

4341
[Fact]
@@ -84,7 +82,7 @@ public async Task GetUserById()
8482
Kind = "identitytoolkit#GetAccountInfoResponse",
8583
Users = new List<GetAccountInfoResponse.User>()
8684
{
87-
new GetAccountInfoResponse.User() { UserID = "user1" },
85+
new GetAccountInfoResponse.User() { UserId = "user1" },
8886
},
8987
},
9088
};
@@ -130,7 +128,7 @@ public async Task UpdateUser()
130128
Kind = "identitytoolkit#GetAccountInfoResponse",
131129
Users = new List<GetAccountInfoResponse.User>()
132130
{
133-
new GetAccountInfoResponse.User() { UserID = "user1" },
131+
new GetAccountInfoResponse.User() { UserId = "user1" },
134132
},
135133
},
136134
};

FirebaseAdmin/FirebaseAdmin/Auth/FirebaseUserManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task<UserRecord> GetUserById(
9090
}
9191

9292
var user = response.Users[0];
93-
if (user == null || user.UserID != uid)
93+
if (user == null || user.UserId != uid)
9494
{
9595
throw new FirebaseException($"Failed to get user: {uid}");
9696
}
@@ -117,7 +117,7 @@ public async Task UpdateUserAsync(
117117
}
118118

119119
var updatedUser = response.Users[0];
120-
if (updatedUser == null || updatedUser.UserID != user.Uid)
120+
if (updatedUser == null || updatedUser.UserId != user.Uid)
121121
{
122122
throw new FirebaseException($"Failed to update user: {user.Uid}");
123123
}

FirebaseAdmin/FirebaseAdmin/Auth/Internal/GetAccountInfoResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal sealed class User
3131
/// Gets or sets the user's ID.
3232
/// </summary>
3333
[JsonProperty(PropertyName = "localId")]
34-
public string UserID { get; set; }
34+
public string UserId { get; set; }
3535

3636
/// <summary>
3737
/// Gets or sets the user's email address.
@@ -109,7 +109,7 @@ internal sealed class Provider
109109
/// Gets or sets the user's ID.
110110
/// </summary>
111111
[JsonProperty(PropertyName = "uid")]
112-
public string UserID { get; set; }
112+
public string UserId { get; set; }
113113

114114
/// <summary>
115115
/// Gets or sets the user's display name.

FirebaseAdmin/FirebaseAdmin/Auth/ProviderUserInfo.cs

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,57 @@ namespace FirebaseAdmin.Auth
88
/// Contains metadata regarding how a user is known by a particular identity provider (IdP).
99
/// Instances of this class are immutable and thread safe.
1010
/// </summary>
11-
public sealed class ProviderUserInfo : IUserInfo
11+
internal sealed class ProviderUserInfo : IUserInfo
1212
{
13-
private string uid;
14-
private string displayName;
15-
private string email;
16-
private string phoneNumber;
17-
private string photoUrl;
18-
private string providerId;
19-
2013
/// <summary>
2114
/// Initializes a new instance of the <see cref="ProviderUserInfo"/> class with data provided by an authentication provider.
2215
/// </summary>
2316
/// <param name="provider">The deserialized JSON user data from the provider.</param>
2417
internal ProviderUserInfo(GetAccountInfoResponse.Provider provider)
2518
{
26-
this.uid = provider.UserID;
27-
this.displayName = provider.DisplayName;
28-
this.email = provider.Email;
29-
this.phoneNumber = provider.PhoneNumber;
30-
this.photoUrl = provider.PhotoUrl;
31-
this.providerId = provider.ProviderID;
19+
this.Uid = provider.UserId;
20+
this.DisplayName = provider.DisplayName;
21+
this.Email = provider.Email;
22+
this.PhoneNumber = provider.PhoneNumber;
23+
this.PhotoUrl = provider.PhotoUrl;
24+
this.ProviderId = provider.ProviderID;
3225
}
3326

3427
/// <summary>
3528
/// Gets the user's unique ID assigned by the identity provider.
3629
/// </summary>
3730
/// <returns>a user ID string.</returns>
38-
public string Uid
39-
{
40-
get => this.uid;
41-
}
31+
public string Uid { get; private set; }
4232

4333
/// <summary>
4434
/// Gets the user's display name, if available.
4535
/// </summary>
4636
/// <returns>a display name string or null.</returns>
47-
public string DisplayName
48-
{
49-
get => this.displayName;
50-
}
37+
public string DisplayName { get; private set; }
5138

5239
/// <summary>
5340
/// Gets the user's email address, if available.
5441
/// </summary>
5542
/// <returns>an email address string or null.</returns>
56-
public string Email
57-
{
58-
get => this.email;
59-
}
43+
public string Email { get; private set; }
6044

6145
/// <summary>
6246
/// Gets the user's phone number.
6347
/// </summary>
6448
/// <returns>a phone number string or null.</returns>
65-
public string PhoneNumber
66-
{
67-
get => this.phoneNumber;
68-
}
49+
public string PhoneNumber { get; private set; }
6950

7051
/// <summary>
7152
/// Gets the user's photo URL, if available.
7253
/// </summary>
7354
/// <returns>a URL string or null.</returns>
74-
public string PhotoUrl
75-
{
76-
get => this.photoUrl;
77-
}
55+
public string PhotoUrl { get; private set; }
7856

7957
/// <summary>
8058
/// Gets the ID of the identity provider. This can be a short domain name (e.g. google.com) or
8159
/// the identifier of an OpenID identity provider.
8260
/// </summary>
8361
/// <returns>an ID string that uniquely identifies the identity provider.</returns>
84-
public string ProviderId
85-
{
86-
get => this.providerId;
87-
}
62+
public string ProviderId { get; private set; }
8863
}
8964
}

FirebaseAdmin/FirebaseAdmin/Auth/UserRecord.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public sealed class UserRecord : IUserInfo
4747
/// <param name="uid">The user's ID.</param>
4848
internal UserRecord(string uid)
4949
{
50-
if (string.IsNullOrEmpty(uid))
50+
if (string.IsNullOrEmpty(uid) || uid.Length > 128)
5151
{
52-
throw new ArgumentException("UserID must not be null or empty.");
52+
throw new ArgumentException("User ID must not be null or empty, and be 128 characters or shorter.");
5353
}
5454

5555
this.uid = uid;
@@ -65,12 +65,12 @@ internal UserRecord(GetAccountInfoResponse.User user)
6565
{
6666
throw new ArgumentException("User object must not be null or empty.");
6767
}
68-
else if (string.IsNullOrEmpty(user.UserID))
68+
else if (string.IsNullOrEmpty(user.UserId))
6969
{
70-
throw new ArgumentException("UserID must not be null or empty.");
70+
throw new ArgumentException("User ID must not be null or empty.");
7171
}
7272

73-
this.uid = user.UserID;
73+
this.uid = user.UserId;
7474
this.email = user.Email;
7575
this.phoneNumber = user.PhoneNumber;
7676
this.emailVerified = user.EmailVerified;

0 commit comments

Comments
 (0)