Skip to content

Commit 797feb1

Browse files
authored
Merge pull request #20 from firebase/hkj-stylecop
Stylecop integration for linting
2 parents 21ca44b + b1221bf commit 797feb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1184
-907
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ matrix:
88
script:
99
- dotnet build FirebaseAdmin/FirebaseAdmin
1010
- dotnet build FirebaseAdmin/FirebaseAdmin.Snippets
11+
- dotnet build FirebaseAdmin/FirebaseAdmin.IntegrationTests
1112
- dotnet test FirebaseAdmin/FirebaseAdmin.Tests

FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAdmin.IntegrationTests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.0</TargetFramework>
5-
65
<IsPackable>false</IsPackable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
78
</PropertyGroup>
89

910
<ItemGroup>
@@ -12,6 +13,9 @@
1213
<PackageReference Include="xunit" Version="2.3.1" />
1314
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
1415
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
16+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
17+
<PrivateAssets>all</PrivateAssets>
18+
</PackageReference>
1519
</ItemGroup>
1620

1721
<ItemGroup>

FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAuthTest.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@
1717
using System.Net.Http;
1818
using System.Text;
1919
using System.Threading.Tasks;
20-
using Xunit;
2120
using FirebaseAdmin;
2221
using FirebaseAdmin.Auth;
2322
using Google.Apis.Auth.OAuth2;
2423
using Google.Apis.Util;
24+
using Xunit;
2525

