Skip to content

Commit f82594d

Browse files
committed
Apply consistent styling
1 parent 83e14af commit f82594d

19 files changed

Lines changed: 184 additions & 92 deletions

src/.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ dotnet_naming_symbols.any_async_methods.required_modifiers = async
1111

1212
dotnet_naming_style.end_in_async.required_suffix = Async
1313
dotnet_naming_style.end_in_async.capitalization = pascal_case
14+
15+
[*.cs]
16+
17+
# SA1101: Prefix local calls with this
18+
dotnet_diagnostic.SA1101.severity = none
19+
20+
# SA1309: Field names should not begin with underscore
21+
dotnet_diagnostic.SA1309.severity = none
22+
23+
# SA1503: Braces should not be omitted
24+
dotnet_diagnostic.SA1503.severity = none

src/Tesla.NET/Tesla.NET.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
32-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
32+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
3333
<PrivateAssets>all</PrivateAssets>
34-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
34+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3535
</PackageReference>
3636
</ItemGroup>
3737

src/stylecop.ruleset

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="Rules for StyleCop.Analyzers" Description="Code analysis rules." ToolsVersion="14.0">
2+
<RuleSet Name="Rules for StyleCop.Analyzers" Description="Code analysis rules." ToolsVersion="16.0">
33
<Include Path="minimumrecommendedrules.ruleset" Action="Default" />
44
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
5-
<Rule Id="SA1101" Action="None" />
6-
<Rule Id="SA1309" Action="None" />
7-
<Rule Id="SA1503" Action="None" />
5+
<Rule Id="SX1101" Action="Error" />
6+
<Rule Id="SX1309" Action="Error" />
87
</Rules>
98
</RuleSet>

test/.editorconfig

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[*.cs]
2+
3+
# SA1101: Prefix local calls with this
4+
dotnet_diagnostic.SA1101.severity = none
5+
6+
# SA1300: Element should begin with upper-case letter
7+
dotnet_diagnostic.SA1300.severity = none
8+
9+
# SA1309: Field names should not begin with underscore
10+
dotnet_diagnostic.SA1309.severity = none
11+
12+
# SA1402: File may only contain a single type
13+
dotnet_diagnostic.SA1402.severity = none
14+
15+
# SA1503: Braces should not be omitted
16+
dotnet_diagnostic.SA1503.severity = none
17+
18+
# SA1600: Elements should be documented
19+
dotnet_diagnostic.SA1600.severity = none
20+
21+
# SA1611: Element parameters should be documented
22+
dotnet_diagnostic.SA1611.severity = none
23+
24+
# SA1615: Element return value should be documented
25+
dotnet_diagnostic.SA1615.severity = none
26+
27+
# SA1623: Property summary documentation should match accessors
28+
dotnet_diagnostic.SA1623.severity = none
29+
30+
# SA1649: File name should match first type name
31+
dotnet_diagnostic.SA1649.severity = none
32+
33+
# CA1303: Do not pass literals as localized parameters
34+
dotnet_diagnostic.CA1303.severity = none
35+
36+
# CA1707: Identifiers should not contain underscores
37+
dotnet_diagnostic.CA1707.severity = none
38+
39+
# IDE1006: Naming Styles
40+
dotnet_diagnostic.IDE1006.severity = none

test/Tesla.NET.Tests/DebuggerDisplayTests.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,13 @@ public abstract class DebuggerDisplayTestsBase : FixtureContext
1717
private PropertyInfo? _debuggerDisplayPropertyInfo;
1818
private MethodInfo? _debuggerDisplayGetMethod;
1919
private object? _debuggerDisplayValue;
20-
protected string? DebuggerDisplayText;
2120

2221
protected DebuggerDisplayTestsBase(ITestOutputHelper output)
2322
: base(output)
2423
{
2524
}
2625

