Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasteles committed Jul 6, 2023
1 parent 9919007 commit d85a7a2
Show file tree
Hide file tree
Showing 15 changed files with 963 additions and 201 deletions.
108 changes: 63 additions & 45 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
root = true

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

# XML project files
[*.{csproj,fsproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
Expand All @@ -17,24 +17,26 @@ indent_size = 2
indent_size = 2

[*.{cs,csx}]
# Organize usings
max_line_length = 120
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = omit_if_default:warning
dotnet_style_readonly_field = true:suggestion

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
Expand All @@ -50,33 +52,31 @@ dotnet_style_prefer_conditional_expression_over_return = true:silent

# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_style.camel_case_style.capitalization = camel_case

dotnet_naming_style.camel_case_style.capitalization = camel_case

# constant case preferences
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

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

# fields case preferences
dotnet_naming_symbols.private_field_symbols.applicable_kinds = field
dotnet_naming_symbols.private_field_symbols.applicable_accessibilities = private

dotnet_naming_rule.private_field_symbols_should_be_camel_case.symbols = private_field_symbols
dotnet_naming_rule.private_field_symbols_should_be_camel_case.severity = warning
dotnet_naming_rule.private_field_symbols_should_be_camel_case.style = camel_case_style

# protected fields
dotnet_naming_symbols.protected_field_symbols.applicable_kinds = field
dotnet_naming_symbols.protected_field_symbols.applicable_kinds = field, property
dotnet_naming_symbols.protected_field_symbols.applicable_accessibilities = protected
dotnet_naming_rule.protected_field_symbols_should_be_camel_case.symbols = protected_field_symbols
dotnet_naming_rule.protected_field_symbols_should_be_camel_case.severity = warning
dotnet_naming_rule.protected_field_symbols_should_be_camel_case.severity = suggestion
dotnet_naming_rule.protected_field_symbols_should_be_camel_case.style = camel_case_style

[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
Expand All @@ -95,13 +95,16 @@ csharp_style_expression_bodied_local_functions = true:suggestion
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion

# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:suggestion

# Expression-level preferences
csharp_prefer_braces = when_multiline:suggestion
csharp_prefer_braces = false
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
Expand All @@ -119,6 +122,7 @@ csharp_new_line_between_query_expression_clauses = true
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
Expand All @@ -135,27 +139,41 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

# Analysers
## dotnet
dotnet_diagnostic.IDE0011.severity = suggestion # require braces
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary.
dotnet_diagnostic.CA1860.severity = silent # Prefer comparing 'Length' to 0 rather than using 'Any()'

## Sonar
dotnet_diagnostic.S1481.severity = warning # variable never used
dotnet_diagnostic.S1144.severity = suggestion # Remove the unused private constructor 'AddAuthorizationHeaderOperationFilter'.
dotnet_diagnostic.S1118.severity = suggestion # Add a 'protected' constructor or the 'static' keyword to the class declaration.
dotnet_diagnostic.S1075.severity = suggestion # hardcoded URIs
dotnet_diagnostic.S3459.severity = suggestion # Unassigned members should be removed
dotnet_diagnostic.S2699.severity = suggestion # add assert to test
dotnet_diagnostic.S3237.severity = silent # Use the 'value' contextual keyword in this property set accessor declaration.
dotnet_diagnostic.S1210.severity = silent # When implementing IComparable , you should also override , =, >, and >=.
dotnet_diagnostic.S2219.severity = silent # runtime type checking should be simplified
dotnet_diagnostic.S2094.severity = silent # empty class (false positive)


## AsyncFixer
dotnet_diagnostic.AsyncFixer01.severity = suggestion # The method dont needs async

# Roslynator
dotnet_analyzer_diagnostic.category-roslynator.severity = default
roslynator_analyzers.enabled_by_default = true
roslynator_refactorings.enabled = true
roslynator_compiler_diagnostic_fixes.enabled = true
# Nunit
dotnet_diagnostic.NUnit1027.severity = suggestion # parameter error nunit

dotnet_diagnostic.RCS1214.severity = warning
dotnet_diagnostic.RCS1036.severity = warning
dotnet_diagnostic.S3881.severity = suggestion
dotnet_diagnostic.IDE0011.severity = silent
dotnet_diagnostic.RCS1001.severity = silent
dotnet_diagnostic.RCS1194.severity = silent
dotnet_diagnostic.RCS1163.severity = silent
dotnet_diagnostic.RCS1118.severity = silent
dotnet_diagnostic.CA1050.severity = silent
dotnet_diagnostic.S3925.severity = silent
# Resharper
resharper_space_within_single_line_array_initializer_braces = true
resharper_keep_existing_attribute_arrangement = true
resharper_max_array_initializer_elements_on_line = 10
resharper_max_initializer_elements_on_line = 1
resharper_trailing_comma_in_multiline_lists = true
resharper_wrap_array_initializer_style = chop_if_long
resharper_empty_block_style = together_same_line

[Usings.cs]
dotnet_diagnostic.IDE0005.severity = silent # Using directive is unnecessary.

# Nunit
dotnet_diagnostic.NUnit1027.severity = silent
dotnet_diagnostic.S3903.severity = silent
dotnet_diagnostic.AsyncFixer05.severity = silent
dotnet_diagnostic.S3973.severity = silent
6 changes: 2 additions & 4 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
"Lint",
"Report",
"Restore",
"Test",
"TestCoverage"
"Test"
]
}
},
Expand All @@ -115,8 +114,7 @@
"Lint",
"Report",
"Restore",
"Test",
"TestCoverage"
"Test"
]
}
},
Expand Down
24 changes: 7 additions & 17 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class BuildProject : NukeBuild
{
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
readonly Configuration Configuration =
IsLocalBuild ? Configuration.Debug : Configuration.Release;

[Parameter(List = false)] readonly bool DotnetRunningInContainer;
[GlobalJson] readonly GlobalJson GlobalJson;
Expand Down Expand Up @@ -39,18 +40,6 @@ class BuildProject : NukeBuild
.EnableNoRestore()));

