Skip to content

Commit

Permalink
Chore: Format code & tidy up (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker authored Sep 10, 2023
1 parent 55f286a commit 3465436
Show file tree
Hide file tree
Showing 268 changed files with 4,875 additions and 5,075 deletions.
33 changes: 22 additions & 11 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should be PascalCase
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_prefix_style.capitalization = pascal_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
Expand All @@ -80,7 +80,7 @@ dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:none
Expand Down Expand Up @@ -121,7 +121,18 @@ csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# IDE1006: 命名样式
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.ide1006.severity = none

# CA1848: 使用 LoggerMessage 委托
dotnet_diagnostic.CA1848.severity = none
dotnet_diagnostic.ca1848.severity = none

# ReSharper properties
resharper_csharp_max_line_length = 150
resharper_local_function_body = expression_body
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_field_attribute_on_same_line = false
resharper_wrap_switch_expression = wrap_if_long

# ReSharper inspection severities
resharper_arrange_local_function_body_highlighting = hint
resharper_arrange_method_or_operator_body_highlighting = hint
13 changes: 13 additions & 0 deletions src/.idea/.idea.GZCTF/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/.idea/.idea.GZCTF/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 13 additions & 26 deletions src/GZCTF.Test/AccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -8,8 +9,8 @@ namespace GZCTF.Test;

public class AccountTest : IClassFixture<TestWebAppFactory>
{
private readonly TestWebAppFactory _factory;
private readonly ITestOutputHelper _output;
readonly TestWebAppFactory _factory;
readonly ITestOutputHelper _output;

public AccountTest(TestWebAppFactory factory, ITestOutputHelper output)
{
Expand All @@ -20,35 +21,21 @@ public AccountTest(TestWebAppFactory factory, ITestOutputHelper output)
[Fact]
public async Task TestCreateUser()
{
using var client = _factory.CreateClient();
var registerResult = await client.PostAsJsonAsync("/api/account/register", new
{
userName = "foo",
password = "foo12345",
email = "[email protected]",
});
using HttpClient client = _factory.CreateClient();
HttpResponseMessage registerResult = await client.PostAsJsonAsync("/api/account/register",
new { userName = "foo", password = "foo12345", email = "[email protected]" });
Assert.Equal(HttpStatusCode.BadRequest, registerResult.StatusCode);

registerResult = await client.PostAsJsonAsync("/api/account/register", new
{
userName = "foo",
password = "foo12345##Foo",
email = "[email protected]",
});
registerResult = await client.PostAsJsonAsync("/api/account/register",
new { userName = "foo", password = "foo12345##Foo", email = "[email protected]" });
Assert.True(registerResult.IsSuccessStatusCode);

var loginResult = await client.PostAsJsonAsync("/api/account/login", new
{
userName = "foo",
password = "foo12345##"
});
HttpResponseMessage loginResult =
await client.PostAsJsonAsync("/api/account/login", new { userName = "foo", password = "foo12345##" });
Assert.False(loginResult.IsSuccessStatusCode);

loginResult = await client.PostAsJsonAsync("/api/account/login", new
{
userName = "foo",
password = "foo12345##Foo"
});
loginResult =
await client.PostAsJsonAsync("/api/account/login", new { userName = "foo", password = "foo12345##Foo" });
Assert.True(loginResult.IsSuccessStatusCode);
}
}
}
12 changes: 7 additions & 5 deletions src/GZCTF.Test/ConfigServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GZCTF.Models.Internal;
using System.Collections.Generic;
using GZCTF.Models.Data;
using GZCTF.Models.Internal;
using GZCTF.Services;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -7,7 +9,7 @@ namespace GZCTF.Test;

public class ConfigServiceTest
{
private readonly ITestOutputHelper output;
readonly ITestOutputHelper output;

public ConfigServiceTest(ITestOutputHelper _output)
{
Expand All @@ -17,11 +19,11 @@ public ConfigServiceTest(ITestOutputHelper _output)
[Fact]
public void TestGetConfigs()
{
var configs = ConfigService.GetConfigs(new TestConfig());
HashSet<Config>? configs = ConfigService.GetConfigs(new TestConfig());
Assert.True(configs is not null);
Assert.True(configs.Count > 0);

foreach (var config in configs)
foreach (Config config in configs)
output.WriteLine($"{config.ConfigKey,-32}={config.Value}");
}
}
Expand All @@ -31,4 +33,4 @@ public class TestConfig
public AccountPolicy AccoutPolicy { get; set; } = new();
public DockerConfig DockerConfig { get; set; } = new();
public EmailConfig EmailConfig { get; set; } = new();
}
}
13 changes: 3 additions & 10 deletions src/GZCTF.Test/ContainerServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GZCTF.Models.Internal;
using GZCTF.Services.Interface;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;

namespace GZCTF.Test;

public class ContainerServiceTest : IClassFixture<TestWebAppFactory>
{
private readonly TestWebAppFactory factory;
private readonly ITestOutputHelper output;
readonly TestWebAppFactory factory;
readonly ITestOutputHelper output;

public ContainerServiceTest(ITestOutputHelper _output, TestWebAppFactory _factory)
{
Expand Down Expand Up @@ -81,4 +74,4 @@ public ContainerServiceTest(ITestOutputHelper _output, TestWebAppFactory _factor

// output.WriteLine($"[{DateTime.Now:u}] Container destoryed.");
//}
}
}
76 changes: 38 additions & 38 deletions src/GZCTF.Test/GZCTF.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<CollectCoverage>true</CollectCoverage>
<Configurations>Debug;Release;GenAPI</Configurations>
<ReleaseVersion>0.17.1</ReleaseVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<CollectCoverage>true</CollectCoverage>
<Configurations>Debug;Release;GenAPI</Configurations>
<ReleaseVersion>0.17.1</ReleaseVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.console" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.10"/>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.10"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.console" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GZCTF\GZCTF.csproj" />
<None Include="..\GZCTF\appsettings*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GZCTF\GZCTF.csproj"/>
<None Include="..\GZCTF\appsettings*"/>
</ItemGroup>

</Project>
Loading

0 comments on commit 3465436

Please sign in to comment.