Skip to content

Commit bbbc925

Browse files
committed
Fixing lint errors
1 parent af9e80b commit bbbc925

18 files changed

+603
-492
lines changed

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/FirebaseMessageClientTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public async Task SendAsync()
6060
{
6161
var handler = new MockMessageHandler()
6262
{
63-
Response = new SendResponse()
63+
Response = new FirebaseMessagingClient.SendResponse()
6464
{
6565
Name = "test-response",
6666
},
@@ -73,15 +73,17 @@ public async Task SendAsync()
7373
};
7474
var response = await client.SendAsync(message);
7575
Assert.Equal("test-response", response);
76-
var req = JsonConvert.DeserializeObject<SendRequest>(handler.Request);
76+
var req = JsonConvert.DeserializeObject<FirebaseMessagingClient.SendRequest>(
77+
handler.Request);
7778
Assert.Equal("test-topic", req.Message.Topic);
7879
Assert.False(req.ValidateOnly);
7980
Assert.Equal(1, handler.Calls);
8081

8182
// Send in dryRun mode.
8283
response = await client.SendAsync(message, dryRun: true);
8384
Assert.Equal("test-response", response);
84-
req = JsonConvert.DeserializeObject<SendRequest>(handler.Request);
85+
req = JsonConvert.DeserializeObject<FirebaseMessagingClient.SendRequest>(
86+
handler.Request);
8587
Assert.Equal("test-topic", req.Message.Topic);
8688
Assert.True(req.ValidateOnly);
8789
Assert.Equal(2, handler.Calls);
@@ -104,7 +106,8 @@ public async Task HttpErrorAsync()
104106
var ex = await Assert.ThrowsAsync<FirebaseException>(
105107
async () => await client.SendAsync(message));
106108
Assert.Contains("not json", ex.Message);
107-
var req = JsonConvert.DeserializeObject<SendRequest>(handler.Request);
109+
var req = JsonConvert.DeserializeObject<FirebaseMessagingClient.SendRequest>(
110+
handler.Request);
108111
Assert.Equal("test-topic", req.Message.Topic);
109112
Assert.False(req.ValidateOnly);
110113
Assert.Equal(1, handler.Calls);

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ public class MessageTest
2727
[Fact]
2828
public void EmptyMessage()
2929
{
30-
var message = new Message(){Token = "test-token"};
31-
AssertJsonEquals(new JObject(){{"token", "test-token"}}, message);
30+
var message = new Message() { Token = "test-token" };
31+
AssertJsonEquals(new JObject() { { "token", "test-token" } }, message);
3232

33-
message = new Message(){Topic = "test-topic"};
34-
AssertJsonEquals(new JObject(){{"topic", "test-topic"}}, message);
33+
message = new Message() { Topic = "test-topic" };
34+
AssertJsonEquals(new JObject() { { "topic", "test-topic" } }, message);
3535

36-
message = new Message(){Condition = "test-condition"};
37-
AssertJsonEquals(new JObject(){{"condition", "test-condition"}}, message);
36+
message = new Message() { Condition = "test-condition" };
37+
AssertJsonEquals(new JObject() { { "condition", "test-condition" } }, message);
3838
}
3939

4040
[Fact]
4141
public void PrefixedTopicName()
4242
{
43-
var message = new Message(){Topic = "/topics/test-topic"};
43+
var message = new Message() { Topic = "/topics/test-topic" };
4444
AssertJsonEquals(new JObject(){{"topic", "test-topic"}}, message);
4545
}
4646

FirebaseAdmin/FirebaseAdmin/Extensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static IReadOnlyDictionary<TKey, TValue> Copy<TKey, TValue>(
121121
{
122122
copy[entry.Key] = entry.Value;
123123
}
124+
124125
return copy;
125126
}
126127
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2018, 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 Newtonsoft.Json;
16+
17+
namespace FirebaseAdmin.Messaging
18+
{
19+
/// <summary>
20+
/// Represents an action available to users when the notification is presented.
21+
/// </summary>
22+
public sealed class Action
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="Action"/> class.
26+
/// </summary>
27+
public Action() { }
28+
29+
internal Action(Action action)
30+
{
31+
this.ActionName = action.ActionName;
32+
this.Title = action.Title;
33+
this.Icon = action.Icon;
34+
}
35+
36+
/// <summary>
37+
/// Gets or sets the name of the Action.
38+
/// </summary>
39+
[JsonProperty("action")]
40+
public string ActionName { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the title text.
44+
/// </summary>
45+
[JsonProperty("title")]
46+
public string Title { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the icon URL.
50+
/// </summary>
51+
[JsonProperty("icon")]
52+
public string Icon { get; set; }
53+
}
54+
}

FirebaseAdmin/FirebaseAdmin/Messaging/AndroidConfig.cs

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,58 @@ namespace FirebaseAdmin.Messaging
2424
public sealed class AndroidConfig
2525
{
2626
/// <summary>
27-
/// A collapse key for the message. Collapse key serves as an identifier for a group of
28-
/// messages that can be collapsed, so that only the last message gets sent when delivery can be
29-
/// resumed. A maximum of 4 different collapse keys may be active at any given time.
27+
/// Gets or sets a collapse key for the message. Collapse key serves as an identifier for a
28+
/// group of messages that can be collapsed, so that only the last message gets sent when
29+
/// delivery can be resumed. A maximum of 4 different collapse keys may be active at any
30+
/// given time.
3031
/// </summary>
3132
[JsonProperty("collapse_key")]
3233
public string CollapseKey { get; set; }
3334

3435
/// <summary>
35-
/// The priority of the message.
36+
/// Gets or sets the priority of the message.
3637
/// </summary>
3738
[JsonIgnore]
3839
public Priority? Priority { get; set; }
3940

4041
/// <summary>
41-
/// String representation of the <see cref="Priority"/> as accepted by the FCM backend
42-
/// service.
42+
/// Gets or sets the time-to-live duration of the message.
43+
/// </summary>
44+
[JsonIgnore]
45+
public TimeSpan? TimeToLive { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the package name of the application where the registration tokens must
49+
/// match in order to receive the message.
50+
/// </summary>
51+
[JsonProperty("restricted_package_name")]
52+
public string RestrictedPackageName { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets a collection of key-value pairs that will be added to the message as data
56+
/// fields. Keys and the values must not be null. When set, overrides any data fields set
57+
/// on the top-level
58+
/// <see cref="Message"/>.
59+
/// </summary>
60+
[JsonProperty("data")]
61+
public IReadOnlyDictionary<string, string> Data { get; set; }
62+
63+
/// <summary>
64+
/// Gets or sets the Android notification to be included in the message.
65+
/// </summary>
66+
[JsonProperty("notification")]
67+
public AndroidNotification Notification { get; set; }
68+
69+
/// <summary>
70+
/// Gets or sets the string representation of <see cref="Priority"/> as accepted by the FCM
71+
/// backend service.
4372
/// </summary>
4473
[JsonProperty("priority")]
4574
private string PriorityString
4675
{
4776
get
4877
{
49-
switch (Priority)
78+
switch (this.Priority)
5079
{
5180
case Messaging.Priority.High:
5281
return "high";
@@ -56,15 +85,16 @@ private string PriorityString
5685
return null;
5786
}
5887
}
88+
5989
set
6090
{
6191
switch (value)
6292
{
6393
case "high":
64-
Priority = Messaging.Priority.High;
94+
this.Priority = Messaging.Priority.High;
6595
return;
6696
case "normal":
67-
Priority = Messaging.Priority.High;
97+
this.Priority = Messaging.Priority.High;
6898
return;
6999
default:
70100
throw new FirebaseException(
@@ -75,69 +105,46 @@ private string PriorityString
75105
}
76106

77107
/// <summary>
78-
/// The time-to-live duration of the message.
79-
/// </summary>
80-
[JsonIgnore]
81-
public TimeSpan? TimeToLive { get; set; }
82-
83-
/// <summary>
84-
/// String representation of <see cref="TimeToLive"/> as accepted by the FCM backend
85-
/// service. The string ends in the suffix "s" (indicating seconds) and is preceded
86-
/// by the number of seconds, with nanoseconds expressed as fractional seconds.
108+
/// Gets or sets the string representation of <see cref="TimeToLive"/> as accepted by the
109+
/// FCM backend service. The string ends in the suffix "s" (indicating seconds) and is
110+
/// preceded by the number of seconds, with nanoseconds expressed as fractional seconds.
87111
/// </summary>
88112
[JsonProperty("ttl")]
89113
private string TtlString
90114
{
91115
get
92116
{
93-
if (TimeToLive == null)
117+
if (this.TimeToLive == null)
94118
{
95119
return null;
96120
}
97-
var totalSeconds = TimeToLive.Value.TotalSeconds;
98-
var seconds = (long) Math.Floor(totalSeconds);
99-
var subsecondNanos = (long) ((totalSeconds - seconds) * 1e9);
121+
122+
var totalSeconds = this.TimeToLive.Value.TotalSeconds;
123+
var seconds = (long)Math.Floor(totalSeconds);
124+
var subsecondNanos = (long)((totalSeconds - seconds) * 1e9);
100125
if (subsecondNanos > 0)
101126
{
102-
return String.Format("{0}.{1:D9}s", seconds, subsecondNanos);
127+
return string.Format("{0}.{1:D9}s", seconds, subsecondNanos);
103128
}
104-
return String.Format("{0}s", seconds);
129+
130+
return string.Format("{0}s", seconds);
105131
}
132+
106133
set
107134
{
108135
var segments = value.TrimEnd('s').Split('.');
109-
var seconds = Int64.Parse(segments[0]);
136+
var seconds = long.Parse(segments[0]);
110137
var ttl = TimeSpan.FromSeconds(seconds);
111138
if (segments.Length == 2)
112139
{
113-
var subsecondNanos = Int64.Parse(segments[1].TrimStart('0'));
140+
var subsecondNanos = long.Parse(segments[1].TrimStart('0'));
114141
ttl = ttl.Add(TimeSpan.FromMilliseconds(subsecondNanos / 1e6));
115142
}
116-
TimeToLive = ttl;
143+
144+
this.TimeToLive = ttl;
117145
}
118146
}
119147

120-
/// <summary>
121-
/// The package name of the application where the registration tokens must match in order
122-
/// to receive the message.
123-
/// </summary>
124-
[JsonProperty("restricted_package_name")]
125-
public string RestrictedPackageName { get; set; }
126-
127-
/// <summary>
128-
/// A collection of key-value pairs that will be added to the message as data fields. Keys
129-
/// and the values must not be null. When set, overrides any data fields set on the top-level
130-
/// <see cref="Message"/>.
131-
/// </summary>
132-
[JsonProperty("data")]
133-
public IReadOnlyDictionary<string, string> Data { get; set; }
134-
135-
/// <summary>
136-
/// The Android notification to be included in the message.
137-
/// </summary>
138-
[JsonProperty("notification")]
139-
public AndroidNotification Notification { get; set; }
140-
141148
/// <summary>
142149
/// Copies this Android config, and validates the content of it to ensure that it can be
143150
/// serialized into the JSON format expected by the FCM service.
@@ -164,20 +171,4 @@ internal AndroidConfig CopyAndValidate()
164171
return copy;
165172
}
166173
}
167-
168-
/// <summary>
169-
/// Priority levels that can be set on an <see cref="AndroidConfig"/>.
170-
/// </summary>
171-
public enum Priority
172-
{
173-
/// <summary>
174-
/// High priority message.
175-
/// </summary>
176-
High,
177-
178-
/// <summary>
179-
/// Normal priority message.
180-
/// </summary>
181-
Normal,
182-
}
183174
}

0 commit comments

Comments
 (0)