Skip to content

Commit

Permalink
Update Project to Standards (#5)
Browse files Browse the repository at this point in the history
* #109 Updated project settings, added NRT changes, all tests pass

* Updated example app in .NET Core 3.1, now needs to update to .NET 6

* Upgraded/changed the example project to .NET 6

* Updated NuGet package references

* Updated .editorconfig settings and Authors value

Co-authored-by: Jason Bock <jasonbock1@rocketmortgage.com>
  • Loading branch information
JasonBock and Jason Bock authored Feb 8, 2022
1 parent 67de9ec commit 14dd92b
Show file tree
Hide file tree
Showing 26 changed files with 364 additions and 346 deletions.
69 changes: 69 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
root = true

[*]
end_of_line = lf

[*.cs]
# Styling
indent_style = space
indent_size = 4
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = methods, control_blocks, types, properties, lambdas, accessors, object_collection_array_initializers
csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = false:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_preferred_modifier_order = public,private,internal,protected,static,readonly,async,override,sealed:suggestion
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_constructors = false:suggestion
csharp_style_expression_bodied_methods = false:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
dotnet_sort_system_directives_first = false
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_object_initializer = true:suggestion
csharp_style_pattern_local_over_anonymous_function = false:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion


# Analyzer Configuration
# These are rules we want to either ignore or have set as suggestion or info

# CA1014: Mark assemblies with CLSCompliant
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1014
dotnet_diagnostic.CA1014.severity = none

# CA1725: Parameter names should match base declaration
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1725
dotnet_diagnostic.CA1725.severity = suggestion

# CA2227: Collection properties should be read only
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2227
dotnet_diagnostic.CA2227.severity = suggestion
20 changes: 20 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'netcoreapp3.1'">
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
<PropertyGroup>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<Authors>Rocket Mortgage</Authors>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;netcoreapp3.1;net48</TargetFrameworks>
<NoWarn>NU1603,NU1701</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions Examples/Middleware.NET60/Middleware.NET60.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RockLib.DistributedTracing.AspNetCore\RockLib.DistributedTracing.AspNetCore.csproj" />
</ItemGroup>
</Project>
29 changes: 29 additions & 0 deletions Examples/Middleware.NET60/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Builder;
using Middleware.NET60;
using RockLib.DistributedTracing.AspNetCore;
using System;
using System.Linq;
using System.Security.Cryptography;

#pragma warning disable CA1812

var builder = WebApplication.CreateBuilder(args);

// Use this to change the name of the correlation id header
//builder.Services.Configure<CorrelationIdMiddlewareOptions>(options => options.HeaderName = "Custom-Id-Header");

var app = builder.Build();

app.UseCorrelationIdMiddleware();

app.MapGet("/", () =>
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = RandomNumberGenerator.GetInt32(-20, 55),
Summary = WeatherForecast.Summaries[RandomNumberGenerator.GetInt32(WeatherForecast.Summaries.Length)]
}).ToArray();
});

app.Run();
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54778",
"sslPort": 44359
"applicationUrl": "http://localhost:2930",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"Middleware.NET60": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5008",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Middleware.netcoreapp3._1": {
"commandName": "Project",
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
19 changes: 19 additions & 0 deletions Examples/Middleware.NET60/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Middleware.NET60;

public sealed class WeatherForecast
{
public static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public DateTime Date { get; init; }

public int TemperatureC { get; init; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; init; }
}
8 changes: 8 additions & 0 deletions Examples/Middleware.NET60/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions Examples/Middleware.netcoreapp3.1/Middleware.netcoreapp3.1.csproj

This file was deleted.

20 changes: 0 additions & 20 deletions Examples/Middleware.netcoreapp3.1/Program.cs

This file was deleted.

51 changes: 0 additions & 51 deletions Examples/Middleware.netcoreapp3.1/Startup.cs

This file was deleted.

15 changes: 0 additions & 15 deletions Examples/Middleware.netcoreapp3.1/WeatherForecast.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xunit;

[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public void GetCorrelationIdAccessor3()
[Fact(DisplayName = "GetCorrelationIdAccessor throws on null context")]
public void GetCorrelationIdAccessorSadPath()
{
HttpContext context = null;
HttpContext context = null!;

Action action = () => context.GetCorrelationIdAccessor();
Action action = () => context!.GetCorrelationIdAccessor();

action.Should().Throw<ArgumentNullException>();
}
Expand Down
Loading

0 comments on commit 14dd92b

Please sign in to comment.