Target Test => _ => _
.Description("Run all tests")
.DependsOn(Build)
.Executes(() => Solution
.GetProjects("*.Tests")
.ForEach(project =>
DotNetTest(s => s
.EnableNoBuild()
.EnableNoRestore()
.SetConfiguration(Configuration)
.SetProjectFile(project))));

Target TestCoverage => _ => _
.Description("Run tests with coverage")
.DependsOn(Build)
.Executes(() => DotNetTest(s => s
Expand All @@ -74,7 +63,8 @@ class BuildProject : NukeBuild
Target Lint => _ => _
.Description("Check for codebase formatting and analysers")
.DependsOn(Build)
.Executes(() => DotNet($"format -v normal --no-restore --verify-no-changes \"{Solution.Path}\""));
.Executes(() =>
DotNet($"format -v normal --no-restore --verify-no-changes \"{Solution.Path}\""));

Target Format => _ => _
.Description("Try fix codebase formatting and analysers")
Expand All @@ -83,12 +73,12 @@ class BuildProject : NukeBuild

Target Report => _ => _
.Description("Run tests and generate coverage report")
.DependsOn(TestCoverage)
.DependsOn(Test)
.Triggers(GenerateReport, BrowseReport);

Target GenerateReport => _ => _
.Description("Generate test coverage report")
.After(TestCoverage)
.After(Test)
.OnlyWhenDynamic(() => CoverageFiles.GlobFiles().Any())
.Executes(() =>
ReportGenerator(r => r
Expand Down Expand Up @@ -124,7 +114,7 @@ class BuildProject : NukeBuild

Target GenerateBadges => _ => _
.Description("Generate cool badges for readme")
.After(TestCoverage)
.After(Test)
.Requires(() => CoverageFiles.GlobFiles().Any())
.Executes(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions src/Json/ResultJsonTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public override Result<TOk, TError> Read(
Utf8JsonReader valueReader = new(JsonSerializer.SerializeToUtf8Bytes(value));
valueReader.Read();
if (status.GetString() == statusOk)
return new Result<TOk, TError>(
return new(
okConverter.Read(ref valueReader, okType, options)!);

if (status.GetString() == statusError)
return new Result<TOk, TError>(
return new(
errorConverter.Read(ref valueReader, errorType, options)!);

throw new JsonException($"Invalid status {status}");
Expand Down
19 changes: 12 additions & 7 deletions src/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace Resulteles;

/// <summary>
/// Represents an successful operation
/// </summary>
public readonly record struct Success;

/// <summary>
/// Helper type for errorValue handling without exceptions.
/// </summary>
Expand Down Expand Up @@ -40,8 +45,8 @@ namespace Resulteles;
public Result(TOk okValue)
{
IsOk = true;
this.OkValue = okValue;
this.ErrorValue = default;
OkValue = okValue;
ErrorValue = default;
}

/// <summary>
Expand All @@ -50,8 +55,8 @@ public Result(TOk okValue)
public Result(TError error)
{
IsOk = false;
this.OkValue = default;
this.ErrorValue = error;
OkValue = default;
ErrorValue = error;
}

/// <summary>
Expand Down Expand Up @@ -125,16 +130,16 @@ public bool Equals(Result<TOk, TError> other) =>
/// Match the result to obtain the value
/// </summary>
public T Match<T>(Func<TOk, T> ok, Func<TError, T> error) =>
IsOk ? ok(this.OkValue) : error(this.ErrorValue);
IsOk ? ok(OkValue) : error(ErrorValue);

/// <summary>
/// Switch the result to process value
/// </summary>
public void Switch(Action<TOk> ok, Action<TError> error)
{
if (IsOk)
ok(this.OkValue);
ok(OkValue);
else
error(this.ErrorValue);
error(ErrorValue);
}
}
Loading

0 comments on commit d85a7a2

Please sign in to comment.