27-
protected void GetDebuggerDisplay<TSut>(TSut sut)
28-
{
29-
_sutType = sut?.GetType();
30-
31-
_debuggerDisplay = _sutType?.GetCustomAttribute<DebuggerDisplayAttribute>(inherit: false);
32-
33-
_debuggerDisplayPropertyInfo =
34-
_sutType?.GetProperty("DebuggerDisplay", BindingFlags.NonPublic | BindingFlags.Instance);
35-
36-
_debuggerDisplayGetMethod = _debuggerDisplayPropertyInfo?.GetGetMethod(true);
37-
38-
_debuggerDisplayValue = _debuggerDisplayGetMethod?.Invoke(sut, new object[] { });
39-
40-
DebuggerDisplayText = _debuggerDisplayValue?.ToString();
41-
}
26+
protected string? DebuggerDisplayText { get; private set; }
4227

4328
[Fact]
4429
public void have_the_debugger_display_attribute()
@@ -79,5 +64,21 @@ public void include_the_type_in_the_debugger_display()
7964

8065
DebuggerDisplayText.Should().StartWith($"{_sutType.Name}:");
8166
}
67+
68+
protected void GetDebuggerDisplay<TSut>(TSut sut)
69+
{
70+
_sutType = sut?.GetType();
71+
72+
_debuggerDisplay = _sutType?.GetCustomAttribute<DebuggerDisplayAttribute>(inherit: false);
73+
74+
_debuggerDisplayPropertyInfo =
75+
_sutType?.GetProperty("DebuggerDisplay", BindingFlags.NonPublic | BindingFlags.Instance);
76+
77+
_debuggerDisplayGetMethod = _debuggerDisplayPropertyInfo?.GetGetMethod(true);
78+
79+
_debuggerDisplayValue = _debuggerDisplayGetMethod?.Invoke(sut, new object[] { });
80+
81+
DebuggerDisplayText = _debuggerDisplayValue?.ToString();
82+
}
8283
}
8384
}

test/Tesla.NET.Tests/InvalidJsonResponseTests.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,34 @@ public abstract class InvalidJsonResponseTestsBase : ClientRequestContext
2525
private readonly HttpStatusCode _statusCode;
2626

2727
protected InvalidJsonResponseTestsBase(ITestOutputHelper output, HttpStatusCode statusCode)
28-
: base(output, useCustomBaseUri : false)
28+
: base(output, useCustomBaseUri: false)
2929
{
3030
// Arrange
3131
_statusCode = statusCode;
3232
_vehicleId = Fixture.Create<long>();
3333
Handler.Response = CreateResponse(statusCode);
3434
}
3535

36+
[Fact]
37+
public async Task It_should_return_just_the_HTTP_status_Code()
38+
{
39+
// Act
40+
IMessageResponse actual = await Sut.GetVehicleStateAsync(_vehicleId, AccessToken).ConfigureAwait(false);
41+
42+
// Assert
43+
actual.HttpStatusCode.Should().Be(_statusCode);
44+
}
45+
46+
[Fact]
47+
public void It_should_not_throw_an_exception()
48+
{
49+
// Act
50+
Func<Task> action = () => Sut.GetVehicleStateAsync(_vehicleId, AccessToken);
51+
52+
// Assert
53+
action.Should().NotThrow();
54+
}
55+
3656
private static HttpResponseMessage CreateResponse(HttpStatusCode statusCode)
3757
{
3858
string stringContent = "0" + Environment.NewLine + Environment.NewLine;
@@ -49,7 +69,7 @@ private static HttpResponseMessage CreateResponse(HttpStatusCode statusCode)
4969
Headers =
5070
{
5171
ContentType = new MediaTypeHeaderValue("application/json"),
52-
}
72+
},
5373
};
5474

