Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 119 additions & 25 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,52 +1,146 @@
# Top-most EditorConfig file
root = true

# All files
[*]
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# C# files
[*.cs]
# Use string interpolation
dotnet_diagnostic.CA1305.severity = warning
# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Use implicit typing for local variables when obvious
csharp_style_var_when_type_is_apparent = true:suggestion
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = no_change

# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Write only one statement per line
# Wrapping preferences
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = false
csharp_preserve_single_line_blocks = true

# Expression-level preferences
csharp_prefer_braces = true:warning
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Language rules
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Interface names start with I
# Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.private_fields_should_be_underscore_camel_case.severity = suggestion
dotnet_naming_rule.private_fields_should_be_underscore_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_underscore_camel_case.style = underscore_camel_case

# Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.required_modifiers =

# Use PascalCase for constant names
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
# Naming styles
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.constant_style.capitalization = pascal_case
dotnet_naming_style.underscore_camel_case.required_prefix = _
dotnet_naming_style.underscore_camel_case.required_suffix =
dotnet_naming_style.underscore_camel_case.word_separator =
dotnet_naming_style.underscore_camel_case.capitalization = camel_case

# Private instance fields start with an underscore
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion
# Code style rules
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
# Code analysis rules
dotnet_diagnostic.CA1062.severity = warning # Validate arguments of public methods
dotnet_diagnostic.CA1063.severity = warning # Implement IDisposable correctly
dotnet_diagnostic.CA2007.severity = warning # Do not directly await a Task
dotnet_diagnostic.CA2008.severity = warning # Do not create tasks without passing a TaskScheduler
dotnet_diagnostic.CA2234.severity = warning # Pass System.Uri objects instead of strings

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _
# Custom rules based on requirements
dotnet_style_prefer_string_interpolation = true:warning # Use string interpolation to concatenate short strings
dotnet_style_predefined_type_for_locals_parameters_members = true:warning # Use implicit typing for local variables when type is obvious
csharp_style_var_when_type_is_apparent = true:warning
dotnet_diagnostic.IDE0007.severity = warning # Use var instead of explicit type
dotnet_diagnostic.IDE0008.severity = warning # Use explicit type instead of var
csharp_preserve_single_line_statements = false:warning # Write only one statement per line
csharp_preserve_single_line_blocks = false:warning # Write only one declaration per line
csharp_style_expression_bodied_methods = false:silent # Add at least one blank line between method definitions and property definitions
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning # Use parentheses to make clauses in an expression apparent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = always_for_clarity:warning
dotnet_diagnostic.IDE0010.severity = error # Add missing cases to switch statement (to discourage use of switch)
dotnet_diagnostic.IDE0011.severity = error # Add braces
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning # Specify accessibility modifiers
dotnet_style_readonly_field = true:warning # Make fields readonly when possible
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning # Prefer a specific order for modifiers
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Description
<!-- Please include a summary of the changes and the related issue. Include any additional context or dependencies here. -->

## Related PBI
<!-- Add the link to the related PBI here -->
[PBI-12345](https://yourtracker.com/path-to-pbi)

34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: .NET CI

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop", "main" ]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore

- name: Check code formatting
run: dotnet format --verify-no-changes --verbosity detailed

- name: Build
run: dotnet build --no-restore

- name: Run tests and check coverage
run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Threshold=50 /p:Exclude="[Pepsi.API]*"

- name: Run .NET Code Analysis
run: dotnet build /p:EnforceCodeStyleInBuild=true /p:AnalysisMode=All /p:TreatWarningsAsErrors=true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## files generated by popular Visual Studio add-ons.
##
## Get latest from `dotnet new gitignore`

.vscode
.idea
# dotenv files
.env

Expand Down
32 changes: 32 additions & 0 deletions Pepsi.API/Data/Vehicles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"Id": 1,
"VehicleType": "truck",
"Capacity": 10000
},
{
"Id": 2,
"VehicleType": "van",
"Capacity": 3000
},
{
"Id": 3,
"VehicleType": "truck",
"Capacity": 7500
},
{
"Id": 4,
"VehicleType": "van",
"Capacity": 3500
},
{
"Id": 5,
"VehicleType": "truck",
"Capacity": 9000
},
{
"Id": 6,
"VehicleType": "van",
"Capacity": 2500
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>All</AnalysisMode>
<CoverletOutputExclude>true</CoverletOutputExclude>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Pepsi.Application\Pepsi.Application.csproj" />
<ProjectReference Include="..\Pepsi.Infrastructure\Pepsi.Infrastructure.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Pepsi.API/Pepsi.API.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Pepsi.API_HostAddress = http://localhost:5225

GET {{Pepsi.API_HostAddress}}/weatherforecast/
Accept: application/json

###
26 changes: 26 additions & 0 deletions Pepsi.API/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

using Pepsi.Infrastructure.Utils;
using System.Diagnostics.CodeAnalysis;




var builder = WebApplication.CreateBuilder(args);

builder.Services.AddScoped<IDatabaseHelper, DatabaseHelper>();

builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true);

var app = builder.Build();

var vehicles = FileReader.ReadVehiclesFromJson();
Console.WriteLine(vehicles!.Count);

app.MapGet("/check-connection", (IDatabaseHelper dbHelper) =>
{
var isConnected = dbHelper.CheckConnection();
return isConnected ? Results.Ok("Database connection is successful!") : Results.StatusCode(500);
});

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22897",
"sslPort": 44326
"applicationUrl": "http://localhost:62862",
"sslPort": 44300
}
},
"profiles": {
Expand All @@ -14,7 +14,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5272",
"applicationUrl": "http://localhost:5225",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -24,7 +24,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7150;http://localhost:5272",
"applicationUrl": "https://localhost:7194;http://localhost:5225",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
11 changes: 11 additions & 0 deletions Pepsi.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
},
"ConnectionStrings": {
"PostgresConnection": "Host=localhost;Port=5432;Database=pepsi;Username=postgres;Password=postgres"
}
}
}
13 changes: 13 additions & 0 deletions Pepsi.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"PostgresConnection": "Host=localhost;Port=5432;Database=pepsi;Username=postgres;Password=postgres"
},

"AllowedHosts": "*"
}
6 changes: 6 additions & 0 deletions Pepsi.Core/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Pepsi.Core;

public class Class1
{

}
9 changes: 9 additions & 0 deletions Pepsi.Core/Entity/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Pepsi.Core.Entity;

public class Client(int id, string name, string address, string region)
{
public int Id { get; init; } = id;
public string Name { get; init; } = name;
public string Address { get; init; } = address;
public string Region { get; init; } = region;
}
Loading