Skip to content

Commit bef5439

Browse files
committed
Added tests for ExportedUserRecord
1 parent 386ddeb commit bef5439

File tree

3 files changed

+159
-18
lines changed

3 files changed

+159
-18
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Xunit;
18+
19+
namespace FirebaseAdmin.Auth.Tests
20+
{
21+
public class ExportedUserRecordTest
22+
{
23+
[Fact]
24+
public void NullResponse()
25+
{
26+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(null));
27+
}
28+
29+
[Fact]
30+
public void NullUid()
31+
{
32+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(
33+
new GetAccountInfoResponse.User()
34+
{
35+
UserId = null,
36+
}));
37+
}
38+
39+
[Fact]
40+
public void EmptyUid()
41+
{
42+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(
43+
new GetAccountInfoResponse.User()
44+
{
45+
UserId = string.Empty,
46+
}));
47+
}
48+
49+
[Fact]
50+
public void UidOnly()
51+
{
52+
var user = new ExportedUserRecord(new GetAccountInfoResponse.User()
53+
{
54+
UserId = "user1",
55+
});
56+
57+
Assert.Equal("user1", user.Uid);
58+
Assert.Null(user.DisplayName);
59+
Assert.Null(user.Email);
60+
Assert.Null(user.PhoneNumber);
61+
Assert.Null(user.PhotoUrl);
62+
Assert.Equal("firebase", user.ProviderId);
63+
Assert.False(user.Disabled);
64+
Assert.False(user.EmailVerified);
65+
Assert.Equal(UserRecord.UnixEpoch, user.TokensValidAfterTimestamp);
66+
Assert.Empty(user.CustomClaims);
67+
Assert.Empty(user.ProviderData);
68+
Assert.NotNull(user.UserMetaData);
69+
Assert.Null(user.UserMetaData.CreationTimestamp);
70+
Assert.Null(user.UserMetaData.LastSignInTimestamp);
71+
Assert.Null(user.PasswordHash);
72+
Assert.Null(user.PasswordSalt);
73+
}
74+
75+
[Fact]
76+
public void AllProperties()
77+
{
78+
var response = new GetAccountInfoResponse.User()
79+
{
80+
UserId = "user1",
81+
DisplayName = "Test User",
82+
Email = "[email protected]",
83+
PhoneNumber = "+11234567890",
84+
PhotoUrl = "https://domain.com/user.png",
85+
Disabled = true,
86+
EmailVerified = true,
87+
ValidSince = 3600,
88+
CreatedAt = 100,
89+
LastLoginAt = 150,
90+
CustomClaims = @"{""admin"": true, ""level"": 10}",
91+
PasswordHash = "secret",
92+
PasswordSalt = "nacl",
93+
Providers = new List<GetAccountInfoResponse.Provider>()
94+
{
95+
new GetAccountInfoResponse.Provider()
96+
{
97+
ProviderID = "google.com",
98+
UserId = "googleuid",
99+
},
100+
new GetAccountInfoResponse.Provider()
101+
{
102+
ProviderID = "other.com",
103+
UserId = "otheruid",
104+
DisplayName = "Other Name",
105+
Email = "[email protected]",
106+
PhotoUrl = "https://other.com/user.png",
107+
PhoneNumber = "+10987654321",
108+
},
109+
},
110+
};
111+
var user = new ExportedUserRecord(response);
112+
113+
Assert.Equal("user1", user.Uid);
114+
Assert.Equal("Test User", user.DisplayName);
115+
Assert.Equal("[email protected]", user.Email);
116+
Assert.Equal("+11234567890", user.PhoneNumber);
117+
Assert.Equal("https://domain.com/user.png", user.PhotoUrl);
118+
Assert.Equal("firebase", user.ProviderId);
119+
Assert.True(user.Disabled);
120+
Assert.True(user.EmailVerified);
121+
Assert.Equal(UserRecord.UnixEpoch.AddSeconds(3600), user.TokensValidAfterTimestamp);
122+
Assert.Equal("secret", user.PasswordHash);
123+
Assert.Equal("nacl", user.PasswordSalt);
124+
125+
var claims = new Dictionary<string, object>()
126+
{
127+
{ "admin", true },
128+
{ "level", 10L },
129+
};
130+
Assert.Equal(claims, user.CustomClaims);
131+
132+
Assert.Equal(2, user.ProviderData.Length);
133+
var provider = user.ProviderData[0];
134+
Assert.Equal("google.com", provider.ProviderId);
135+
Assert.Equal("googleuid", provider.Uid);
136+
Assert.Null(provider.DisplayName);
137+
Assert.Null(provider.Email);
138+
Assert.Null(provider.PhoneNumber);
139+
Assert.Null(provider.PhotoUrl);
140+
141+
provider = user.ProviderData[1];
142+
Assert.Equal("other.com", provider.ProviderId);
143+
Assert.Equal("otheruid", provider.Uid);
144+
Assert.Equal("Other Name", provider.DisplayName);
145+
Assert.Equal("[email protected]", provider.Email);
146+
Assert.Equal("+10987654321", provider.PhoneNumber);
147+
Assert.Equal("https://other.com/user.png", provider.PhotoUrl);
148+
149+
var metadata = user.UserMetaData;
150+
Assert.NotNull(metadata);
151+
Assert.Equal(UserRecord.UnixEpoch.AddMilliseconds(100), metadata.CreationTimestamp);
152+
Assert.Equal(UserRecord.UnixEpoch.AddMilliseconds(150), metadata.LastSignInTimestamp);
153+
}
154+
}
155+
}

FirebaseAdmin/FirebaseAdmin/Auth/ExportedUserRecords.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ namespace FirebaseAdmin.Auth
2222
public sealed class ExportedUserRecords
2323
{
2424
/// <summary>
25-
/// Gets or sets the next page link.
25+
/// Gets the token representing the next page of users.
2626
/// </summary>
27-
public string NextPageToken { get; set; }
27+
public string NextPageToken { get; internal set; }
2828

2929
/// <summary>
30-
/// Gets or sets the users.
30+
/// Gets the users included in the current page.
3131
/// </summary>
32-
public IEnumerable<ExportedUserRecord> Users { get; set; }
32+
public IEnumerable<ExportedUserRecord> Users { get; internal set; }
3333
}
3434
}

FirebaseAdmin/FirebaseAdmin/Auth/ListUsersRequest.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,11 @@ private ListUsersRequest(
6363

6464
public void SetPageSize(int pageSize)
6565
{
66-
if (pageSize > MaxListUsersResults)
67-
{
68-
throw new ArgumentException("Page size must not exceed 1000.");
69-
}
70-
else if (pageSize <= 0)
71-
{
72-
throw new ArgumentException("Page size must be a positive integer.");
73-
}
74-
7566
this.AddOrUpdate("maxResults", pageSize.ToString());
7667
}
7768

7869
public void SetPageToken(string pageToken)
7970
{
80-
if (pageToken == string.Empty)
81-
{
82-
throw new ArgumentException("Page token must not be empty.");
83-
}
84-
8571
this.AddOrUpdate("nextPageToken", pageToken);
8672
}
8773

0 commit comments

Comments
 (0)