5575
HttpResponseMessage response = new HttpResponseMessage(statusCode)
@@ -58,26 +78,6 @@ private static HttpResponseMessage CreateResponse(HttpStatusCode statusCode)
5878
};
5979
return response;
6080
}
61-
62-
[Fact]
63-
public async Task It_should_return_just_the_HTTP_status_Code()
64-
{
65-
// Act
66-
IMessageResponse actual = await Sut.GetVehicleStateAsync(_vehicleId, AccessToken).ConfigureAwait(false);
67-
68-
// Assert
69-
actual.HttpStatusCode.Should().Be(_statusCode);
70-
}
71-
72-
[Fact]
73-
public void It_should_not_throw_an_exception()
74-
{
75-
// Act
76-
Func<Task> action = () => Sut.GetVehicleStateAsync(_vehicleId, AccessToken);
77-
78-
// Assert
79-
action.Should().NotThrow();
80-
}
8181
}
8282

8383
/// <summary>

test/Tesla.NET.Tests/Models/Internal/GetVehiclesResponseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public When_deserializing_GetVehiclesResponse_Should_deserialize(ITestOutputHelp
7272
}
7373

7474
[Fact]
75-
public void response() =>_sut.Response.Should().BeEquivalentTo(_expectedResponse, WithStrictOrdering);
75+
public void response() => _sut.Response.Should().BeEquivalentTo(_expectedResponse, WithStrictOrdering);
7676
}
7777
}

test/Tesla.NET.Tests/Models/SampleJson.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ namespace Tesla.NET.Models
1111

1212
internal static class SampleJson
1313
{
14-
public static TJson Load<TJson>(string fileName)
15-
where TJson : JToken
16-
{
17-
Stream? stream =
18-
typeof(SampleJson).Assembly.GetManifestResourceStream(typeof(SampleJson), $"{fileName}.json");
19-
20-
if (stream == null)
21-
throw new InvalidOperationException(
22-
$"Unable to load Sample JSON file '{fileName}'" +
23-
" - did you mark the file as an 'embedded resource'?");
24-
25-
using var sr = new StreamReader(stream);
26-
string json = sr.ReadToEnd();
27-
return (TJson)JToken.Parse(json);
28-
}
29-
3014
public static JObject AccessTokenResponse => Load<JObject>(nameof(AccessTokenResponse));
3115

3216
public static JObject ChargeState => GetChargeStateResponse.Response();
@@ -57,6 +41,23 @@ public static TJson Load<TJson>(string fileName)
5741

5842
public static JObject VehicleStateMinimal => new JObject();
5943

44+
public static TJson Load<TJson>(string fileName)
45+
where TJson : JToken
46+
{
47+
Stream? stream =
48+
typeof(SampleJson).Assembly.GetManifestResourceStream(typeof(SampleJson), $"{fileName}.json");
49+
50+
if (stream == null)
51+
{
52+
throw new InvalidOperationException(
53+
$"Unable to load Sample JSON file '{fileName}' - did you mark the file as an 'embedded resource'?");
54+
}
55+
56+
using var sr = new StreamReader(stream);
57+
string json = sr.ReadToEnd();
58+
return (TJson)JToken.Parse(json);
59+
}
60+
6061
private static JObject Response(this JToken data)
6162
{
6263
JObject response = (JObject?)data["response"] ?? throw new InvalidOperationException("response is null.");

test/Tesla.NET.Tests/RefreshAccessTokenTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected RefreshAccessTokenFailureTestsBase(ITestOutputHelper output, bool useC
193193
}
194194

195195
[Fact]
196-
public async Task Should_return_the_error_status_code()
196+
public async Task Should_return_the_error_status_code()
197197
{
198198
// Act
199199
IMessageResponse actual =

test/Tesla.NET.Tests/RequiresArgNullEx.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Tesla.NET
1414

1515
public class RequiresArgNullEx
1616
{
17-
[Theory, RequiresArgNullExAutoMoq(typeof(TeslaClientBase))]
17+
[Theory]
18+
[RequiresArgNullExAutoMoq(typeof(TeslaClientBase))]
1819
[Substitute(typeof(TeslaClientBase), typeof(TeslaAuthClient))]
1920
[Substitute(typeof(MessageResponse<>), typeof(MessageResponse<object>))]
2021
[Substitute(typeof(ResponseDataWrapper<>), typeof(ResponseDataWrapper<Guid>))]

0 commit comments

Comments
 (0)