2626
namespace FirebaseAdmin.IntegrationTests
2727
{
2828
public class FirebaseAuthTest
2929
{
30-
private const string VerifyCustomTokenUrl =
30+
private const string VerifyCustomTokenUrl =
3131
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken";
3232

3333
public FirebaseAuthTest()
3434
{
3535
IntegrationTestUtils.EnsureDefaultApp();
3636
}
37-
37+
3838
[Fact]
3939
public async Task CreateCustomToken()
4040
{
@@ -50,9 +50,9 @@ public async Task CreateCustomTokenWithClaims()
5050
{
5151
var developerClaims = new Dictionary<string, object>()
5252
{
53-
{"admin", true},
54-
{"package", "gold"},
55-
{"magicNumber", 42L},
53+
{ "admin", true },
54+
{ "package", "gold" },
55+
{ "magicNumber", 42L },
5656
};
5757
var customToken = await FirebaseAuth.DefaultInstance.CreateCustomTokenAsync(
5858
"testuser", developerClaims);
@@ -72,13 +72,14 @@ public async Task CreateCustomTokenWithClaims()
7272
public async Task CreateCustomTokenWithoutServiceAccount()
7373
{
7474
var googleCred = FirebaseApp.DefaultInstance.Options.Credential;
75-
var serviceAcct = (ServiceAccountCredential) googleCred.UnderlyingCredential;
76-
var token = await ((ITokenAccess) googleCred).GetAccessTokenForRequestAsync();
77-
var app = FirebaseApp.Create(new AppOptions()
78-
{
79-
Credential = GoogleCredential.FromAccessToken(token),
80-
ServiceAccountId = serviceAcct.Id,
81-
}, "IAMSignApp");
75+
var serviceAcct = (ServiceAccountCredential)googleCred.UnderlyingCredential;
76+
var token = await ((ITokenAccess)googleCred).GetAccessTokenForRequestAsync();
77+
var app = FirebaseApp.Create(
78+
new AppOptions()
79+
{
80+
Credential = GoogleCredential.FromAccessToken(token),
81+
ServiceAccountId = serviceAcct.Id,
82+
}, "IAMSignApp");
8283
try
8384
{
8485
var customToken = await FirebaseAuth.GetAuth(app).CreateCustomTokenAsync(
@@ -98,7 +99,7 @@ public async Task SetCustomUserClaims()
9899
{
99100
var customClaims = new Dictionary<string, object>()
100101
{
101-
{"admin", true}
102+
{ "admin", true },
102103
};
103104

104105
await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync("testuser", customClaims);
@@ -126,12 +127,13 @@ private static async Task<string> SignInWithCustomTokenAsync(string customToken)
126127
var rb = new Google.Apis.Requests.RequestBuilder()
127128
{
128129
Method = Google.Apis.Http.HttpConsts.Post,
129-
BaseUri = new Uri(VerifyCustomTokenUrl),
130+
BaseUri = new Uri(VerifyCustomTokenUrl),
130131
};
131132
rb.AddParameter(RequestParameterType.Query, "key", IntegrationTestUtils.GetApiKey());
132133
var request = rb.CreateRequest();
133134
var jsonSerializer = Google.Apis.Json.NewtonsoftJsonSerializer.Instance;
134-
var payload = jsonSerializer.Serialize(new SignInRequest{
135+
var payload = jsonSerializer.Serialize(new SignInRequest
136+
{
135137
CustomToken = customToken,
136138
ReturnSecureToken = true,
137139
});
@@ -159,6 +161,6 @@ internal class SignInRequest
159161
internal class SignInResponse
160162
{
161163
[Newtonsoft.Json.JsonProperty("idToken")]
162-
public String IdToken { get; set; }
164+
public string IdToken { get; set; }
163165
}
164166
}

FirebaseAdmin/FirebaseAdmin.IntegrationTests/IntegrationTestUtils.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ internal static class IntegrationTestUtils
2626
private const string ServiceAccountFile = "./resources/integration_cert.json";
2727
private const string ApiKeyFile = "./resources/integration_apikey.txt";
2828

29-
private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(() => {
30-
var options = new AppOptions()
29+
private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(
30+
() =>
3131
{
32-
Credential = GoogleCredential.FromFile(ServiceAccountFile),
33-
};
34-
return FirebaseApp.Create(options);
35-
}, true);
32+
var options = new AppOptions()
33+
{
34+
Credential = GoogleCredential.FromFile(ServiceAccountFile),
35+
};
36+
return FirebaseApp.Create(options);
37+
}, true);
3638

3739
public static FirebaseApp EnsureDefaultApp()
3840
{

FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAdmin.Snippets.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<IsPackable>false</IsPackable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
68
</PropertyGroup>
79

810
<ItemGroup>
@@ -11,6 +13,9 @@
1113

1214
<ItemGroup>
1315
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
16+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
17+
<PrivateAssets>all</PrivateAssets>
18+
</PackageReference>
1419
</ItemGroup>
1520

1621
</Project>

FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAppSnippets.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
namespace FirebaseAdmin.Snippets
2323
{
24-
class FirebaseAppSnippets
24+
internal class FirebaseAppSnippets
2525
{
26-
static void InitSdkWithServiceAccount()
26+
internal static void InitSdkWithServiceAccount()
2727
{
2828
// [START initialize_sdk_with_service_account]
2929
FirebaseApp.Create(new AppOptions()
@@ -33,7 +33,7 @@ static void InitSdkWithServiceAccount()
3333
// [END initialize_sdk_with_service_account]
3434
}
3535

36-
static void InitSdkWithApplicationDefault()
36+
internal static void InitSdkWithApplicationDefault()
3737
{
3838
// [START initialize_sdk_with_application_default]
3939
FirebaseApp.Create(new AppOptions()
@@ -43,7 +43,7 @@ static void InitSdkWithApplicationDefault()
4343
// [END initialize_sdk_with_application_default]
4444
}
4545

46-
static void InitSdkWithRefreshToken()
46+
internal static void InitSdkWithRefreshToken()
4747
{
4848
// [START initialize_sdk_with_refresh_token]
4949
FirebaseApp.Create(new AppOptions()
@@ -53,14 +53,14 @@ static void InitSdkWithRefreshToken()
5353
// [END initialize_sdk_with_refresh_token]
5454
}
5555

56-
static void InitSdkWithDefaultConfig()
56+
internal static void InitSdkWithDefaultConfig()
5757
{
5858
// [START initialize_sdk_with_default_config]
5959
FirebaseApp.Create();
6060
// [END initialize_sdk_with_default_config]
6161
}
6262

63-
static void InitDefaultApp()
63+
internal static void InitDefaultApp()
6464
{
6565
// [START access_services_default]
6666
// Initialize the default app
@@ -78,7 +78,7 @@ static void InitDefaultApp()
7878
// [END access_services_default]
7979
}
8080

81-
static void InitCustomApp()
81+
internal static void InitCustomApp()
8282
{
8383
var defaultOptions = new AppOptions()
8484
{
@@ -107,7 +107,7 @@ static void InitCustomApp()
107107
// [END access_services_nondefault]
108108
}
109109

110-
static void InitWithServiceAccountId()
110+
internal static void InitWithServiceAccountId()
111111
{
112112
// [START initialize_sdk_with_service_account_id]
113113
FirebaseApp.Create(new AppOptions()

FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAuthSnippets.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
namespace FirebaseAdmin.Snippets
2121
{
22-
class FirebaseAuthSnippets
22+
internal class FirebaseAuthSnippets
2323
{
24-
static async Task CreateCustomTokenAsync()
24+
internal static async Task CreateCustomTokenAsync()
2525
{
2626
// [START custom_token]
2727
var uid = "some-uid";
@@ -32,7 +32,7 @@ static async Task CreateCustomTokenAsync()
3232
Console.WriteLine("Created custom token: {0}", customToken);
3333
}
3434

35-
static async Task CreateCustomTokenWithClaimsAsync()
35+
internal static async Task CreateCustomTokenWithClaimsAsync()
3636
{
3737
// [START custom_token_with_claims]
3838
var uid = "some-uid";
@@ -48,7 +48,7 @@ static async Task CreateCustomTokenWithClaimsAsync()
4848
Console.WriteLine("Created custom token: {0}", customToken);
4949
}
5050

51-
static async Task VeridyIdTokenAsync(string idToken)
51+
internal static async Task VeridyIdTokenAsync(string idToken)
5252
{
5353
// [START verify_id_token]
5454
FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance

0 commit comments

Comments
 (0)