diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..67fed2a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,75 @@ +root = true + +[*] +end_of_line = crlf +indent_style = tab +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.cs] +indent_size = 4 +dotnet_sort_system_directives_first = false +dotnet_style_coalesce_expression = true : warning +dotnet_style_collection_initializer = true : warning +dotnet_style_explicit_tuple_names = true : warning +dotnet_style_null_propagation = true : warning +dotnet_style_object_initializer = true : warning +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity : warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : warning +dotnet_style_parentheses_in_other_operators = always_for_clarity : warning +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity : warning +dotnet_style_predefined_type_for_locals_parameters_members = true : error +dotnet_style_predefined_type_for_member_access = true : error +dotnet_style_prefer_auto_properties = true : error +dotnet_style_prefer_conditional_expression_over_assignment = true +dotnet_style_prefer_conditional_expression_over_return = true +dotnet_style_prefer_inferred_anonymous_type_member_names = true : warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true : warning +dotnet_style_qualification_for_event = false : none +dotnet_style_qualification_for_field = false : none +dotnet_style_qualification_for_method = false : none +dotnet_style_qualification_for_property = false : none +dotnet_style_readonly_field = true : warning +dotnet_style_require_accessibility_modifiers = always : warning +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = 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 = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true +csharp_prefer_braces = true : silent +csharp_prefer_simple_default_expression = true : warning +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_around_binary_operators = before_and_after +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_space_between_parentheses = false +csharp_style_conditional_delegate_call = true : warning +csharp_style_deconstructed_variable_declaration = true : warning +csharp_style_expression_bodied_accessors = when_on_single_line : suggestion +csharp_style_expression_bodied_constructors = false : none +csharp_style_expression_bodied_indexers = when_on_single_line : suggestion +csharp_style_expression_bodied_methods = false : none +csharp_style_expression_bodied_operators = when_on_single_line : suggestion +csharp_style_expression_bodied_properties = when_on_single_line : suggestion +csharp_style_inlined_variable_declaration = true : warning +csharp_style_pattern_local_over_anonymous_function = true : warning +csharp_style_pattern_matching_over_as_with_null_check = true : warning +csharp_style_pattern_matching_over_is_with_cast_check = true : warning +csharp_style_throw_expression = true : warning +csharp_style_var_elsewhere = true : warning +csharp_style_var_for_built_in_types = true : warning +csharp_style_var_when_type_is_apparent = true : warning diff --git a/.simpleversion.json b/.simpleversion.json index d3c5e8d..13873b0 100644 --- a/.simpleversion.json +++ b/.simpleversion.json @@ -1,22 +1,22 @@ { - "version": "0.2.0", - "label": ["alpha1"], - "branches": { - "release": [ - "^refs/heads/master$", - "^refs/heads/preview/.+$", - "^refs/heads/release/.+$" - ], - "overrides": [ - { - "match": "^refs/heads/feature/.+$", - "metadata": [ "{shortbranchname}" ] - }, - { - "match": "^refs/heads/release/.+$", - "label": [], - "metadata": [ "*" ] - } - ] - } + "version": "0.2.0", + "label": [ "alpha1" ], + "branches": { + "release": [ + "^refs/heads/master$", + "^refs/heads/preview/.+$", + "^refs/heads/release/.+$" + ], + "overrides": [ + { + "match": "^refs/heads/feature/.+$", + "metadata": [ "{shortbranchname}" ] + }, + { + "match": "^refs/heads/release/.+$", + "label": [], + "metadata": [ "*" ] + } + ] + } } \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 294567b..133e514 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,46 +1,46 @@ - - 1.0.0 - $(Version) - $([System.Text.RegularExpressions.Regex]::Match($(Version), '\d+\.\d+\.\d+').Value) - + + 1.0.0 + $(Version) + $([System.Text.RegularExpressions.Regex]::Match($(Version), '\d+\.\d+\.\d+').Value) + - - net461 - + + net461 + - - - Kieranties - (c) Kieranties - SimpleVersion - A simple tool to version your code - $(MajorMinorPatchVersion).0 - $([System.Text.RegularExpressions.Regex]::Match($(Version), '\d+\.\d+').Value).0.0 - $(Version)$(VersionSuffix) - + + + Kieranties + (c) Kieranties + SimpleVersion - A simple tool to version your code + $(MajorMinorPatchVersion).0 + $([System.Text.RegularExpressions.Regex]::Match($(Version), '\d+\.\d+').Value).0.0 + $(Version)$(VersionSuffix) + - - Kieran@Kieranties.com - https://github.com/Kieranties/SimpleVersion - semver;versioning;git - https://github.com/Kieranties/SimpleVersion - git - https://raw.github.com/Kieranties/SimpleVersion/master/docs/img/logo.png - MIT - + + Kieran@Kieranties.com + https://github.com/Kieranties/SimpleVersion + semver;versioning;git + https://github.com/Kieranties/SimpleVersion + git + https://raw.github.com/Kieranties/SimpleVersion/master/docs/img/logo.png + MIT + - - true - true - - $(NoWarn);NU5105 - + + true + true + + $(NoWarn);NU5105 + - - - + + + - - $(MSBuildThisFileDirectory)shared/SimpleVersion.ruleset - + + $(MSBuildThisFileDirectory)shared/SimpleVersion.ruleset + \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index 1e416b0..e71bb65 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,22 +1,22 @@ - - - $(GenerateNuspecDependsOn);SetReleaseNotes - - - - - - - - - - - - - - @(ReleaseNotes->'%(Identity)', '%0a') - - + + $(GenerateNuspecDependsOn);SetReleaseNotes + + + + + + + + + + + + + + @(ReleaseNotes->'%(Identity)', '%0a') + + + \ No newline at end of file diff --git a/Packages.props b/Packages.props index c846132..fa32cdb 100644 --- a/Packages.props +++ b/Packages.props @@ -1,33 +1,33 @@ - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/SimpleVersion.sln b/SimpleVersion.sln index ba4e0c3..87eb16a 100644 --- a/SimpleVersion.sln +++ b/SimpleVersion.sln @@ -5,6 +5,7 @@ VisualStudioVersion = 16.0.28729.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D5992CB5-3542-41C8-BE85-F52699729C57}" ProjectSection(SolutionItems) = preProject + src\App.props = src\App.props src\Directory.Build.props = src\Directory.Build.props EndProjectSection EndProject @@ -19,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9EEF54AE-E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0F190AA6-731C-425E-894B-F4A63A86200A}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig .gitignore = .gitignore .simpleversion.json = .simpleversion.json azure-pipelines.yml = azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7bc5efa..36bf816 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -101,4 +101,4 @@ jobs: packagesToPush: $(DistDir)/**/*.nupkg nuGetFeedType: internal publishVstsFeed: SimpleVersion - feedsToUse: nuget.config + feedsToUse: nuget.config \ No newline at end of file diff --git a/global.json b/global.json index 2a1bab3..746fa4e 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { - "msbuild-sdks": { - "Microsoft.Build.CentralPackageVersions": "2.0.26" - } + "msbuild-sdks": { + "Microsoft.Build.CentralPackageVersions": "2.0.26" + } } \ No newline at end of file diff --git a/nuget.config b/nuget.config index eac1650..6f60b4b 100644 --- a/nuget.config +++ b/nuget.config @@ -1,10 +1,10 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/shared/Tests.GlobalSuppressions.cs b/shared/Tests.GlobalSuppressions.cs index 811f2ed..cb62fe8 100644 --- a/shared/Tests.GlobalSuppressions.cs +++ b/shared/Tests.GlobalSuppressions.cs @@ -1,6 +1,6 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( - "Naming", - "CA1707:Identifiers should not contain underscores", - Justification = "Use underscores for readability in tests")] + "Naming", + "CA1707:Identifiers should not contain underscores", + Justification = "Use underscores for readability in tests")] \ No newline at end of file diff --git a/shared/stylecop.json b/shared/stylecop.json index 58f69bb..e1e19d1 100644 --- a/shared/stylecop.json +++ b/shared/stylecop.json @@ -1,14 +1,14 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "Kieranties", - "copyrightText": "Licensed under the {licenseName} license. See {licenseUri} for full license information.", - "xmlHeader": false, - "variables": { - "licenseName": "MIT", - "licenseUri": "https://kieranties.mit-license.org/" - } - } - } -} +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "Kieranties", + "copyrightText": "Licensed under the {licenseName} license. See {licenseUri} for full license information.", + "xmlHeader": false, + "variables": { + "licenseName": "MIT", + "licenseUri": "https://kieranties.mit-license.org/" + } + } + } +} \ No newline at end of file diff --git a/src/App.props b/src/App.props index 3c353fd..96b26e7 100644 --- a/src/App.props +++ b/src/App.props @@ -1,28 +1,28 @@ - - - + + + - - - + + + - - - False - False + + + False + False - + - - True - - None - False - - None - + + True + + None + False + + None + - \ No newline at end of file + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 19cfeea..02cca55 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,9 +1,9 @@ - - - - true - - + + + + + + diff --git a/src/SimpleVersion.Abstractions/Constants.cs b/src/SimpleVersion.Abstractions/Constants.cs index 260b3ab..5a9245d 100644 --- a/src/SimpleVersion.Abstractions/Constants.cs +++ b/src/SimpleVersion.Abstractions/Constants.cs @@ -1,9 +1,9 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. namespace SimpleVersion { - public static class Constants - { - public const string VersionFileName = ".simpleversion.json"; - } + public static class Constants + { + public const string VersionFileName = ".simpleversion.json"; + } } diff --git a/src/SimpleVersion.Abstractions/IEnvironment.cs b/src/SimpleVersion.Abstractions/IEnvironment.cs index 330d82c..48f5ba4 100644 --- a/src/SimpleVersion.Abstractions/IEnvironment.cs +++ b/src/SimpleVersion.Abstractions/IEnvironment.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Collections.Generic; @@ -8,8 +8,8 @@ namespace SimpleVersion { - public interface IEnvironment - { - string GetVariable(string name); - } + public interface IEnvironment + { + string GetVariable(string name); + } } diff --git a/src/SimpleVersion.Abstractions/Model/BranchConfiguration.cs b/src/SimpleVersion.Abstractions/Model/BranchConfiguration.cs index 03ad311..efbb10c 100644 --- a/src/SimpleVersion.Abstractions/Model/BranchConfiguration.cs +++ b/src/SimpleVersion.Abstractions/Model/BranchConfiguration.cs @@ -1,17 +1,17 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System.Collections.Generic; namespace SimpleVersion.Model { - public class BranchConfiguration - { - public string Match { get; set; } = string.Empty; + public class BranchConfiguration + { + public string Match { get; set; } = string.Empty; #pragma warning disable CA2227 // Collection properties should be read only - public List Label { get; set; } = null; + public List Label { get; set; } = null; - public List MetaData { get; set; } = null; + public List MetaData { get; set; } = null; #pragma warning restore CA2227 // Collection properties should be read only - } -} + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Model/BranchInfo.cs b/src/SimpleVersion.Abstractions/Model/BranchInfo.cs index 9612297..98f95e7 100644 --- a/src/SimpleVersion.Abstractions/Model/BranchInfo.cs +++ b/src/SimpleVersion.Abstractions/Model/BranchInfo.cs @@ -1,14 +1,14 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Collections.Generic; namespace SimpleVersion.Model { - public class BranchInfo - { - public List Release { get; } = new List(); + public class BranchInfo + { + public List Release { get; } = new List(); - public List Overrides { get; } = new List(); - } -} + public List Overrides { get; } = new List(); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Model/Configuration.cs b/src/SimpleVersion.Abstractions/Model/Configuration.cs index fa1f517..06fd039 100644 --- a/src/SimpleVersion.Abstractions/Model/Configuration.cs +++ b/src/SimpleVersion.Abstractions/Model/Configuration.cs @@ -1,21 +1,21 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System.Collections.Generic; namespace SimpleVersion.Model { #pragma warning disable CA1724 - public class Configuration + public class Configuration #pragma warning restore CA1724 - { - public string Version { get; set; } = string.Empty; + { + public string Version { get; set; } = string.Empty; - public int OffSet { get; set; } = 0; + public int OffSet { get; set; } = 0; - public List Label { get; } = new List(); + public List Label { get; } = new List(); - public List MetaData { get; } = new List(); + public List MetaData { get; } = new List(); - public BranchInfo Branches { get; set; } = new BranchInfo(); - } -} + public BranchInfo Branches { get; set; } = new BranchInfo(); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Model/LabelConfiguration.cs b/src/SimpleVersion.Abstractions/Model/LabelConfiguration.cs index 5e9af49..eef90d1 100644 --- a/src/SimpleVersion.Abstractions/Model/LabelConfiguration.cs +++ b/src/SimpleVersion.Abstractions/Model/LabelConfiguration.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Collections.Generic; @@ -8,8 +8,8 @@ namespace SimpleVersion.Model { - public class LabelConfiguration - { - public List Label { get; } = new List(); - } -} + public class LabelConfiguration + { + public List Label { get; } = new List(); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Model/VersionResult.cs b/src/SimpleVersion.Abstractions/Model/VersionResult.cs index 253261c..362500a 100644 --- a/src/SimpleVersion.Abstractions/Model/VersionResult.cs +++ b/src/SimpleVersion.Abstractions/Model/VersionResult.cs @@ -1,31 +1,31 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System.Collections.Generic; namespace SimpleVersion.Model { - public class VersionResult - { - public string Version { get; set; } = string.Empty; + public class VersionResult + { + public string Version { get; set; } = string.Empty; - public int Major { get; set; } = 0; + public int Major { get; set; } = 0; - public int Minor { get; set; } = 0; + public int Minor { get; set; } = 0; - public int Patch { get; set; } = 0; + public int Patch { get; set; } = 0; - public int Revision { get; set; } = 0; + public int Revision { get; set; } = 0; - public int Height { get; set; } = 0; + public int Height { get; set; } = 0; - public string HeightPadded => Height.ToString("D4", System.Globalization.CultureInfo.CurrentCulture); + public string HeightPadded => Height.ToString("D4", System.Globalization.CultureInfo.CurrentCulture); - public string Sha { get; set; } = string.Empty; + public string Sha { get; set; } = string.Empty; - public string BranchName { get; set; } = string.Empty; + public string BranchName { get; set; } = string.Empty; - public string CanonicalBranchName { get; set; } = string.Empty; + public string CanonicalBranchName { get; set; } = string.Empty; - public IDictionary Formats { get; } = new Dictionary(System.StringComparer.OrdinalIgnoreCase); - } -} + public IDictionary Formats { get; } = new Dictionary(System.StringComparer.OrdinalIgnoreCase); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Pipeline/ICalculatorProcess.cs b/src/SimpleVersion.Abstractions/Pipeline/ICalculatorProcess.cs index 07064a1..4156447 100644 --- a/src/SimpleVersion.Abstractions/Pipeline/ICalculatorProcess.cs +++ b/src/SimpleVersion.Abstractions/Pipeline/ICalculatorProcess.cs @@ -1,9 +1,9 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. namespace SimpleVersion.Pipeline { - public interface ICalculatorProcess - { - void Apply(VersionContext context); - } -} + public interface ICalculatorProcess + { + void Apply(VersionContext context); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Pipeline/IVersionCalculator.cs b/src/SimpleVersion.Abstractions/Pipeline/IVersionCalculator.cs index c159dad..3a93d1b 100644 --- a/src/SimpleVersion.Abstractions/Pipeline/IVersionCalculator.cs +++ b/src/SimpleVersion.Abstractions/Pipeline/IVersionCalculator.cs @@ -1,13 +1,13 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Model; namespace SimpleVersion.Pipeline { - public interface IVersionCalculator - { - IVersionCalculator AddProcessor() where T : ICalculatorProcess, new(); + public interface IVersionCalculator + { + IVersionCalculator AddProcessor() where T : ICalculatorProcess, new(); - VersionResult GetResult(string path); - } -} + VersionResult GetResult(string path); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Pipeline/VersionContext.cs b/src/SimpleVersion.Abstractions/Pipeline/VersionContext.cs index 45673b4..b05f764 100644 --- a/src/SimpleVersion.Abstractions/Pipeline/VersionContext.cs +++ b/src/SimpleVersion.Abstractions/Pipeline/VersionContext.cs @@ -1,17 +1,17 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Model; namespace SimpleVersion.Pipeline { - public class VersionContext - { - public string Path { get; set; } = string.Empty; + public class VersionContext + { + public string Path { get; set; } = string.Empty; - public string RepositoryPath { get; set; } = string.Empty; + public string RepositoryPath { get; set; } = string.Empty; - public Configuration Configuration { get; set; } = new Configuration(); + public Configuration Configuration { get; set; } = new Configuration(); - public VersionResult Result { get; set; } = new VersionResult(); - } + public VersionResult Result { get; set; } = new VersionResult(); + } } \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/Rules/IRule.cs b/src/SimpleVersion.Abstractions/Rules/IRule.cs index 044ee4a..41f1b85 100644 --- a/src/SimpleVersion.Abstractions/Rules/IRule.cs +++ b/src/SimpleVersion.Abstractions/Rules/IRule.cs @@ -1,16 +1,16 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System.Collections.Generic; namespace SimpleVersion.Rules { - public interface IRule - { - string Token { get; } + public interface IRule + { + string Token { get; } - T Resolve(VersionContext context, T value); + T Resolve(VersionContext context, T value); - IEnumerable Apply(VersionContext context, IEnumerable value); - } -} + IEnumerable Apply(VersionContext context, IEnumerable value); + } +} \ No newline at end of file diff --git a/src/SimpleVersion.Abstractions/SimpleVersion.Abstractions.csproj b/src/SimpleVersion.Abstractions/SimpleVersion.Abstractions.csproj index f196693..c6c51a4 100644 --- a/src/SimpleVersion.Abstractions/SimpleVersion.Abstractions.csproj +++ b/src/SimpleVersion.Abstractions/SimpleVersion.Abstractions.csproj @@ -1,8 +1,8 @@ - - + + - - SimpleVersion - + + SimpleVersion + - + \ No newline at end of file diff --git a/src/SimpleVersion.Cake/CakeAliases.cs b/src/SimpleVersion.Cake/CakeAliases.cs index eb73855..45bb345 100644 --- a/src/SimpleVersion.Cake/CakeAliases.cs +++ b/src/SimpleVersion.Cake/CakeAliases.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using Cake.Core; using Cake.Core.Annotations; @@ -7,19 +7,19 @@ namespace Cake.SimpleVersion { - public static class CakeAliases - { - [CakeMethodAlias] - public static VersionResult SimpleVersion( - this ICakeContext context, - string path = null) - { - if (string.IsNullOrWhiteSpace(path)) - path = context.Environment.WorkingDirectory.FullPath; + public static class CakeAliases + { + [CakeMethodAlias] + public static VersionResult SimpleVersion( + this ICakeContext context, + string path = null) + { + if (string.IsNullOrWhiteSpace(path)) + path = context.Environment.WorkingDirectory.FullPath; - return VersionCalculator - .Default() - .GetResult(path); - } - } + return VersionCalculator + .Default() + .GetResult(path); + } + } } diff --git a/src/SimpleVersion.Cake/SimpleVersion.Cake.csproj b/src/SimpleVersion.Cake/SimpleVersion.Cake.csproj index 4c0a9be..41abf8e 100644 --- a/src/SimpleVersion.Cake/SimpleVersion.Cake.csproj +++ b/src/SimpleVersion.Cake/SimpleVersion.Cake.csproj @@ -1,29 +1,29 @@ - - + + - + - - Cake.SimpleVersion - $(PackageTags);Cake - + + Cake.SimpleVersion + $(PackageTags);Cake + - - $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs - + + $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs + - - - + + + - - - + + - lib\$(TargetFramework)\ - - - + lib\$(TargetFramework)\ + + + diff --git a/src/SimpleVersion.Command/Program.cs b/src/SimpleVersion.Command/Program.cs index 1863308..4f99ec2 100644 --- a/src/SimpleVersion.Command/Program.cs +++ b/src/SimpleVersion.Command/Program.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using Newtonsoft.Json; using SimpleVersion.Pipeline; @@ -6,30 +6,32 @@ namespace SimpleVersion.Command { - public sealed class Program - { - public static int Main(string[] args) - { - var exitCode = 0; - try { - var path = System.IO.Directory.GetCurrentDirectory(); - if (args.Length > 0) - path = args[0]; + public sealed class Program + { + public static int Main(string[] args) + { + var exitCode = 0; + try + { + var path = System.IO.Directory.GetCurrentDirectory(); + if (args.Length > 0) + path = args[0]; - var result = VersionCalculator - .Default() - .GetResult(path); + var result = VersionCalculator + .Default() + .GetResult(path); - Console.Out.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); - } + Console.Out.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); + } #pragma warning disable CA1031 // Do not catch general exception types - catch (Exception ex) { - Console.Error.WriteLine($"[Error] {ex.Message}"); - exitCode = -1; - } + catch (Exception ex) + { + Console.Error.WriteLine($"[Error] {ex.Message}"); + exitCode = -1; + } #pragma warning restore CA1031 // Do not catch general exception types - return exitCode; - } - } + return exitCode; + } + } } diff --git a/src/SimpleVersion.Command/SimpleVersion.Command.csproj b/src/SimpleVersion.Command/SimpleVersion.Command.csproj index 8b22ca7..4c85506 100644 --- a/src/SimpleVersion.Command/SimpleVersion.Command.csproj +++ b/src/SimpleVersion.Command/SimpleVersion.Command.csproj @@ -1,24 +1,24 @@ - - + + - + - - Exe - SimpleVersion - + + Exe + SimpleVersion + - - $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs - SimpleVersion.Command - + + $(TargetsForTfmSpecificContentInPackage);PackBuildOutputs + SimpleVersion.Command + - - - + + - tools\ - - - + tools\ + + + diff --git a/src/SimpleVersion.Core/Comparers/ConfigurationVersionLabelComparer.cs b/src/SimpleVersion.Core/Comparers/ConfigurationVersionLabelComparer.cs index 2ee9371..f304d2a 100644 --- a/src/SimpleVersion.Core/Comparers/ConfigurationVersionLabelComparer.cs +++ b/src/SimpleVersion.Core/Comparers/ConfigurationVersionLabelComparer.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Model; using System; @@ -7,48 +7,45 @@ namespace SimpleVersion.Comparers { - public class ConfigurationVersionLabelComparer : IEqualityComparer - { - public bool Equals(Configuration x, Configuration y) - { - if (ReferenceEquals(x, y)) - return true; - - if (x == null && y != null) - return false; - - if (y == null && x != null) - return false; - - if(x.Version == y.Version) - { - if (x.Label != null) - { - return y.Label == null ? false : x.Label.SequenceEqual(y.Label); - } - else - { - return y.Label == null; - } - } - - return false; - } - - public int GetHashCode(Configuration configuration) - { - if(configuration is null) - throw new ArgumentNullException(nameof(configuration)); - - if (configuration.Version is null) + public class ConfigurationVersionLabelComparer : IEqualityComparer + { + public bool Equals(Configuration x, Configuration y) + { + if (ReferenceEquals(x, y)) return true; + + if (x == null && y != null) return false; + + if (y == null && x != null) return false; + + if (x.Version == y.Version) + { + if (x.Label != null) + { + return y.Label == null ? false : x.Label.SequenceEqual(y.Label); + } + else + { + return y.Label == null; + } + } + + return false; + } + + public int GetHashCode(Configuration configuration) + { + if (configuration is null) + throw new ArgumentNullException(nameof(configuration)); + + if (configuration.Version is null) #pragma warning disable CA2208 // Instantiate argument exceptions correctly - throw new ArgumentNullException("Version"); + throw new ArgumentNullException("Version"); - if (configuration.Label is null) - throw new ArgumentNullException("Label"); + if (configuration.Label is null) + throw new ArgumentNullException("Label"); #pragma warning restore CA2208 // Instantiate argument exceptions correctly - return configuration.Version.GetHashCode() * 17 + configuration.Label.GetHashCode(); - } - } + return (configuration.Version.GetHashCode() * 17) + configuration.Label.GetHashCode(); + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/BuildServers/AzureDevopsProcess.cs b/src/SimpleVersion.Core/Pipeline/BuildServers/AzureDevopsProcess.cs index fbe44d1..ae4aa44 100644 --- a/src/SimpleVersion.Core/Pipeline/BuildServers/AzureDevopsProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/BuildServers/AzureDevopsProcess.cs @@ -1,32 +1,32 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Text.RegularExpressions; namespace SimpleVersion.Pipeline.BuildServers { - public class AzureDevopsProcess : ICalculatorProcess - { - private static Regex _trim = new Regex(@"^refs\/(heads\/)?", RegexOptions.IgnoreCase); - private readonly IEnvironment _env; + public class AzureDevopsProcess : ICalculatorProcess + { + private static readonly Regex _trim = new Regex(@"^refs\/(heads\/)?", RegexOptions.IgnoreCase); + private readonly IEnvironment _env; - public AzureDevopsProcess(): this(new VersioningEnvironment()) - { + public AzureDevopsProcess() : this(new VersioningEnvironment()) + { - } + } - public AzureDevopsProcess(IEnvironment env) - { - _env = env; - } + public AzureDevopsProcess(IEnvironment env) + { + _env = env; + } - public void Apply(VersionContext context) - { - if (_env.GetVariable("TF_BUILD").ToBool()) - { - context.Result.CanonicalBranchName = _env.GetVariable("BUILD_SOURCEBRANCH"); - context.Result.BranchName = _trim.Replace(context.Result.CanonicalBranchName, string.Empty); ; - } - } - } + public void Apply(VersionContext context) + { + if (_env.GetVariable("TF_BUILD").ToBool()) + { + context.Result.CanonicalBranchName = _env.GetVariable("BUILD_SOURCEBRANCH"); + context.Result.BranchName = _trim.Replace(context.Result.CanonicalBranchName, string.Empty); ; + } + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs b/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs index a23910b..add4375 100644 --- a/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs @@ -1,31 +1,31 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Rules; namespace SimpleVersion.Pipeline.Formatting { - public class Semver1FormatProcess : ICalculatorProcess - { - public void Apply(VersionContext context) - { - var rules = new IRule[] - { - new HeightRule(true), - ShortShaRule.Instance, - BranchNameRule.Instance, - ShortBranchNameRule.Instance, - BranchNameSuffixRule.Instance - }; + public class Semver1FormatProcess : ICalculatorProcess + { + public void Apply(VersionContext context) + { + var rules = new IRule[] + { + new HeightRule(true), + ShortShaRule.Instance, + BranchNameRule.Instance, + ShortBranchNameRule.Instance, + BranchNameSuffixRule.Instance + }; - var labelParts = context.Configuration.Label.ApplyRules(context, rules); - var label = string.Join("-", labelParts).ResolveRules(context, rules); + var labelParts = context.Configuration.Label.ApplyRules(context, rules); + var label = string.Join("-", labelParts).ResolveRules(context, rules); - var format = context.Result.Version; + var format = context.Result.Version; - if (!string.IsNullOrWhiteSpace(label)) - format += $"-{label}"; + if (!string.IsNullOrWhiteSpace(label)) + format += $"-{label}"; - context.Result.Formats["Semver1"] = format; - } - } + context.Result.Formats["Semver1"] = format; + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs b/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs index c5dbfd6..dc896e4 100644 --- a/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs @@ -1,35 +1,35 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Rules; namespace SimpleVersion.Pipeline.Formatting { - public class Semver2FormatProcess : ICalculatorProcess - { - public void Apply(VersionContext context) - { - var rules = new IRule[] - { - HeightRule.Instance, - ShortShaRule.Instance, - BranchNameRule.Instance, - ShortBranchNameRule.Instance, - BranchNameSuffixRule.Instance - }; + public class Semver2FormatProcess : ICalculatorProcess + { + public void Apply(VersionContext context) + { + var rules = new IRule[] + { + HeightRule.Instance, + ShortShaRule.Instance, + BranchNameRule.Instance, + ShortBranchNameRule.Instance, + BranchNameSuffixRule.Instance + }; - var labelParts = context.Configuration.Label.ApplyRules(context, rules); - var label = string.Join(".", labelParts).ResolveRules(context, rules); - var meta = string.Join(".", context.Configuration.MetaData).ResolveRules(context, rules); - - var format = context.Result.Version; + var labelParts = context.Configuration.Label.ApplyRules(context, rules); + var label = string.Join(".", labelParts).ResolveRules(context, rules); + var meta = string.Join(".", context.Configuration.MetaData).ResolveRules(context, rules); - if (!string.IsNullOrWhiteSpace(label)) - format += $"-{label}"; + var format = context.Result.Version; - if (!string.IsNullOrWhiteSpace(meta)) - format += $"+{meta}"; + if (!string.IsNullOrWhiteSpace(label)) + format += $"-{label}"; - context.Result.Formats["Semver2"] = format; - } - } + if (!string.IsNullOrWhiteSpace(meta)) + format += $"+{meta}"; + + context.Result.Formats["Semver2"] = format; + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/Formatting/VersionFormatProcess.cs b/src/SimpleVersion.Core/Pipeline/Formatting/VersionFormatProcess.cs index e893dbf..114fcde 100644 --- a/src/SimpleVersion.Core/Pipeline/Formatting/VersionFormatProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/Formatting/VersionFormatProcess.cs @@ -1,33 +1,33 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Rules; using System; namespace SimpleVersion.Pipeline.Formatting { - public class VersionFormatProcess : ICalculatorProcess - { - public void Apply(VersionContext context) - { - var versionString = HeightRule.Instance.Resolve(context, context.Configuration.Version); + public class VersionFormatProcess : ICalculatorProcess + { + public void Apply(VersionContext context) + { + var versionString = HeightRule.Instance.Resolve(context, context.Configuration.Version); - if (Version.TryParse(versionString, out var version)) - { - context.Result.Major = version.Major > -1 ? version.Major : 0; - context.Result.Minor = version.Minor > -1 ? version.Minor : 0; - context.Result.Patch = version.Build > -1 ? version.Build : 0; + if (Version.TryParse(versionString, out var version)) + { + context.Result.Major = version.Major > -1 ? version.Major : 0; + context.Result.Minor = version.Minor > -1 ? version.Minor : 0; + context.Result.Patch = version.Build > -1 ? version.Build : 0; - context.Result.Version = $"{context.Result.Major}.{context.Result.Minor}.{context.Result.Patch}"; - if(version.Revision > -1) - { - context.Result.Version += $".{version.Revision}"; - context.Result.Revision = version.Revision; - } - } - else - { - throw new InvalidOperationException($"Version '{versionString}' is not in a valid format"); - } - } - } + context.Result.Version = $"{context.Result.Major}.{context.Result.Minor}.{context.Result.Patch}"; + if (version.Revision > -1) + { + context.Result.Version += $".{version.Revision}"; + context.Result.Revision = version.Revision; + } + } + else + { + throw new InvalidOperationException($"Version '{versionString}' is not in a valid format"); + } + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/ResolveConfigurationProcess.cs b/src/SimpleVersion.Core/Pipeline/ResolveConfigurationProcess.cs index cf3d0a1..fa71d5d 100644 --- a/src/SimpleVersion.Core/Pipeline/ResolveConfigurationProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/ResolveConfigurationProcess.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using LibGit2Sharp; using SVM = SimpleVersion.Model; @@ -11,136 +11,137 @@ namespace SimpleVersion.Pipeline { - public class ResolveConfigurationProcess : ICalculatorProcess - { - private static readonly ConfigurationVersionLabelComparer _comparer = new ConfigurationVersionLabelComparer(); - - public void Apply(VersionContext context) - { - if (context == null) - throw new ArgumentNullException(nameof(context)); - - if (string.IsNullOrWhiteSpace(context.RepositoryPath)) - throw new ArgumentException($"{nameof(context.RepositoryPath)} must be a directory"); - - using(var repo = new Repository(context.RepositoryPath)){ - if(string.IsNullOrWhiteSpace(context.Result.CanonicalBranchName)) - context.Result.CanonicalBranchName = repo.Head.CanonicalName; - - if(string.IsNullOrWhiteSpace(context.Result.BranchName)) - context.Result.BranchName = repo.Head.FriendlyName; - - var config = GetConfiguration(repo.Head?.Tip, context) - ?? throw new InvalidOperationException($"Could not read '{Constants.VersionFileName}', has it been committed?"); - - context.Configuration = config; - - PopulateResult(context, repo); - } - } - - private void PopulateResult(VersionContext context, Repository repo) - { - // Get the state of this tree to compare for diffs - var tipTree = repo.Head.Tip.Tree; - - // Initialise count - The current commit counts, include offset - var height = 1 + context.Configuration.OffSet; - - // skip the first commit as that is our baseline - var commits = GetReachableCommits(repo).Skip(1).GetEnumerator(); - - while (commits.MoveNext()) - { - // Get the current tree - var next = commits.Current.Tree; - // Perform a diff - var diff = repo.Diff.Compare(next, tipTree); - // If a change to the file is found, stop counting - if (HasVersionChange(diff, commits.Current, context)) - break; - - // Increment height - height++; - } - - context.Result.Sha = repo.Head.Tip.Sha; - context.Result.Height = height; - } - - private static bool HasVersionChange( - TreeChanges diff, - Commit commit, - VersionContext context) - { - if (diff.Any(d => d.Path == Constants.VersionFileName)) - { - var commitConfig = GetConfiguration(commit, context); - return commitConfig != null && !_comparer.Equals(context.Configuration, commitConfig); - } - - return false; - } - - private static IEnumerable GetReachableCommits(Repository repo) - { - var filter = new CommitFilter - { - FirstParentOnly = true, - IncludeReachableFrom = repo.Head, - SortBy = CommitSortStrategies.Reverse - }; - - return repo.Commits.QueryBy(filter).Reverse(); - } - - private static SVM.Configuration GetConfiguration(Commit commit, VersionContext context) - { - var gitObj = commit?.Tree[Constants.VersionFileName]?.Target; - if (gitObj == null) - return null; - - var config = Read((gitObj as Blob).GetContentText()); - ApplyConfigOverrides(config, context); - return config; - } - - private static void ApplyConfigOverrides(SVM.Configuration config, VersionContext context) - { - if (config == null) - return; - - var firstMatch = config.Branches - .Overrides.FirstOrDefault(x => Regex.IsMatch(context.Result.CanonicalBranchName, x.Match, RegexOptions.IgnoreCase)); - - if (firstMatch != null) - { - if (firstMatch.Label != null) - { - config.Label.Clear(); - config.Label.AddRange(firstMatch.Label); - } - - if(firstMatch.MetaData != null) - { - config.MetaData.Clear(); - config.MetaData.AddRange(firstMatch.MetaData); - } - } - } - private static SVM.Configuration Read(string rawConfiguration) - { - try - { - return JsonConvert.DeserializeObject(rawConfiguration); - } + public class ResolveConfigurationProcess : ICalculatorProcess + { + private static readonly ConfigurationVersionLabelComparer _comparer = new ConfigurationVersionLabelComparer(); + + public void Apply(VersionContext context) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); + + if (string.IsNullOrWhiteSpace(context.RepositoryPath)) + throw new ArgumentException($"{nameof(context.RepositoryPath)} must be a directory"); + + using (var repo = new Repository(context.RepositoryPath)) + { + if (string.IsNullOrWhiteSpace(context.Result.CanonicalBranchName)) + context.Result.CanonicalBranchName = repo.Head.CanonicalName; + + if (string.IsNullOrWhiteSpace(context.Result.BranchName)) + context.Result.BranchName = repo.Head.FriendlyName; + + var config = GetConfiguration(repo.Head?.Tip, context) + ?? throw new InvalidOperationException($"Could not read '{Constants.VersionFileName}', has it been committed?"); + + context.Configuration = config; + + PopulateResult(context, repo); + } + } + + private void PopulateResult(VersionContext context, Repository repo) + { + // Get the state of this tree to compare for diffs + var tipTree = repo.Head.Tip.Tree; + + // Initialise count - The current commit counts, include offset + var height = 1 + context.Configuration.OffSet; + + // skip the first commit as that is our baseline + var commits = GetReachableCommits(repo).Skip(1).GetEnumerator(); + + while (commits.MoveNext()) + { + // Get the current tree + var next = commits.Current.Tree; + // Perform a diff + var diff = repo.Diff.Compare(next, tipTree); + // If a change to the file is found, stop counting + if (HasVersionChange(diff, commits.Current, context)) + break; + + // Increment height + height++; + } + + context.Result.Sha = repo.Head.Tip.Sha; + context.Result.Height = height; + } + + private static bool HasVersionChange( + TreeChanges diff, + Commit commit, + VersionContext context) + { + if (diff.Any(d => d.Path == Constants.VersionFileName)) + { + var commitConfig = GetConfiguration(commit, context); + return commitConfig != null && !_comparer.Equals(context.Configuration, commitConfig); + } + + return false; + } + + private static IEnumerable GetReachableCommits(Repository repo) + { + var filter = new CommitFilter + { + FirstParentOnly = true, + IncludeReachableFrom = repo.Head, + SortBy = CommitSortStrategies.Reverse + }; + + return repo.Commits.QueryBy(filter).Reverse(); + } + + private static SVM.Configuration GetConfiguration(Commit commit, VersionContext context) + { + var gitObj = commit?.Tree[Constants.VersionFileName]?.Target; + if (gitObj == null) + return null; + + var config = Read((gitObj as Blob).GetContentText()); + ApplyConfigOverrides(config, context); + return config; + } + + private static void ApplyConfigOverrides(SVM.Configuration config, VersionContext context) + { + if (config == null) + return; + + var firstMatch = config.Branches + .Overrides.FirstOrDefault(x => Regex.IsMatch(context.Result.CanonicalBranchName, x.Match, RegexOptions.IgnoreCase)); + + if (firstMatch != null) + { + if (firstMatch.Label != null) + { + config.Label.Clear(); + config.Label.AddRange(firstMatch.Label); + } + + if (firstMatch.MetaData != null) + { + config.MetaData.Clear(); + config.MetaData.AddRange(firstMatch.MetaData); + } + } + } + private static SVM.Configuration Read(string rawConfiguration) + { + try + { + return JsonConvert.DeserializeObject(rawConfiguration); + } #pragma warning disable CA1031 // Do not catch general exception types - catch - { - //TODO handle logger of invalid parsing - return null; - } + catch + { + //TODO handle logger of invalid parsing + return null; + } #pragma warning restore CA1031 // Do not catch general exception types - } - } + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/ResolveRepositoryPathProcess.cs b/src/SimpleVersion.Core/Pipeline/ResolveRepositoryPathProcess.cs index ec46a38..46be045 100644 --- a/src/SimpleVersion.Core/Pipeline/ResolveRepositoryPathProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/ResolveRepositoryPathProcess.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using LibGit2Sharp; using System; @@ -6,24 +6,24 @@ namespace SimpleVersion.Pipeline { - public class ResolveRepositoryPathProcess : ICalculatorProcess - { - public void Apply(VersionContext context) - { - if (context == null) - throw new ArgumentNullException(nameof(context)); + public class ResolveRepositoryPathProcess : ICalculatorProcess + { + public void Apply(VersionContext context) + { + if (context == null) + throw new ArgumentNullException(nameof(context)); - if (string.IsNullOrWhiteSpace(context.Path)) - throw new Exception("Context path should be populated"); + if (string.IsNullOrWhiteSpace(context.Path)) + throw new Exception("Context path should be populated"); - var resolvedPath = Repository.Discover(context.Path); + var resolvedPath = Repository.Discover(context.Path); - if (string.IsNullOrWhiteSpace(resolvedPath)) - throw new DirectoryNotFoundException($"Could not find git repository at '{context.Path}' or any parent directory"); + if (string.IsNullOrWhiteSpace(resolvedPath)) + throw new DirectoryNotFoundException($"Could not find git repository at '{context.Path}' or any parent directory"); - // resolvedPath is full pth to .git folder. We want the repo root. - resolvedPath = resolvedPath.Trim(Path.DirectorySeparatorChar); - context.RepositoryPath = Directory.GetParent(resolvedPath).FullName; - } - } + // resolvedPath is full pth to .git folder. We want the repo root. + resolvedPath = resolvedPath.Trim(Path.DirectorySeparatorChar); + context.RepositoryPath = Directory.GetParent(resolvedPath).FullName; + } + } } diff --git a/src/SimpleVersion.Core/Pipeline/VersionCalculator.cs b/src/SimpleVersion.Core/Pipeline/VersionCalculator.cs index 43ed299..869a346 100644 --- a/src/SimpleVersion.Core/Pipeline/VersionCalculator.cs +++ b/src/SimpleVersion.Core/Pipeline/VersionCalculator.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Model; using SimpleVersion.Pipeline.BuildServers; @@ -8,33 +8,33 @@ namespace SimpleVersion.Pipeline { - public class VersionCalculator : IVersionCalculator - { - public static IVersionCalculator Default() - => new VersionCalculator() - .AddProcessor() - .AddProcessor() - .AddProcessor() - .AddProcessor() - .AddProcessor() - .AddProcessor(); + public class VersionCalculator : IVersionCalculator + { + public static IVersionCalculator Default() + => new VersionCalculator() + .AddProcessor() + .AddProcessor() + .AddProcessor() + .AddProcessor() + .AddProcessor() + .AddProcessor(); - private readonly Queue> _queue = new Queue>(); + private readonly Queue> _queue = new Queue>(); - public IVersionCalculator AddProcessor() where T : ICalculatorProcess, new() - { - _queue.Enqueue(new Lazy(() => new T())); - return this; - } + public IVersionCalculator AddProcessor() where T : ICalculatorProcess, new() + { + _queue.Enqueue(new Lazy(() => new T())); + return this; + } - public VersionResult GetResult(string path) - { - var ctx = new VersionContext { Path = path }; + public VersionResult GetResult(string path) + { + var ctx = new VersionContext { Path = path }; - foreach (var processor in _queue) - processor.Value.Apply(ctx); + foreach (var processor in _queue) + processor.Value.Apply(ctx); - return ctx.Result; - } - } + return ctx.Result; + } + } } diff --git a/src/SimpleVersion.Core/Rules/BaseBranchNameRule.cs b/src/SimpleVersion.Core/Rules/BaseBranchNameRule.cs index 1157d8e..635e43c 100644 --- a/src/SimpleVersion.Core/Rules/BaseBranchNameRule.cs +++ b/src/SimpleVersion.Core/Rules/BaseBranchNameRule.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Collections.Generic; @@ -10,41 +10,41 @@ namespace SimpleVersion.Rules { - public abstract class BaseBranchNameRule : IRule - { - private const string _defaultPattern = "[^a-z0-9]"; - - protected BaseBranchNameRule() : this(_defaultPattern) - { - } - - protected BaseBranchNameRule(string pattern) - { - Pattern = new Regex(pattern, RegexOptions.IgnoreCase); - } - - public abstract string Token { get; protected set; } - - public Regex Pattern { get; protected set; } - - public virtual IEnumerable Apply(VersionContext context, IEnumerable value) - { - // No default implementation applies branch name - return value; - } - - public virtual string Resolve(VersionContext context, string value) - { - if (Regex.IsMatch(value, Token, RegexOptions.IgnoreCase)) - { - var name = ResolveBranchName(context); - name = Pattern.Replace(name, ""); - return Regex.Replace(value, Regex.Escape(Token), name, RegexOptions.IgnoreCase); - } - - return value; - } - - protected abstract string ResolveBranchName(VersionContext context); - } + public abstract class BaseBranchNameRule : IRule + { + private const string _defaultPattern = "[^a-z0-9]"; + + protected BaseBranchNameRule() : this(_defaultPattern) + { + } + + protected BaseBranchNameRule(string pattern) + { + Pattern = new Regex(pattern, RegexOptions.IgnoreCase); + } + + public abstract string Token { get; protected set; } + + public Regex Pattern { get; protected set; } + + public virtual IEnumerable Apply(VersionContext context, IEnumerable value) + { + // No default implementation applies branch name + return value; + } + + public virtual string Resolve(VersionContext context, string value) + { + if (Regex.IsMatch(value, Token, RegexOptions.IgnoreCase)) + { + var name = ResolveBranchName(context); + name = Pattern.Replace(name, ""); + return Regex.Replace(value, Regex.Escape(Token), name, RegexOptions.IgnoreCase); + } + + return value; + } + + protected abstract string ResolveBranchName(VersionContext context); + } } diff --git a/src/SimpleVersion.Core/Rules/BranchNameRule.cs b/src/SimpleVersion.Core/Rules/BranchNameRule.cs index fb6536d..f2150bd 100644 --- a/src/SimpleVersion.Core/Rules/BranchNameRule.cs +++ b/src/SimpleVersion.Core/Rules/BranchNameRule.cs @@ -1,26 +1,26 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using SimpleVersion.Pipeline; namespace SimpleVersion.Rules { - public class BranchNameRule : BaseBranchNameRule - { - private static Lazy _default = new Lazy(() => new BranchNameRule()); + public class BranchNameRule : BaseBranchNameRule + { + private static readonly Lazy _default = new Lazy(() => new BranchNameRule()); - public static BranchNameRule Instance => _default.Value; + public static BranchNameRule Instance => _default.Value; - public BranchNameRule() : base() - { - } + public BranchNameRule() : base() + { + } - public BranchNameRule(string pattern) : base(pattern) - { - } + public BranchNameRule(string pattern) : base(pattern) + { + } - public override string Token { get; protected set; } = "{branchname}"; + public override string Token { get; protected set; } = "{branchname}"; - protected override string ResolveBranchName(VersionContext context) => context.Result.CanonicalBranchName; - } + protected override string ResolveBranchName(VersionContext context) => context.Result.CanonicalBranchName; + } } diff --git a/src/SimpleVersion.Core/Rules/BranchNameSuffixRule.cs b/src/SimpleVersion.Core/Rules/BranchNameSuffixRule.cs index 6d593e7..d2ccf5a 100644 --- a/src/SimpleVersion.Core/Rules/BranchNameSuffixRule.cs +++ b/src/SimpleVersion.Core/Rules/BranchNameSuffixRule.cs @@ -1,29 +1,29 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System; namespace SimpleVersion.Rules { - public class BranchNameSuffixRule : BaseBranchNameRule - { - private static Lazy _default = new Lazy(() => new BranchNameSuffixRule()); + public class BranchNameSuffixRule : BaseBranchNameRule + { + private static readonly Lazy _default = new Lazy(() => new BranchNameSuffixRule()); - public static BranchNameSuffixRule Instance => _default.Value; + public static BranchNameSuffixRule Instance => _default.Value; - public BranchNameSuffixRule() : base() - { - } + public BranchNameSuffixRule() : base() + { + } - public BranchNameSuffixRule(string pattern) : base(pattern) - { - } - - public override string Token { get; protected set; } = "{branchnamesuffix}"; + public BranchNameSuffixRule(string pattern) : base(pattern) + { + } - protected override string ResolveBranchName(VersionContext context) - { - return context.Result.CanonicalBranchName.Substring(context.Result.CanonicalBranchName.LastIndexOf('/') + 1); - } - } + public override string Token { get; protected set; } = "{branchnamesuffix}"; + + protected override string ResolveBranchName(VersionContext context) + { + return context.Result.CanonicalBranchName.Substring(context.Result.CanonicalBranchName.LastIndexOf('/') + 1); + } + } } diff --git a/src/SimpleVersion.Core/Rules/HeightRule.cs b/src/SimpleVersion.Core/Rules/HeightRule.cs index f313369..b38fc97 100644 --- a/src/SimpleVersion.Core/Rules/HeightRule.cs +++ b/src/SimpleVersion.Core/Rules/HeightRule.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System; @@ -7,44 +7,44 @@ namespace SimpleVersion.Rules { - public class HeightRule : IRule - { - private static Lazy _default = new Lazy(() => new HeightRule()); - - public static HeightRule Instance => _default.Value; - - public HeightRule() :this(false) - { - - } - - public HeightRule(bool padded) - { - Padded = padded; - } - - public bool Padded { get; } - - public string Token => "*"; - - public string Resolve(VersionContext context, string value) - { - if (Padded) - return value.Replace(Token, context.Result.HeightPadded); - else - return value.Replace(Token, context.Result.Height.ToString(System.Globalization.CultureInfo.CurrentCulture)); - } - - public IEnumerable Apply(VersionContext context, IEnumerable input) - { - if (!context.Configuration.Version.Contains(Token) - && input.Count() != 0 - && !input.Contains(Token)) - { - return input.Concat(new[] { Token }); - } - - return input; - } - } + public class HeightRule : IRule + { + private static readonly Lazy _default = new Lazy(() => new HeightRule()); + + public static HeightRule Instance => _default.Value; + + public HeightRule() : this(false) + { + + } + + public HeightRule(bool padded) + { + Padded = padded; + } + + public bool Padded { get; } + + public string Token => "*"; + + public string Resolve(VersionContext context, string value) + { + if (Padded) + return value.Replace(Token, context.Result.HeightPadded); + else + return value.Replace(Token, context.Result.Height.ToString(System.Globalization.CultureInfo.CurrentCulture)); + } + + public IEnumerable Apply(VersionContext context, IEnumerable input) + { + if (!context.Configuration.Version.Contains(Token) + && input.Count() != 0 + && !input.Contains(Token)) + { + return input.Concat(new[] { Token }); + } + + return input; + } + } } diff --git a/src/SimpleVersion.Core/Rules/RuleExtensions.cs b/src/SimpleVersion.Core/Rules/RuleExtensions.cs index 4ec8612..5cbe510 100644 --- a/src/SimpleVersion.Core/Rules/RuleExtensions.cs +++ b/src/SimpleVersion.Core/Rules/RuleExtensions.cs @@ -1,28 +1,28 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System.Collections.Generic; namespace SimpleVersion.Rules { - public static class RuleExtensions - { - public static IEnumerable ApplyRules(this IEnumerable value, VersionContext context, IEnumerable> rules) - { - var next = value; - foreach (var rule in rules) - next = rule.Apply(context, next); + public static class RuleExtensions + { + public static IEnumerable ApplyRules(this IEnumerable value, VersionContext context, IEnumerable> rules) + { + var next = value; + foreach (var rule in rules) + next = rule.Apply(context, next); - return next; - } + return next; + } - public static T ResolveRules(this T value, VersionContext context, IEnumerable> rules) - { - var next = value; - foreach (var rule in rules) - next = rule.Resolve(context, next); + public static T ResolveRules(this T value, VersionContext context, IEnumerable> rules) + { + var next = value; + foreach (var rule in rules) + next = rule.Resolve(context, next); - return next; - } - } + return next; + } + } } diff --git a/src/SimpleVersion.Core/Rules/ShortBranchNameRule.cs b/src/SimpleVersion.Core/Rules/ShortBranchNameRule.cs index 80b1255..d819ba9 100644 --- a/src/SimpleVersion.Core/Rules/ShortBranchNameRule.cs +++ b/src/SimpleVersion.Core/Rules/ShortBranchNameRule.cs @@ -1,26 +1,26 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System; namespace SimpleVersion.Rules { - public class ShortBranchNameRule : BaseBranchNameRule - { - private static Lazy _default = new Lazy(() => new ShortBranchNameRule()); + public class ShortBranchNameRule : BaseBranchNameRule + { + private static readonly Lazy _default = new Lazy(() => new ShortBranchNameRule()); - public static ShortBranchNameRule Instance => _default.Value; + public static ShortBranchNameRule Instance => _default.Value; - public ShortBranchNameRule() : base() - { - } + public ShortBranchNameRule() : base() + { + } - public ShortBranchNameRule(string pattern) : base(pattern) - { - } - - public override string Token { get; protected set; } = "{shortbranchname}"; + public ShortBranchNameRule(string pattern) : base(pattern) + { + } - protected override string ResolveBranchName(VersionContext context) => context.Result.BranchName; - } + public override string Token { get; protected set; } = "{shortbranchname}"; + + protected override string ResolveBranchName(VersionContext context) => context.Result.BranchName; + } } diff --git a/src/SimpleVersion.Core/Rules/ShortShaRule.cs b/src/SimpleVersion.Core/Rules/ShortShaRule.cs index fa4db81..b49dae1 100644 --- a/src/SimpleVersion.Core/Rules/ShortShaRule.cs +++ b/src/SimpleVersion.Core/Rules/ShortShaRule.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline; using System; @@ -8,31 +8,31 @@ namespace SimpleVersion.Rules { - public class ShortShaRule : IRule - { - private static Lazy _default = new Lazy(() => new ShortShaRule()); + public class ShortShaRule : IRule + { + private static readonly Lazy _default = new Lazy(() => new ShortShaRule()); - public static ShortShaRule Instance => _default.Value; + public static ShortShaRule Instance => _default.Value; - public string Token => "{shortsha}"; + public string Token => "{shortsha}"; - public string Resolve(VersionContext context, string value) - { - var shortSha = context.Result.Sha.Substring(0, 7); - return Regex.Replace(value, Regex.Escape(Token), $"c{shortSha}", RegexOptions.IgnoreCase); - } + public string Resolve(VersionContext context, string value) + { + var shortSha = context.Result.Sha.Substring(0, 7); + return Regex.Replace(value, Regex.Escape(Token), $"c{shortSha}", RegexOptions.IgnoreCase); + } - public IEnumerable Apply(VersionContext context, IEnumerable input) - { - var isRelease = context.Configuration.Branches.Release - .Any(x => Regex.IsMatch(context.Result.CanonicalBranchName, x)); + public IEnumerable Apply(VersionContext context, IEnumerable input) + { + var isRelease = context.Configuration.Branches.Release + .Any(x => Regex.IsMatch(context.Result.CanonicalBranchName, x)); - if (!isRelease && !input.Contains(Token)) - { - return input.Concat(new[] { Token }); - } + if (!isRelease && !input.Contains(Token)) + { + return input.Concat(new[] { Token }); + } - return input; - } - } + return input; + } + } } diff --git a/src/SimpleVersion.Core/SimpleVersion.Core.csproj b/src/SimpleVersion.Core/SimpleVersion.Core.csproj index ff146bc..d48cc9f 100644 --- a/src/SimpleVersion.Core/SimpleVersion.Core.csproj +++ b/src/SimpleVersion.Core/SimpleVersion.Core.csproj @@ -1,18 +1,18 @@ - - + + - - SimpleVersion - + + SimpleVersion + - - - - - + + + + + - - - + + + diff --git a/src/SimpleVersion.Core/StringExtensions.cs b/src/SimpleVersion.Core/StringExtensions.cs index f78a02c..d16fe87 100644 --- a/src/SimpleVersion.Core/StringExtensions.cs +++ b/src/SimpleVersion.Core/StringExtensions.cs @@ -1,22 +1,22 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; namespace SimpleVersion { - public static class StringExtensions - { - public static bool ToBool(this string value) - { - if (string.IsNullOrWhiteSpace(value)) - return false; + public static class StringExtensions + { + public static bool ToBool(this string value) + { + if (string.IsNullOrWhiteSpace(value)) + return false; - if(int.TryParse(value, out var intValue)) - { - return intValue == 0; - } + if (int.TryParse(value, out var intValue)) + { + return intValue == 0; + } - return bool.TrueString.Equals(value, StringComparison.OrdinalIgnoreCase); - } - } + return bool.TrueString.Equals(value, StringComparison.OrdinalIgnoreCase); + } + } } diff --git a/src/SimpleVersion.Core/VersioningEnvironment.cs b/src/SimpleVersion.Core/VersioningEnvironment.cs index 6a62f69..417f995 100644 --- a/src/SimpleVersion.Core/VersioningEnvironment.cs +++ b/src/SimpleVersion.Core/VersioningEnvironment.cs @@ -1,9 +1,9 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. namespace SimpleVersion { - public class VersioningEnvironment : IEnvironment - { - public string GetVariable(string name) => System.Environment.GetEnvironmentVariable(name); - } + public class VersioningEnvironment : IEnvironment + { + public string GetVariable(string name) => System.Environment.GetEnvironmentVariable(name); + } } diff --git a/test/Assets/.simpleversion.json b/test/Assets/.simpleversion.json index 87f4532..136efee 100644 --- a/test/Assets/.simpleversion.json +++ b/test/Assets/.simpleversion.json @@ -1,12 +1,12 @@ { - "Version": "1.2.3.4", - "Label": [ "alpha1" ], - "Metadata": [ "test", "branch" ], - "Branches": { - "Release": [ - "^master$", - "^preview/.+$", - "^release/.+$" - ] - } -} \ No newline at end of file + "Version": "1.2.3.4", + "Label": [ "alpha1" ], + "Metadata": [ "test", "branch" ], + "Branches": { + "Release": [ + "^master$", + "^preview/.+$", + "^release/.+$" + ] + } +} diff --git a/test/Assets/Expectations/Empty.json b/test/Assets/Expectations/Empty.json index 7ce1cb1..7e0e312 100644 --- a/test/Assets/Expectations/Empty.json +++ b/test/Assets/Expectations/Empty.json @@ -1,9 +1,9 @@ { - "Version": "", - "OffSet": 0, - "Label": [], - "MetaData": [], - "Branches": { - "Release": [] - } -} \ No newline at end of file + "Version": "", + "OffSet": 0, + "Label": [], + "MetaData": [], + "Branches": { + "Release": [] + } +} diff --git a/test/Assets/Expectations/ToTextWithModel.json b/test/Assets/Expectations/ToTextWithModel.json index 6cd8827..372f0ea 100644 --- a/test/Assets/Expectations/ToTextWithModel.json +++ b/test/Assets/Expectations/ToTextWithModel.json @@ -1,15 +1,15 @@ { - "Version": "1.2.3.4", - "OffSet": 0, - "Label": [ - "First", - "Second" - ], - "MetaData": [ - "Meta1", - "Meta2" - ], - "Branches": { - "Release": [] - } -} \ No newline at end of file + "Version": "1.2.3.4", + "OffSet": 0, + "Label": [ + "First", + "Second" + ], + "MetaData": [ + "Meta1", + "Meta2" + ], + "Branches": { + "Release": [] + } +} diff --git a/test/Directory.Build.props b/test/Directory.Build.props index f2512ba..2d7fbff 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -1,30 +1,30 @@ - - - - false - + - - - - - - - + + false + + + + + + + + + + + + + Assets\%(RecursiveDir)%(Filename)%(Extension) + Always + + + + + + GlobalSuppressions.cs + + - - - Assets\%(RecursiveDir)%(Filename)%(Extension) - Always - - - - - - GlobalSuppressions.cs - - - diff --git a/test/SimpleVersion.Abstractions.Tests/Model/BranchConfigurationFixture.cs b/test/SimpleVersion.Abstractions.Tests/Model/BranchConfigurationFixture.cs index 380348f..fe56171 100644 --- a/test/SimpleVersion.Abstractions.Tests/Model/BranchConfigurationFixture.cs +++ b/test/SimpleVersion.Abstractions.Tests/Model/BranchConfigurationFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Model; @@ -6,18 +6,18 @@ namespace SimpleVersion.Abstractions.Tests.Model { - public class BranchConfigurationFixture - { - [Fact] - public void Ctor_SetsDefaults() - { - // Arrange / Act - var sut = new BranchConfiguration(); + public class BranchConfigurationFixture + { + [Fact] + public void Ctor_SetsDefaults() + { + // Arrange / Act + var sut = new BranchConfiguration(); - // Assert - sut.Label.Should().BeNull(); - sut.Match.Should().BeEmpty(); - sut.MetaData.Should().BeNull(); - } - } + // Assert + sut.Label.Should().BeNull(); + sut.Match.Should().BeEmpty(); + sut.MetaData.Should().BeNull(); + } + } } diff --git a/test/SimpleVersion.Abstractions.Tests/Model/BranchInfoFixture.cs b/test/SimpleVersion.Abstractions.Tests/Model/BranchInfoFixture.cs index da7ed79..f8559db 100644 --- a/test/SimpleVersion.Abstractions.Tests/Model/BranchInfoFixture.cs +++ b/test/SimpleVersion.Abstractions.Tests/Model/BranchInfoFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Model; @@ -6,17 +6,17 @@ namespace SimpleVersion.Abstractions.Tests.Model { - public class BranchInfoFixture - { - [Fact] - public void Ctor_PopulatesEmpty_Release() - { - // Arrange / Act - var sut = new BranchInfo(); + public class BranchInfoFixture + { + [Fact] + public void Ctor_PopulatesEmpty_Release() + { + // Arrange / Act + var sut = new BranchInfo(); - // Assert - sut.Release.Should().BeEmpty(); - sut.Overrides.Should().BeEmpty(); - } - } + // Assert + sut.Release.Should().BeEmpty(); + sut.Overrides.Should().BeEmpty(); + } + } } diff --git a/test/SimpleVersion.Abstractions.Tests/Model/ConfigurationFixture.cs b/test/SimpleVersion.Abstractions.Tests/Model/ConfigurationFixture.cs index 42fae5c..148aa21 100644 --- a/test/SimpleVersion.Abstractions.Tests/Model/ConfigurationFixture.cs +++ b/test/SimpleVersion.Abstractions.Tests/Model/ConfigurationFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Model; @@ -7,53 +7,53 @@ namespace SimpleVersion.Abstractions.Tests.Model { - public class ConfigurationFixture - { - [Fact] - public void Ctor_SetsDefaults() - { - // Arrange / Act - var sut = new Configuration(); - - // Assert - sut.Label.Should().BeEmpty(); - sut.MetaData.Should().BeEmpty(); - sut.Version.Should().BeEmpty(); - sut.OffSet.Should().Be(0); - sut.Branches.Should().NotBeNull(); - } - - [Fact] - public void Equals_GivenNull_ReturnsFalse() - { - // Arrange - var sut = new Configuration(); - - // Act - var result = sut.Equals(null); - - // Assert - result.Should().BeFalse(); - } - - public static string Thing => "this"; - - public static IEnumerable DifferInLabel() - { - yield return new[] { new Configuration(), new Configuration { Label = { "one" } } }; - yield return new[] { new Configuration { Label = { "one" } }, new Configuration() }; - yield return new[] { new Configuration { Label = { "one", "two" } }, new Configuration { Label = { "one", "three" } } }; - } - - [Theory] - [MemberData(nameof(DifferInLabel))] - public void Equals_DifferInLabel_ReturnsTrue(Configuration sut, Configuration other) - { - // Arrange / Act - var result = sut.Equals(other); - - // Assert - result.Should().BeFalse(); - } - } + public class ConfigurationFixture + { + [Fact] + public void Ctor_SetsDefaults() + { + // Arrange / Act + var sut = new Configuration(); + + // Assert + sut.Label.Should().BeEmpty(); + sut.MetaData.Should().BeEmpty(); + sut.Version.Should().BeEmpty(); + sut.OffSet.Should().Be(0); + sut.Branches.Should().NotBeNull(); + } + + [Fact] + public void Equals_GivenNull_ReturnsFalse() + { + // Arrange + var sut = new Configuration(); + + // Act + var result = sut.Equals(null); + + // Assert + result.Should().BeFalse(); + } + + public static string Thing => "this"; + + public static IEnumerable DifferInLabel() + { + yield return new[] { new Configuration(), new Configuration { Label = { "one" } } }; + yield return new[] { new Configuration { Label = { "one" } }, new Configuration() }; + yield return new[] { new Configuration { Label = { "one", "two" } }, new Configuration { Label = { "one", "three" } } }; + } + + [Theory] + [MemberData(nameof(DifferInLabel))] + public void Equals_DifferInLabel_ReturnsTrue(Configuration sut, Configuration other) + { + // Arrange / Act + var result = sut.Equals(other); + + // Assert + result.Should().BeFalse(); + } + } } diff --git a/test/SimpleVersion.Abstractions.Tests/Model/VersionResultFixture.cs b/test/SimpleVersion.Abstractions.Tests/Model/VersionResultFixture.cs index a5bde1b..837ed75 100644 --- a/test/SimpleVersion.Abstractions.Tests/Model/VersionResultFixture.cs +++ b/test/SimpleVersion.Abstractions.Tests/Model/VersionResultFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using Xunit; using FluentAssertions; @@ -6,58 +6,58 @@ namespace SimpleVersion.Abstractions.Tests.Model { - public class VersionResultFixture - { - [Fact] - public void Ctor_SetsDefaults() - { - // Arrange / Act - var sut = new VersionResult(); - - // Assert - sut.Version.Should().BeEmpty(); - sut.Major.Should().Be(0); - sut.Minor.Should().Be(0); - sut.Patch.Should().Be(0); - sut.Revision.Should().Be(0); - sut.Height.Should().Be(0); - sut.HeightPadded.Should().Be("0000"); - sut.Sha.Should().BeEmpty(); - sut.BranchName.Should().BeEmpty(); - sut.CanonicalBranchName.Should().BeEmpty(); - sut.Formats.Should().BeEmpty(); - } - - [Fact] - public void HeightPadded_Pads_Height() - { - // Arrange / Act - var sut = new VersionResult { Height = 40 }; - - // Assert - sut.HeightPadded.Should().Be("0040"); - } - - [Fact] - public void Formats_Has_CaseInsensitiveKeys() - { - // Arrange - var key = "This is the KEY"; - var value = "This is the value"; - var sut = new VersionResult - { - Formats = { - [key] = value - } - }; - - // Act - var upperResult = sut.Formats[key.ToUpper(System.Globalization.CultureInfo.CurrentCulture)]; - var lowerResult = sut.Formats[key.ToLower(System.Globalization.CultureInfo.CurrentCulture)]; - - // Assert - upperResult.Should().Be(value); - lowerResult.Should().Be(value); - } - } + public class VersionResultFixture + { + [Fact] + public void Ctor_SetsDefaults() + { + // Arrange / Act + var sut = new VersionResult(); + + // Assert + sut.Version.Should().BeEmpty(); + sut.Major.Should().Be(0); + sut.Minor.Should().Be(0); + sut.Patch.Should().Be(0); + sut.Revision.Should().Be(0); + sut.Height.Should().Be(0); + sut.HeightPadded.Should().Be("0000"); + sut.Sha.Should().BeEmpty(); + sut.BranchName.Should().BeEmpty(); + sut.CanonicalBranchName.Should().BeEmpty(); + sut.Formats.Should().BeEmpty(); + } + + [Fact] + public void HeightPadded_Pads_Height() + { + // Arrange / Act + var sut = new VersionResult { Height = 40 }; + + // Assert + sut.HeightPadded.Should().Be("0040"); + } + + [Fact] + public void Formats_Has_CaseInsensitiveKeys() + { + // Arrange + var key = "This is the KEY"; + var value = "This is the value"; + var sut = new VersionResult + { + Formats = { + [key] = value + } + }; + + // Act + var upperResult = sut.Formats[key.ToUpper(System.Globalization.CultureInfo.CurrentCulture)]; + var lowerResult = sut.Formats[key.ToLower(System.Globalization.CultureInfo.CurrentCulture)]; + + // Assert + upperResult.Should().Be(value); + lowerResult.Should().Be(value); + } + } } diff --git a/test/SimpleVersion.Abstractions.Tests/Pipeline/VersionContextFixture.cs b/test/SimpleVersion.Abstractions.Tests/Pipeline/VersionContextFixture.cs index 28ea475..91c76b0 100644 --- a/test/SimpleVersion.Abstractions.Tests/Pipeline/VersionContextFixture.cs +++ b/test/SimpleVersion.Abstractions.Tests/Pipeline/VersionContextFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -6,19 +6,19 @@ namespace SimpleVersion.Abstractions.Tests.Pipeline { - public class VersionContextFixture - { - [Fact] - public void Ctor_SetsDefaults() - { - // Arrange / Act - var sut = new VersionContext(); + public class VersionContextFixture + { + [Fact] + public void Ctor_SetsDefaults() + { + // Arrange / Act + var sut = new VersionContext(); - // Assert - sut.Path.Should().BeEmpty(); - sut.RepositoryPath.Should().BeEmpty(); - sut.Result.Should().NotBeNull(); - sut.Configuration.Should().NotBeNull(); - } - } + // Assert + sut.Path.Should().BeEmpty(); + sut.RepositoryPath.Should().BeEmpty(); + sut.Result.Should().NotBeNull(); + sut.Configuration.Should().NotBeNull(); + } + } } diff --git a/test/SimpleVersion.Abstractions.Tests/SimpleVersion.Abstractions.Tests.csproj b/test/SimpleVersion.Abstractions.Tests/SimpleVersion.Abstractions.Tests.csproj index 5d20700..936fc4d 100644 --- a/test/SimpleVersion.Abstractions.Tests/SimpleVersion.Abstractions.Tests.csproj +++ b/test/SimpleVersion.Abstractions.Tests/SimpleVersion.Abstractions.Tests.csproj @@ -1,8 +1,8 @@ - - - - - - + + + + + + diff --git a/test/SimpleVersion.Core.Tests/Comparers/ConfigurationVersionLabelComparerFixture.cs b/test/SimpleVersion.Core.Tests/Comparers/ConfigurationVersionLabelComparerFixture.cs index 9f314c7..2aa3d7d 100644 --- a/test/SimpleVersion.Core.Tests/Comparers/ConfigurationVersionLabelComparerFixture.cs +++ b/test/SimpleVersion.Core.Tests/Comparers/ConfigurationVersionLabelComparerFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Comparers; @@ -9,127 +9,127 @@ namespace SimpleVersion.Core.Tests.Comparers { - public class ConfigurationVersionLabelComparerFixture - { - private readonly ConfigurationVersionLabelComparer _sut; - - public ConfigurationVersionLabelComparerFixture() - { - _sut = new ConfigurationVersionLabelComparer(); - } - - public static IEnumerable Matching() - { - yield return new[] { new Configuration(), new Configuration() }; - yield return new[] { new Configuration { Label = { "one" } }, new Configuration { Label = { "one" } } }; - yield return new[] { new Configuration { Version= "1.2.3", Label = { "one", "two" } }, new Configuration { Version = "1.2.3", Label = { "one", "two" } } }; - } - - [Theory] - [MemberData(nameof(Matching))] - public void Equals_WithMatchingValues_ReturnsTrue(Configuration x, Configuration y) - { - // Arrange / Act - var result = _sut.Equals(x, y); - - // Assert - result.Should().BeTrue(); - } - - public static IEnumerable DifferInLabel() - { - yield return new[] { new Configuration(), new Configuration { Label = { "one" } } }; - yield return new[] { new Configuration { Label = { "one" } }, new Configuration() }; - yield return new[] { new Configuration { Label = { "one", "two" } }, new Configuration { Label = { "one", "three" } } }; - } - - [Theory] - [MemberData(nameof(DifferInLabel))] - public void Equals_DifferInLabel_ReturnsFalse(Configuration x, Configuration y) - { - // Arrange / Act - var result = _sut.Equals(x, y); - - // Assert - result.Should().BeFalse(); - } - - public static IEnumerable DifferInVersion() - { - yield return new[] { new Configuration(), new Configuration { Version = "1.2.3" } }; - yield return new[] { new Configuration { Version = "1.2.3" }, new Configuration() }; - yield return new[] { new Configuration { Version = "1.2.3" }, new Configuration { Version = "1.2.3.4" } }; - } - - [Theory] - [MemberData(nameof(DifferInVersion))] - public void Equals_DifferInVersion_ReturnsFalse(Configuration x, Configuration y) - { - // Arrange / Act - var result = _sut.Equals(x, y); - - // Assert - result.Should().BeFalse(); - } - - public static IEnumerable NullValues() - { - yield return new[] { new Configuration(), null }; - yield return new[] { null, new Configuration() }; - } - - [Theory] - [MemberData(nameof(NullValues))] - public void Equals_NullInstance_ReturnsFalse(Configuration x, Configuration y) - { - // Arrange / Act - var result = _sut.Equals(x, y); - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void GetHashCode_NullInstance_Throws() - { - // Arrange / Act - Action action = () => _sut.GetHashCode(null); - - // Assert - action.Should().Throw() - .And.ParamName.Should().Be("configuration"); - } - - [Fact] - public void GetHashCode_NullVersion_Throws() - { - // Arrange - var config = new Configuration { Version = null }; - - // Act - Action action = () => _sut.GetHashCode(config); - - // Assert - action.Should().Throw() - .And.ParamName.Should().Be("Version"); - } - - [Fact] - public void GetHashCode_Returns_Hashcode() - { - // Arrange - var config = new Configuration - { - Version = "1.2.3", - Label = { "hi" } - }; - var expected = config.Version.GetHashCode() * 17 + config.Label.GetHashCode(); - - // Arrange / Act - var result = _sut.GetHashCode(config); - - // Assert - result.Should().Be(expected); - } - } + public class ConfigurationVersionLabelComparerFixture + { + private readonly ConfigurationVersionLabelComparer _sut; + + public ConfigurationVersionLabelComparerFixture() + { + _sut = new ConfigurationVersionLabelComparer(); + } + + public static IEnumerable Matching() + { + yield return new[] { new Configuration(), new Configuration() }; + yield return new[] { new Configuration { Label = { "one" } }, new Configuration { Label = { "one" } } }; + yield return new[] { new Configuration { Version = "1.2.3", Label = { "one", "two" } }, new Configuration { Version = "1.2.3", Label = { "one", "two" } } }; + } + + [Theory] + [MemberData(nameof(Matching))] + public void Equals_WithMatchingValues_ReturnsTrue(Configuration x, Configuration y) + { + // Arrange / Act + var result = _sut.Equals(x, y); + + // Assert + result.Should().BeTrue(); + } + + public static IEnumerable DifferInLabel() + { + yield return new[] { new Configuration(), new Configuration { Label = { "one" } } }; + yield return new[] { new Configuration { Label = { "one" } }, new Configuration() }; + yield return new[] { new Configuration { Label = { "one", "two" } }, new Configuration { Label = { "one", "three" } } }; + } + + [Theory] + [MemberData(nameof(DifferInLabel))] + public void Equals_DifferInLabel_ReturnsFalse(Configuration x, Configuration y) + { + // Arrange / Act + var result = _sut.Equals(x, y); + + // Assert + result.Should().BeFalse(); + } + + public static IEnumerable DifferInVersion() + { + yield return new[] { new Configuration(), new Configuration { Version = "1.2.3" } }; + yield return new[] { new Configuration { Version = "1.2.3" }, new Configuration() }; + yield return new[] { new Configuration { Version = "1.2.3" }, new Configuration { Version = "1.2.3.4" } }; + } + + [Theory] + [MemberData(nameof(DifferInVersion))] + public void Equals_DifferInVersion_ReturnsFalse(Configuration x, Configuration y) + { + // Arrange / Act + var result = _sut.Equals(x, y); + + // Assert + result.Should().BeFalse(); + } + + public static IEnumerable NullValues() + { + yield return new[] { new Configuration(), null }; + yield return new[] { null, new Configuration() }; + } + + [Theory] + [MemberData(nameof(NullValues))] + public void Equals_NullInstance_ReturnsFalse(Configuration x, Configuration y) + { + // Arrange / Act + var result = _sut.Equals(x, y); + + // Assert + result.Should().BeFalse(); + } + + [Fact] + public void GetHashCode_NullInstance_Throws() + { + // Arrange / Act + Action action = () => _sut.GetHashCode(null); + + // Assert + action.Should().Throw() + .And.ParamName.Should().Be("configuration"); + } + + [Fact] + public void GetHashCode_NullVersion_Throws() + { + // Arrange + var config = new Configuration { Version = null }; + + // Act + Action action = () => _sut.GetHashCode(config); + + // Assert + action.Should().Throw() + .And.ParamName.Should().Be("Version"); + } + + [Fact] + public void GetHashCode_Returns_Hashcode() + { + // Arrange + var config = new Configuration + { + Version = "1.2.3", + Label = { "hi" } + }; + var expected = (config.Version.GetHashCode() * 17) + config.Label.GetHashCode(); + + // Arrange / Act + var result = _sut.GetHashCode(config); + + // Assert + result.Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/BuildServers/AzureDevopsProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/BuildServers/AzureDevopsProcessFixture.cs index 7b3ff48..14535f1 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/BuildServers/AzureDevopsProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/BuildServers/AzureDevopsProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using SimpleVersion.Pipeline.BuildServers; using System; @@ -13,65 +13,65 @@ namespace SimpleVersion.Core.Tests.Pipeline.BuildServers { - public class AzureDevopsProcessFixture - { - private readonly IEnvironment _env; - private AzureDevopsProcess _sut; + public class AzureDevopsProcessFixture + { + private readonly IEnvironment _env; + private readonly AzureDevopsProcess _sut; - public AzureDevopsProcessFixture() - { - _env = Substitute.For(); - _sut = new AzureDevopsProcess(_env); - } + public AzureDevopsProcessFixture() + { + _env = Substitute.For(); + _sut = new AzureDevopsProcess(_env); + } - [Fact] - public void Apply_NotAzure_DoesNotApply() - { - // Arrange - _env.GetVariable("TF_BUILD").Returns("False"); - var expectedBranchName = "BranchName"; - var expectedCanonicalBranchName = "CanonicalBranchName"; - var context = new VersionContext - { - Result = - { - BranchName = expectedBranchName, - CanonicalBranchName = expectedCanonicalBranchName - } - }; + [Fact] + public void Apply_NotAzure_DoesNotApply() + { + // Arrange + _env.GetVariable("TF_BUILD").Returns("False"); + var expectedBranchName = "BranchName"; + var expectedCanonicalBranchName = "CanonicalBranchName"; + var context = new VersionContext + { + Result = + { + BranchName = expectedBranchName, + CanonicalBranchName = expectedCanonicalBranchName + } + }; - // Act - _sut.Apply(context); + // Act + _sut.Apply(context); - // Assert - context.Result.BranchName.Should().Be(expectedBranchName); - context.Result.CanonicalBranchName.Should().Be(expectedCanonicalBranchName); - } + // Assert + context.Result.BranchName.Should().Be(expectedBranchName); + context.Result.CanonicalBranchName.Should().Be(expectedCanonicalBranchName); + } - [Theory] - [InlineData("refs/heads/master", "master")] - [InlineData("refs/heads/release/1.0/master", "release/1.0/master")] - [InlineData("refs/pull/10/merge", "pull/10/merge")] - public void Apply_IsAzure_DoesApply(string canonical, string name) - { - // Arrange - _env.GetVariable("TF_BUILD").Returns("True"); - _env.GetVariable("BUILD_SOURCEBRANCH").Returns(canonical); - var context = new VersionContext - { - Result = - { - BranchName = "Default Name", - CanonicalBranchName = "Default Canonical Name" - } - }; + [Theory] + [InlineData("refs/heads/master", "master")] + [InlineData("refs/heads/release/1.0/master", "release/1.0/master")] + [InlineData("refs/pull/10/merge", "pull/10/merge")] + public void Apply_IsAzure_DoesApply(string canonical, string name) + { + // Arrange + _env.GetVariable("TF_BUILD").Returns("True"); + _env.GetVariable("BUILD_SOURCEBRANCH").Returns(canonical); + var context = new VersionContext + { + Result = + { + BranchName = "Default Name", + CanonicalBranchName = "Default Canonical Name" + } + }; - // Act - _sut.Apply(context); + // Act + _sut.Apply(context); - // Assert - context.Result.BranchName.Should().Be(name); - context.Result.CanonicalBranchName.Should().Be(canonical); - } - } + // Assert + context.Result.BranchName.Should().Be(name); + context.Result.CanonicalBranchName.Should().Be(canonical); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver1FormatProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver1FormatProcessFixture.cs index 8c6b6a9..b61e54d 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver1FormatProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver1FormatProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using System; using System.Collections.Generic; @@ -9,73 +9,73 @@ namespace SimpleVersion.Core.Tests.Pipeline.Formatting { - public class Semver1FormatProcessFixture - { - private readonly Semver1FormatProcess _sut; + public class Semver1FormatProcessFixture + { + private readonly Semver1FormatProcess _sut; - public Semver1FormatProcessFixture() - { - _sut = new Semver1FormatProcess(); - } + public Semver1FormatProcessFixture() + { + _sut = new Semver1FormatProcess(); + } - public static IEnumerable LabelParts() - { - yield return new object[] { Array.Empty(), "1.2.0", 10, "1.2.0" }; - yield return new object[] { new[] { "one" }, "1.2.0", 10, "1.2.0-one-0010" }; - yield return new object[] { new[] { "one", "two" }, "1.2.0", 106, "1.2.0-one-two-0106" }; - yield return new object[] { new[] { "*", "one", "two" }, "1.2.0", 106, "1.2.0-0106-one-two" }; - yield return new object[] { new[] { "one", "*", "two" }, "1.2.0", 106, "1.2.0-one-0106-two" }; - } + public static IEnumerable LabelParts() + { + yield return new object[] { Array.Empty(), "1.2.0", 10, "1.2.0" }; + yield return new object[] { new[] { "one" }, "1.2.0", 10, "1.2.0-one-0010" }; + yield return new object[] { new[] { "one", "two" }, "1.2.0", 106, "1.2.0-one-two-0106" }; + yield return new object[] { new[] { "*", "one", "two" }, "1.2.0", 106, "1.2.0-0106-one-two" }; + yield return new object[] { new[] { "one", "*", "two" }, "1.2.0", 106, "1.2.0-one-0106-two" }; + } - [Theory] - [MemberData(nameof(LabelParts))] - public void Apply_LabelParts_NonRelease_Is_Formatted( - string[] parts, - string version, - int height, - string expectedPart) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, label: parts), - Result = Utils.GetVersionResult(height, false) - }; - context.Result.Version = context.Configuration.Version; + [Theory] + [MemberData(nameof(LabelParts))] + public void Apply_LabelParts_NonRelease_Is_Formatted( + string[] parts, + string version, + int height, + string expectedPart) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, label: parts), + Result = Utils.GetVersionResult(height, false) + }; + context.Result.Version = context.Configuration.Version; - var shaSub = context.Result.Sha.Substring(0, 7); - var fullExpected = $"{expectedPart}-c{shaSub}"; - - // Act - _sut.Apply(context); + var shaSub = context.Result.Sha.Substring(0, 7); + var fullExpected = $"{expectedPart}-c{shaSub}"; - // Assert - context.Result.Formats.Should().ContainKey("Semver1"); - context.Result.Formats["Semver1"].Should().Be(fullExpected); - } + // Act + _sut.Apply(context); - [Theory] - [MemberData(nameof(LabelParts))] - public void Apply_LabelParts_Release_Is_Formatted( - string[] parts, - string version, - int height, - string expected) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, label: parts), - Result = Utils.GetVersionResult(height, true) - }; - context.Result.Version = context.Configuration.Version; - - // Act - _sut.Apply(context); + // Assert + context.Result.Formats.Should().ContainKey("Semver1"); + context.Result.Formats["Semver1"].Should().Be(fullExpected); + } - // Assert - context.Result.Formats.Should().ContainKey("Semver1"); - context.Result.Formats["Semver1"].Should().Be(expected); - } - } + [Theory] + [MemberData(nameof(LabelParts))] + public void Apply_LabelParts_Release_Is_Formatted( + string[] parts, + string version, + int height, + string expected) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, label: parts), + Result = Utils.GetVersionResult(height, true) + }; + context.Result.Version = context.Configuration.Version; + + // Act + _sut.Apply(context); + + // Assert + context.Result.Formats.Should().ContainKey("Semver1"); + context.Result.Formats["Semver1"].Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver2FormatProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver2FormatProcessFixture.cs index 75c7029..4b6063a 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver2FormatProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/Semver2FormatProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,148 +9,148 @@ namespace SimpleVersion.Core.Tests.Pipeline.Formatting { - public class Semver2FormatProcessFixture - { - private readonly Semver2FormatProcess _sut; - - public Semver2FormatProcessFixture() - { - _sut = new Semver2FormatProcess(); - } - - public static IEnumerable LabelParts() - { - return new List - { - new object[] { Array.Empty(), "1.2.0", 10 }, - new object[] { new[] { "one" }, "1.2.0", 10 }, - new object[] { new[] { "one", "two" }, "1.2.0", 106 } - }; - } - - [Theory] - [MemberData(nameof(LabelParts))] - public void Apply_LabelParts_NonRelease_Is_Formatted( - string[] parts, - string version, - int height) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, label: parts), - Result = Utils.GetVersionResult(height, false) - }; - context.Result.Version = context.Configuration.Version; - - string expected; - if (parts.Length > 0) - expected = $"{version}-{string.Join(".", parts)}.{height}.c4ca82d2"; - else - expected = $"{version}-c4ca82d2"; - - // Act - _sut.Apply(context); - - // Assert - context.Result.Formats.Should().ContainKey("Semver2"); - context.Result.Formats["Semver2"].Should().Be(expected); - } - - - [Theory] - [MemberData(nameof(LabelParts))] - public void Apply_LabelParts_Release_Is_Formatted( - string[] parts, - string version, - int height) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, parts), - Result = Utils.GetVersionResult(height) - }; - context.Result.Version = context.Configuration.Version; - - string expected; - if (parts.Length > 0) - expected = $"{version}-{string.Join(".", parts)}.{height}"; - else - expected = $"{version}"; - - // Act - _sut.Apply(context); - - // Assert - context.Result.Formats.Should().ContainKey("Semver2"); - context.Result.Formats["Semver2"].Should().Be(expected); - } - - public static IEnumerable MetaDataParts() - { - yield return new object[] { Array.Empty(), "1.2.0", 10 }; - yield return new object[] { new[] { "one" }, "1.2.0", 10 }; - yield return new object[] { new[] { "one", "two" }, "1.2.0", 106 }; - } - - [Theory] - [MemberData(nameof(MetaDataParts))] - public void Apply_MetaDataParts_NonRelease_Is_Formatted( - string[] parts, - string version, - int height) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, meta: parts), - Result = Utils.GetVersionResult(height, false) - }; - context.Result.Version = context.Configuration.Version; - - string expected; - if (parts.Length > 0) - expected = $"{version}-c4ca82d2+{string.Join(".", parts)}"; - else - expected = $"{version}-c4ca82d2"; - - // Act - _sut.Apply(context); - - // Assert - context.Result.Formats.Should().ContainKey("Semver2"); - context.Result.Formats["Semver2"].Should().Be(expected); - } - - [Theory] - [MemberData(nameof(MetaDataParts))] - public void Apply_MetaDataParts_Release_Is_Formatted( - string[] parts, - string version, - int height) - { - - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration(version, meta: parts), - Result = Utils.GetVersionResult(height) - }; - context.Result.Version = context.Configuration.Version; - - string expected; - if (parts.Length > 0) - expected = $"{version}+{string.Join(".", parts)}"; - else - expected = $"{version}"; - - // Act - _sut.Apply(context); - - // Assert - context.Result.Formats.Should().ContainKey("Semver2"); - context.Result.Formats["Semver2"].Should().Be(expected); - } - } + public class Semver2FormatProcessFixture + { + private readonly Semver2FormatProcess _sut; + + public Semver2FormatProcessFixture() + { + _sut = new Semver2FormatProcess(); + } + + public static IEnumerable LabelParts() + { + return new List + { + new object[] { Array.Empty(), "1.2.0", 10 }, + new object[] { new[] { "one" }, "1.2.0", 10 }, + new object[] { new[] { "one", "two" }, "1.2.0", 106 } + }; + } + + [Theory] + [MemberData(nameof(LabelParts))] + public void Apply_LabelParts_NonRelease_Is_Formatted( + string[] parts, + string version, + int height) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, label: parts), + Result = Utils.GetVersionResult(height, false) + }; + context.Result.Version = context.Configuration.Version; + + string expected; + if (parts.Length > 0) + expected = $"{version}-{string.Join(".", parts)}.{height}.c4ca82d2"; + else + expected = $"{version}-c4ca82d2"; + + // Act + _sut.Apply(context); + + // Assert + context.Result.Formats.Should().ContainKey("Semver2"); + context.Result.Formats["Semver2"].Should().Be(expected); + } + + + [Theory] + [MemberData(nameof(LabelParts))] + public void Apply_LabelParts_Release_Is_Formatted( + string[] parts, + string version, + int height) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, parts), + Result = Utils.GetVersionResult(height) + }; + context.Result.Version = context.Configuration.Version; + + string expected; + if (parts.Length > 0) + expected = $"{version}-{string.Join(".", parts)}.{height}"; + else + expected = $"{version}"; + + // Act + _sut.Apply(context); + + // Assert + context.Result.Formats.Should().ContainKey("Semver2"); + context.Result.Formats["Semver2"].Should().Be(expected); + } + + public static IEnumerable MetaDataParts() + { + yield return new object[] { Array.Empty(), "1.2.0", 10 }; + yield return new object[] { new[] { "one" }, "1.2.0", 10 }; + yield return new object[] { new[] { "one", "two" }, "1.2.0", 106 }; + } + + [Theory] + [MemberData(nameof(MetaDataParts))] + public void Apply_MetaDataParts_NonRelease_Is_Formatted( + string[] parts, + string version, + int height) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, meta: parts), + Result = Utils.GetVersionResult(height, false) + }; + context.Result.Version = context.Configuration.Version; + + string expected; + if (parts.Length > 0) + expected = $"{version}-c4ca82d2+{string.Join(".", parts)}"; + else + expected = $"{version}-c4ca82d2"; + + // Act + _sut.Apply(context); + + // Assert + context.Result.Formats.Should().ContainKey("Semver2"); + context.Result.Formats["Semver2"].Should().Be(expected); + } + + [Theory] + [MemberData(nameof(MetaDataParts))] + public void Apply_MetaDataParts_Release_Is_Formatted( + string[] parts, + string version, + int height) + { + + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration(version, meta: parts), + Result = Utils.GetVersionResult(height) + }; + context.Result.Version = context.Configuration.Version; + + string expected; + if (parts.Length > 0) + expected = $"{version}+{string.Join(".", parts)}"; + else + expected = $"{version}"; + + // Act + _sut.Apply(context); + + // Assert + context.Result.Formats.Should().ContainKey("Semver2"); + context.Result.Formats["Semver2"].Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/VersionFormatProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/VersionFormatProcessFixture.cs index 04dc845..803f0a8 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/Formatting/VersionFormatProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/Formatting/VersionFormatProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,121 +9,121 @@ namespace SimpleVersion.Core.Tests.Pipeline.Formatting { - public class VersionFormatProcessFixture - { - private readonly VersionFormatProcess _sut; + public class VersionFormatProcessFixture + { + private readonly VersionFormatProcess _sut; - public VersionFormatProcessFixture() - { - _sut = new VersionFormatProcess(); - } + public VersionFormatProcessFixture() + { + _sut = new VersionFormatProcess(); + } - public static IEnumerable InvalidVersions() - { - yield return new[] { "1" }; - yield return new[] { "1.2.=" }; - yield return new[] { "1.l.4" }; - yield return new[] { "*.l.5" }; - } + public static IEnumerable InvalidVersions() + { + yield return new[] { "1" }; + yield return new[] { "1.2.=" }; + yield return new[] { "1.l.4" }; + yield return new[] { "*.l.5" }; + } - [Theory] - [MemberData(nameof(InvalidVersions))] - public void Apply_InvalidVersion_Throws(string version) - { - // Arrange - var context = new VersionContext - { - Configuration = { - Version = version - } - }; + [Theory] + [MemberData(nameof(InvalidVersions))] + public void Apply_InvalidVersion_Throws(string version) + { + // Arrange + var context = new VersionContext + { + Configuration = { + Version = version + } + }; - // Act - Action action = () => _sut.Apply(context); + // Act + Action action = () => _sut.Apply(context); - // Asset - action.Should().Throw() - .WithMessage($"Version '{context.Configuration.Version}' is not in a valid format"); - } + // Asset + action.Should().Throw() + .WithMessage($"Version '{context.Configuration.Version}' is not in a valid format"); + } - public static IEnumerable ValidVersions() - { - yield return new object[] { "1.0", "1.0.0", 1, 0, 0, 0 }; - yield return new object[] { "1.0.0", "1.0.0", 1, 0, 0, 0 }; - yield return new object[] { "1.2.0", "1.2.0", 1, 2, 0, 0 }; - yield return new object[] { "1.2.3", "1.2.3", 1, 2, 3, 0 }; - yield return new object[] { "14.22.32.234", "14.22.32.234", 14, 22, 32, 234 }; - } + public static IEnumerable ValidVersions() + { + yield return new object[] { "1.0", "1.0.0", 1, 0, 0, 0 }; + yield return new object[] { "1.0.0", "1.0.0", 1, 0, 0, 0 }; + yield return new object[] { "1.2.0", "1.2.0", 1, 2, 0, 0 }; + yield return new object[] { "1.2.3", "1.2.3", 1, 2, 3, 0 }; + yield return new object[] { "14.22.32.234", "14.22.32.234", 14, 22, 32, 234 }; + } - [Theory] - [MemberData(nameof(ValidVersions))] - public void Apply_ValidVersions_SetsMembers( - string version, - string expectedVersion, - int major, - int minor, - int patch, - int revision) - { - // Arrange - // Arrange - var context = new VersionContext - { - Configuration = { - Version = version - } - }; + [Theory] + [MemberData(nameof(ValidVersions))] + public void Apply_ValidVersions_SetsMembers( + string version, + string expectedVersion, + int major, + int minor, + int patch, + int revision) + { + // Arrange + // Arrange + var context = new VersionContext + { + Configuration = { + Version = version + } + }; - // Act - _sut.Apply(context); + // Act + _sut.Apply(context); - // Assert - context.Result.Version.Should().Be(expectedVersion); - context.Result.Major.Should().Be(major); - context.Result.Minor.Should().Be(minor); - context.Result.Patch.Should().Be(patch); - context.Result.Revision.Should().Be(revision); + // Assert + context.Result.Version.Should().Be(expectedVersion); + context.Result.Major.Should().Be(major); + context.Result.Minor.Should().Be(minor); + context.Result.Patch.Should().Be(patch); + context.Result.Revision.Should().Be(revision); - } + } - [Theory] - [InlineData("1.0", "1.0.0", 10, 1, 0, 0, 0)] - [InlineData("1.0.0", "1.0.0", 10, 1, 0, 0, 0)] - [InlineData("1.0.0.0", "1.0.0.0", 10, 1, 0, 0, 0)] - [InlineData("1.*", "1.10.0", 10, 1, 10, 0, 0)] - [InlineData("1.0.*", "1.0.10", 10, 1, 0, 10, 0)] - [InlineData("1.0.0.*", "1.0.0.10", 10, 1, 0, 0, 10)] - [InlineData("1.*.0", "1.10.0", 10, 1, 10, 0, 0)] - [InlineData("1.0.*.0", "1.0.10.0", 10, 1, 0, 10, 0)] - public void Height_In_Version( - string version, - string expectedVersion, - int commits, - int major, - int minor, - int patch, - int revision) - { - // Arrange - var context = new VersionContext - { - Configuration = { - Version = version - }, - Result = { - Height = commits - } - }; + [Theory] + [InlineData("1.0", "1.0.0", 10, 1, 0, 0, 0)] + [InlineData("1.0.0", "1.0.0", 10, 1, 0, 0, 0)] + [InlineData("1.0.0.0", "1.0.0.0", 10, 1, 0, 0, 0)] + [InlineData("1.*", "1.10.0", 10, 1, 10, 0, 0)] + [InlineData("1.0.*", "1.0.10", 10, 1, 0, 10, 0)] + [InlineData("1.0.0.*", "1.0.0.10", 10, 1, 0, 0, 10)] + [InlineData("1.*.0", "1.10.0", 10, 1, 10, 0, 0)] + [InlineData("1.0.*.0", "1.0.10.0", 10, 1, 0, 10, 0)] + public void Height_In_Version( + string version, + string expectedVersion, + int commits, + int major, + int minor, + int patch, + int revision) + { + // Arrange + var context = new VersionContext + { + Configuration = { + Version = version + }, + Result = { + Height = commits + } + }; - // Act - _sut.Apply(context); + // Act + _sut.Apply(context); - // Assert - context.Result.Version.Should().Be(expectedVersion); - context.Result.Major.Should().Be(major); - context.Result.Minor.Should().Be(minor); - context.Result.Patch.Should().Be(patch); - context.Result.Revision.Should().Be(revision); - } - } + // Assert + context.Result.Version.Should().Be(expectedVersion); + context.Result.Major.Should().Be(major); + context.Result.Minor.Should().Be(minor); + context.Result.Patch.Should().Be(patch); + context.Result.Revision.Should().Be(revision); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/ResolveConfigurationProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/ResolveConfigurationProcessFixture.cs index 20db3f7..f8dc21c 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/ResolveConfigurationProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/ResolveConfigurationProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using GitTools.Testing; @@ -11,423 +11,423 @@ namespace SimpleVersion.Core.Tests.Pipeline { - public class ResolveConfigurationProcessFixture - { - private readonly ResolveConfigurationProcess _sut; - - public ResolveConfigurationProcessFixture() - { - _sut = new ResolveConfigurationProcess(); - } - - [Fact] - public void Apply_NullContext_Throws() - { - // Arrange / Act - Action action = () => _sut.Apply(null); - - // Assert - action.Should().Throw() - .And.ParamName.Should().Be("context"); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" \t\t")] - public void Apply_InvalidRepositoryPath_Throws(string path) - { - // Arrange - var context = new VersionContext { RepositoryPath = path }; - - // Act - Action action = () => _sut.Apply(context); - - // Assert - action.Should().Throw(); - } - - [Fact] - public void Apply_NoCommits_ShouldThrow() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // Act - Action action = () => _sut.Apply(context); - - // Assert - action.Should().Throw() - .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); - } - } - - [Fact] - public void Apply_CommitsForFile_ShouldThrow() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - fixture.MakeACommit(); - fixture.MakeACommit(); - fixture.MakeACommit(); - - // Act - Action action = () => _sut.Apply(context); - - // Assert - action.Should().Throw() - .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); - } - } - - [Fact] - public void Apply_First_Commit_Height_Is_One() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); - - // Act - _sut.Apply(context); - - // Assert - context.Result.Height.Should().Be(1); - } - } - - [Fact] - public void Apply_Single_Branch_Increments_Each_Commit() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - // Act - _sut.Apply(context); - - // Assert - context.Result.Height.Should().Be(5); - } - } - - [Fact] - public void Apply_Modfied_No_Version_Or_Label_Changes_Does_Not_Reset() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - config.MetaData.Add("example"); - Utils.WriteConfiguration(config, fixture); // 6 - - // Act - _sut.Apply(context); - - // Assert - context.Result.Height.Should().Be(6); - } - } - - [Fact] - public void Apply_Feature_Branch_No_Change_Increments_Merge_Once() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - fixture.BranchTo("feature/other"); - fixture.MakeACommit(); // feature 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - fixture.Checkout("master"); - fixture.MergeNoFF("feature/other"); // 6 - - // Act - _sut.Apply(context); - - context.Result.Height.Should().Be(6); - } - } - - [Fact] - public void Apply_Feature_Branch_Changes_Version_Resets_On_Merge() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - fixture.BranchTo("feature/other"); - fixture.MakeACommit(); // feature 1 - config.Version = "0.1.1"; - Utils.WriteConfiguration(config, fixture); // 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - fixture.Checkout("master"); - fixture.MergeNoFF("feature/other"); // 1 - - // Act - _sut.Apply(context); - - // Assert - context.Result.Height.Should().Be(1); - } - } - - [Fact] - public void Apply_Feature_Branch_Changes_Version_Resets_On_Each_Merge() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - fixture.BranchTo("feature/other"); - fixture.MakeACommit(); // feature 1 - config.Version = "0.1.1"; - Utils.WriteConfiguration(config, fixture); // 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - fixture.Checkout("master"); - fixture.MergeNoFF("feature/other"); // 1 - - fixture.Checkout("feature/other"); - fixture.MakeACommit(); // feature 1 - config.Version = "0.1.2"; - Utils.WriteConfiguration(config, fixture); // 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - fixture.Checkout("master"); - fixture.MergeNoFF("feature/other"); // 1 - - // Act - _sut.Apply(context); - - // Assert - context.Result.Height.Should().Be(1); - } - } - - [Fact] - public void Apply_Feature_Branch_Sets_BranchName() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - fixture.BranchTo("feature/other"); - fixture.MakeACommit(); // feature 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - // Act - _sut.Apply(context); - - context.Result.BranchName.Should().Be("feature/other"); - context.Result.CanonicalBranchName.Should().Be("refs/heads/feature/other"); - } - } - - [Fact] - public void Apply_BranchOverride_AppliesOverride() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - var expectedLabel = new List { "{branchName}" }; - var expectedMeta = new List { "meta" }; - - // write the version file - var config = new Configuration - { - Version = "0.1.0", - Branches = { - Overrides = { - new BranchConfiguration - { - Match = "feature/other", - Label = expectedLabel, - MetaData = expectedMeta - } - } - } - }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - fixture.MakeACommit(); // 5 - - fixture.BranchTo("feature/other"); - fixture.MakeACommit(); // feature 1 - fixture.MakeACommit(); // feature 2 - fixture.MakeACommit(); // feature 3 - - // Act - _sut.Apply(context); - - context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering()); - context.Configuration.MetaData.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering()); - } - } + public class ResolveConfigurationProcessFixture + { + private readonly ResolveConfigurationProcess _sut; + + public ResolveConfigurationProcessFixture() + { + _sut = new ResolveConfigurationProcess(); + } + + [Fact] + public void Apply_NullContext_Throws() + { + // Arrange / Act + Action action = () => _sut.Apply(null); + + // Assert + action.Should().Throw() + .And.ParamName.Should().Be("context"); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" \t\t")] + public void Apply_InvalidRepositoryPath_Throws(string path) + { + // Arrange + var context = new VersionContext { RepositoryPath = path }; + + // Act + Action action = () => _sut.Apply(context); + + // Assert + action.Should().Throw(); + } + + [Fact] + public void Apply_NoCommits_ShouldThrow() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // Act + Action action = () => _sut.Apply(context); + + // Assert + action.Should().Throw() + .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); + } + } + + [Fact] + public void Apply_CommitsForFile_ShouldThrow() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + fixture.MakeACommit(); + fixture.MakeACommit(); + fixture.MakeACommit(); + + // Act + Action action = () => _sut.Apply(context); + + // Assert + action.Should().Throw() + .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); + } + } + + [Fact] + public void Apply_First_Commit_Height_Is_One() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); + + // Act + _sut.Apply(context); + + // Assert + context.Result.Height.Should().Be(1); + } + } + + [Fact] + public void Apply_Single_Branch_Increments_Each_Commit() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + // Act + _sut.Apply(context); + + // Assert + context.Result.Height.Should().Be(5); + } + } + + [Fact] + public void Apply_Modfied_No_Version_Or_Label_Changes_Does_Not_Reset() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + config.MetaData.Add("example"); + Utils.WriteConfiguration(config, fixture); // 6 + + // Act + _sut.Apply(context); + + // Assert + context.Result.Height.Should().Be(6); + } + } + + [Fact] + public void Apply_Feature_Branch_No_Change_Increments_Merge_Once() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + fixture.BranchTo("feature/other"); + fixture.MakeACommit(); // feature 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + fixture.Checkout("master"); + fixture.MergeNoFF("feature/other"); // 6 + + // Act + _sut.Apply(context); + + context.Result.Height.Should().Be(6); + } + } + + [Fact] + public void Apply_Feature_Branch_Changes_Version_Resets_On_Merge() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + fixture.BranchTo("feature/other"); + fixture.MakeACommit(); // feature 1 + config.Version = "0.1.1"; + Utils.WriteConfiguration(config, fixture); // 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + fixture.Checkout("master"); + fixture.MergeNoFF("feature/other"); // 1 + + // Act + _sut.Apply(context); + + // Assert + context.Result.Height.Should().Be(1); + } + } + + [Fact] + public void Apply_Feature_Branch_Changes_Version_Resets_On_Each_Merge() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + fixture.BranchTo("feature/other"); + fixture.MakeACommit(); // feature 1 + config.Version = "0.1.1"; + Utils.WriteConfiguration(config, fixture); // 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + fixture.Checkout("master"); + fixture.MergeNoFF("feature/other"); // 1 + + fixture.Checkout("feature/other"); + fixture.MakeACommit(); // feature 1 + config.Version = "0.1.2"; + Utils.WriteConfiguration(config, fixture); // 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + fixture.Checkout("master"); + fixture.MergeNoFF("feature/other"); // 1 + + // Act + _sut.Apply(context); + + // Assert + context.Result.Height.Should().Be(1); + } + } + + [Fact] + public void Apply_Feature_Branch_Sets_BranchName() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + fixture.BranchTo("feature/other"); + fixture.MakeACommit(); // feature 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + // Act + _sut.Apply(context); + + context.Result.BranchName.Should().Be("feature/other"); + context.Result.CanonicalBranchName.Should().Be("refs/heads/feature/other"); + } + } + + [Fact] + public void Apply_BranchOverride_AppliesOverride() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + var expectedLabel = new List { "{branchName}" }; + var expectedMeta = new List { "meta" }; + + // write the version file + var config = new Configuration + { + Version = "0.1.0", + Branches = { + Overrides = { + new BranchConfiguration + { + Match = "feature/other", + Label = expectedLabel, + MetaData = expectedMeta + } + } + } + }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + fixture.MakeACommit(); // 5 + + fixture.BranchTo("feature/other"); + fixture.MakeACommit(); // feature 1 + fixture.MakeACommit(); // feature 2 + fixture.MakeACommit(); // feature 3 + + // Act + _sut.Apply(context); + + context.Configuration.Label.Should().BeEquivalentTo(expectedLabel, options => options.WithStrictOrdering()); + context.Configuration.MetaData.Should().BeEquivalentTo(expectedMeta, options => options.WithStrictOrdering()); + } + } + + [Fact] + public void Apply_Malformed_Json_At_Commit_Throws() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file (Well formaed) + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + + + // Write the version file (with parsing errors) + var file = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); + using (var writer = File.AppendText(file)) + { + writer.WriteLine("This will not parse"); + writer.Flush(); + } + + fixture.Repository.Index.Add(Constants.VersionFileName); + fixture.Repository.Index.Write(); + fixture.MakeACommit(); // 5 + fixture.MakeACommit(); // 6 + fixture.MakeACommit(); // 7 + fixture.MakeACommit(); // 8 + + // Act + Action action = () => _sut.Apply(context); + + // Assert + action.Should().Throw() + .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); + } + } [Fact] - public void Apply_Malformed_Json_At_Commit_Throws() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file (Well formaed) - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - - - // Write the version file (with parsing errors) - var file = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); - using (var writer = File.AppendText(file)) - { - writer.WriteLine("This will not parse"); - writer.Flush(); - } - - fixture.Repository.Index.Add(Constants.VersionFileName); - fixture.Repository.Index.Write(); - fixture.MakeACommit(); // 5 - fixture.MakeACommit(); // 6 - fixture.MakeACommit(); // 7 - fixture.MakeACommit(); // 8 - - // Act - Action action = () => _sut.Apply(context); - - // Assert - action.Should().Throw() - .WithMessage($"Could not read '{Constants.VersionFileName}', has it been committed?"); - } - } - - [Fact] - public void Apply_Malformed_Json_Committed_Counts_As_No_Change() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; - - // write the version file (Well formaed) - var config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 1 - - fixture.MakeACommit(); // 2 - fixture.MakeACommit(); // 3 - fixture.MakeACommit(); // 4 - - - // Write the version file (with parsing errors) - var file = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); - - using (var writer = File.AppendText(file)) - { - writer.WriteLine("This will not parse"); - writer.Flush(); - } - - fixture.Repository.Index.Add(Constants.VersionFileName); - fixture.Repository.Index.Write(); - fixture.MakeACommit(); // 5 - fixture.MakeACommit(); // 6 - fixture.MakeACommit(); // 7 - fixture.MakeACommit(); // 8 - - config = new Configuration { Version = "0.1.0" }; - Utils.WriteConfiguration(config, fixture); // 9 - - // Act - _sut.Apply(context); - - context.Result.Height.Should().Be(9); - } - } - } + public void Apply_Malformed_Json_Committed_Counts_As_No_Change() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { RepositoryPath = fixture.RepositoryPath }; + + // write the version file (Well formaed) + var config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 1 + + fixture.MakeACommit(); // 2 + fixture.MakeACommit(); // 3 + fixture.MakeACommit(); // 4 + + + // Write the version file (with parsing errors) + var file = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); + + using (var writer = File.AppendText(file)) + { + writer.WriteLine("This will not parse"); + writer.Flush(); + } + + fixture.Repository.Index.Add(Constants.VersionFileName); + fixture.Repository.Index.Write(); + fixture.MakeACommit(); // 5 + fixture.MakeACommit(); // 6 + fixture.MakeACommit(); // 7 + fixture.MakeACommit(); // 8 + + config = new Configuration { Version = "0.1.0" }; + Utils.WriteConfiguration(config, fixture); // 9 + + // Act + _sut.Apply(context); + + context.Result.Height.Should().Be(9); + } + } + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/ResolveRepositoryPathProcessFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/ResolveRepositoryPathProcessFixture.cs index d03aee5..09efa2a 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/ResolveRepositoryPathProcessFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/ResolveRepositoryPathProcessFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using GitTools.Testing; @@ -13,91 +13,91 @@ namespace SimpleVersion.Core.Tests.Pipeline { - public class ResolveRepositoryPathProcessFixture - { - private readonly ResolveRepositoryPathProcess _sut; - - public ResolveRepositoryPathProcessFixture() - { - _sut = new ResolveRepositoryPathProcess(); - } - - [Fact] - public void Apply_NullContext_Throws() - { - // Arrange / Act - Action action = () => _sut.Apply(null); - - // Assert - action.Should().Throw() - .And.ParamName.Should().Be("context"); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData("\t\t ")] - public void Apply_EmptyOrNullContextPath_Throws(string path) - { - // Arrange / Act - Action action = () => _sut.Apply(new VersionContext { Path = path }); - - // Assert - action.Should().Throw(); - } - - - public static IEnumerable InvalidPaths() - { - yield return new[] { Environment.GetLogicalDrives()[0] }; - yield return new[] { Path.Combine(Directory.GetCurrentDirectory(), "does not exist") }; - } - - [Theory] - [MemberData(nameof(InvalidPaths))] - public void Apply_InvalidContextPath_Throws(string path) - { - // Arrange / Act - Action action = () => _sut.Apply(new VersionContext { Path = path }); - - // Assert - action.Should().Throw() - .And.Message.Should().Be($"Could not find git repository at '{path}' or any parent directory"); - - } - - [Fact] - public void Apply_WithRootPath_ReturnsRootPath() - { - using(var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var context = new VersionContext { Path = fixture.RepositoryPath }; - - // Act - _sut.Apply(context); - - // Assert - context.RepositoryPath.Should().Be(fixture.RepositoryPath); - } - } - - [Fact] - public void Apply_DescendantPath_ReturnsRootPath() - { - using (var fixture = new EmptyRepositoryFixture()) - { - // Arrange - var dir = Directory.CreateDirectory(Path.Combine(fixture.RepositoryPath, "alpha", "beta")); - var context = new VersionContext { Path = dir.FullName }; - - // Act - _sut.Apply(context); - - // Assert - context.RepositoryPath.Should().Be(fixture.RepositoryPath); - } - } - - } + public class ResolveRepositoryPathProcessFixture + { + private readonly ResolveRepositoryPathProcess _sut; + + public ResolveRepositoryPathProcessFixture() + { + _sut = new ResolveRepositoryPathProcess(); + } + + [Fact] + public void Apply_NullContext_Throws() + { + // Arrange / Act + Action action = () => _sut.Apply(null); + + // Assert + action.Should().Throw() + .And.ParamName.Should().Be("context"); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("\t\t ")] + public void Apply_EmptyOrNullContextPath_Throws(string path) + { + // Arrange / Act + Action action = () => _sut.Apply(new VersionContext { Path = path }); + + // Assert + action.Should().Throw(); + } + + + public static IEnumerable InvalidPaths() + { + yield return new[] { Environment.GetLogicalDrives()[0] }; + yield return new[] { Path.Combine(Directory.GetCurrentDirectory(), "does not exist") }; + } + + [Theory] + [MemberData(nameof(InvalidPaths))] + public void Apply_InvalidContextPath_Throws(string path) + { + // Arrange / Act + Action action = () => _sut.Apply(new VersionContext { Path = path }); + + // Assert + action.Should().Throw() + .And.Message.Should().Be($"Could not find git repository at '{path}' or any parent directory"); + + } + + [Fact] + public void Apply_WithRootPath_ReturnsRootPath() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var context = new VersionContext { Path = fixture.RepositoryPath }; + + // Act + _sut.Apply(context); + + // Assert + context.RepositoryPath.Should().Be(fixture.RepositoryPath); + } + } + + [Fact] + public void Apply_DescendantPath_ReturnsRootPath() + { + using (var fixture = new EmptyRepositoryFixture()) + { + // Arrange + var dir = Directory.CreateDirectory(Path.Combine(fixture.RepositoryPath, "alpha", "beta")); + var context = new VersionContext { Path = dir.FullName }; + + // Act + _sut.Apply(context); + + // Assert + context.RepositoryPath.Should().Be(fixture.RepositoryPath); + } + } + + } } diff --git a/test/SimpleVersion.Core.Tests/Pipeline/VersionCalculatorFixture.cs b/test/SimpleVersion.Core.Tests/Pipeline/VersionCalculatorFixture.cs index 20e88e7..6eb9fcc 100644 --- a/test/SimpleVersion.Core.Tests/Pipeline/VersionCalculatorFixture.cs +++ b/test/SimpleVersion.Core.Tests/Pipeline/VersionCalculatorFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Model; @@ -7,26 +7,26 @@ namespace SimpleVersion.Core.Tests.Pipeline { - public class VersionCalculatorFixture - { - private readonly VersionCalculator _sut; + public class VersionCalculatorFixture + { + private readonly VersionCalculator _sut; - public VersionCalculatorFixture() - { - _sut = new VersionCalculator(); - } + public VersionCalculatorFixture() + { + _sut = new VersionCalculator(); + } - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" \t\t")] - public void GetResult_EmptyPath_ReturnsResult(string path) - { - // Arrange / Act - var result = _sut.GetResult(path); + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" \t\t")] + public void GetResult_EmptyPath_ReturnsResult(string path) + { + // Arrange / Act + var result = _sut.GetResult(path); - // Assert - result.Should().BeEquivalentTo(new VersionResult()); - } - } + // Assert + result.Should().BeEquivalentTo(new VersionResult()); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Rules/BranchNameRuleFixture.cs b/test/SimpleVersion.Core.Tests/Rules/BranchNameRuleFixture.cs index 06e83b6..e47b100 100644 --- a/test/SimpleVersion.Core.Tests/Rules/BranchNameRuleFixture.cs +++ b/test/SimpleVersion.Core.Tests/Rules/BranchNameRuleFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,83 +9,83 @@ namespace SimpleVersion.Core.Tests.Rules { - public class BranchNameRuleFixture - { - [Fact] - public void Instance_SetsDefaults() - { - // Arrange / Act - var sut = BranchNameRule.Instance; + public class BranchNameRuleFixture + { + [Fact] + public void Instance_SetsDefaults() + { + // Arrange / Act + var sut = BranchNameRule.Instance; - // Assert - sut.Pattern.Should().NotBeNull(); - sut.Token.Should().Be("{branchname}"); - } + // Assert + sut.Pattern.Should().NotBeNull(); + sut.Token.Should().Be("{branchname}"); + } - public static IEnumerable ApplyData() - { - yield return new object[] { null, null }; - yield return new object[] { null, Array.Empty() }; - yield return new object[] { new VersionContext(), new[] { "this" } }; - } + public static IEnumerable ApplyData() + { + yield return new object[] { null, null }; + yield return new object[] { null, Array.Empty() }; + yield return new object[] { new VersionContext(), new[] { "this" } }; + } - [Theory] - [MemberData(nameof(ApplyData))] - public void Apply_Returns_Input(VersionContext context, IEnumerable input) - { - // Arrange - var sut = new BranchNameRule(); + [Theory] + [MemberData(nameof(ApplyData))] + public void Apply_Returns_Input(VersionContext context, IEnumerable input) + { + // Arrange + var sut = new BranchNameRule(); - // Act - var result = sut.Apply(context, input); + // Act + var result = sut.Apply(context, input); - // Assert - result.Should().BeSameAs(input); - } - - [Theory] - [InlineData("refs/heads/master", "{branchName}", "refsheadsmaster")] - [InlineData("refs/heads/master", "{BRANCHNAME}", "refsheadsmaster")] - [InlineData("refs/heads/release/1.0", "{BRANCHNAME}", "refsheadsrelease10")] - [InlineData("refs/heads/release-1.0", "{BRANCHNAME}", "refsheadsrelease10")] - public void Resolve_Replaces_CanonicalBranchName(string branchName, string input, string expected) - { - // Arrange - var sut = new BranchNameRule(); - var context = new VersionContext - { - Result = - { - CanonicalBranchName = branchName - } - }; + // Assert + result.Should().BeSameAs(input); + } - // Act - var result = sut.Resolve(context, input); + [Theory] + [InlineData("refs/heads/master", "{branchName}", "refsheadsmaster")] + [InlineData("refs/heads/master", "{BRANCHNAME}", "refsheadsmaster")] + [InlineData("refs/heads/release/1.0", "{BRANCHNAME}", "refsheadsrelease10")] + [InlineData("refs/heads/release-1.0", "{BRANCHNAME}", "refsheadsrelease10")] + public void Resolve_Replaces_CanonicalBranchName(string branchName, string input, string expected) + { + // Arrange + var sut = new BranchNameRule(); + var context = new VersionContext + { + Result = + { + CanonicalBranchName = branchName + } + }; - // Assert - result.Should().Be(expected); - } + // Act + var result = sut.Resolve(context, input); - [Theory] - [InlineData("master", "{branchName}", "[mr]", "aste")] - public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) - { - // Arrange - var sut = new BranchNameRule(pattern); - var context = new VersionContext - { - Result = - { - CanonicalBranchName = branchName - } - }; + // Assert + result.Should().Be(expected); + } - // Act - var result = sut.Resolve(context, input); + [Theory] + [InlineData("master", "{branchName}", "[mr]", "aste")] + public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) + { + // Arrange + var sut = new BranchNameRule(pattern); + var context = new VersionContext + { + Result = + { + CanonicalBranchName = branchName + } + }; - // Assert - result.Should().Be(expected); - } - } + // Act + var result = sut.Resolve(context, input); + + // Assert + result.Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Rules/BranchNameSuffixRuleFixture.cs b/test/SimpleVersion.Core.Tests/Rules/BranchNameSuffixRuleFixture.cs index 63d0630..82cb78a 100644 --- a/test/SimpleVersion.Core.Tests/Rules/BranchNameSuffixRuleFixture.cs +++ b/test/SimpleVersion.Core.Tests/Rules/BranchNameSuffixRuleFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,83 +9,83 @@ namespace SimpleVersion.Core.Tests.Rules { - public class BranchNameSuffixRuleFixture - { - [Fact] - public void Instance_SetsDefaults() - { - // Arrange / Act - var sut = BranchNameSuffixRule.Instance; + public class BranchNameSuffixRuleFixture + { + [Fact] + public void Instance_SetsDefaults() + { + // Arrange / Act + var sut = BranchNameSuffixRule.Instance; - // Assert - sut.Pattern.Should().NotBeNull(); - sut.Token.Should().Be("{branchnamesuffix}"); - } + // Assert + sut.Pattern.Should().NotBeNull(); + sut.Token.Should().Be("{branchnamesuffix}"); + } - public static IEnumerable ApplyData() - { - yield return new object[] { null, null }; - yield return new object[] { null, Array.Empty() }; - yield return new object[] { new VersionContext(), new[] { "this" } }; - } + public static IEnumerable ApplyData() + { + yield return new object[] { null, null }; + yield return new object[] { null, Array.Empty() }; + yield return new object[] { new VersionContext(), new[] { "this" } }; + } - [Theory] - [MemberData(nameof(ApplyData))] - public void Apply_Returns_Input(VersionContext context, IEnumerable input) - { - // Arrange - var sut = new BranchNameSuffixRule(); + [Theory] + [MemberData(nameof(ApplyData))] + public void Apply_Returns_Input(VersionContext context, IEnumerable input) + { + // Arrange + var sut = new BranchNameSuffixRule(); - // Act - var result = sut.Apply(context, input); + // Act + var result = sut.Apply(context, input); - // Assert - result.Should().BeSameAs(input); - } + // Assert + result.Should().BeSameAs(input); + } - [Theory] - [InlineData("refs/heads/master", "{branchNameSuffix}", "master")] - [InlineData("refs/heads/master", "{BRANCHNAMESUFFIX}", "master")] - [InlineData("refs/heads/release/1.0", "{BRANCHNAMESuffix}", "10")] - [InlineData("refs/heads/release-1.0", "{BRANCHNAMEsuffix}", "release10")] - public void Resolve_Replaces_CanonicalBranchName(string branchName, string input, string expected) - { - // Arrange - var sut = new BranchNameSuffixRule(); - var context = new VersionContext - { - Result = - { - CanonicalBranchName = branchName - } - }; + [Theory] + [InlineData("refs/heads/master", "{branchNameSuffix}", "master")] + [InlineData("refs/heads/master", "{BRANCHNAMESUFFIX}", "master")] + [InlineData("refs/heads/release/1.0", "{BRANCHNAMESuffix}", "10")] + [InlineData("refs/heads/release-1.0", "{BRANCHNAMEsuffix}", "release10")] + public void Resolve_Replaces_CanonicalBranchName(string branchName, string input, string expected) + { + // Arrange + var sut = new BranchNameSuffixRule(); + var context = new VersionContext + { + Result = + { + CanonicalBranchName = branchName + } + }; - // Act - var result = sut.Resolve(context, input); + // Act + var result = sut.Resolve(context, input); - // Assert - result.Should().Be(expected); - } + // Assert + result.Should().Be(expected); + } - [Theory] - [InlineData("master", "{branchNameSuffix}", "[mr]", "aste")] - public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) - { - // Arrange - var sut = new BranchNameSuffixRule(pattern); - var context = new VersionContext - { - Result = - { - CanonicalBranchName = branchName - } - }; + [Theory] + [InlineData("master", "{branchNameSuffix}", "[mr]", "aste")] + public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) + { + // Arrange + var sut = new BranchNameSuffixRule(pattern); + var context = new VersionContext + { + Result = + { + CanonicalBranchName = branchName + } + }; - // Act - var result = sut.Resolve(context, input); + // Act + var result = sut.Resolve(context, input); - // Assert - result.Should().Be(expected); - } - } + // Assert + result.Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Rules/HeightRuleFixture.cs b/test/SimpleVersion.Core.Tests/Rules/HeightRuleFixture.cs index 5632840..33da0a4 100644 --- a/test/SimpleVersion.Core.Tests/Rules/HeightRuleFixture.cs +++ b/test/SimpleVersion.Core.Tests/Rules/HeightRuleFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -10,111 +10,111 @@ namespace SimpleVersion.Core.Tests.Rules { - public class HeightRuleFixture - { - [Fact] - public void Instance_Padded_IsFalse() - { - // Arrange - var sut = HeightRule.Instance; - - // Act - var result = sut.Padded; - - // Assert - result.Should().BeFalse(); - } - - [Fact] - public void Token_Is_Asterisk() - { - // Arrange / Act - var sut = new HeightRule(); - - // Assert - sut.Token.Should().Be("*"); - } - - [Fact] - public void Padded_ByDefault_IsFalse() - { - // Arrange / Act - var sut = new HeightRule(); - - // Assert - sut.Padded.Should().BeFalse(); - } - - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void Padded_WhenSet_SetsCorrectly(bool usePadding) - { - // Arrange / Act - var sut = new HeightRule(usePadding); - - // Assert - sut.Padded.Should().Be(usePadding); - } - - [Theory] - [InlineData(true, 10, "myString-*", "myString-0010")] - [InlineData(false, 15, "myString-*", "myString-15")] - [InlineData(true, 10, "myString-*.*", "myString-0010.0010")] - [InlineData(false, 15, "myString-*-*", "myString-15-15")] - [InlineData(true, 10, "myString", "myString")] - [InlineData(false, 15, "myString", "myString")] - public void Resolve_ReplacesToken_IfNeeded(bool usePadding, int height, string input, string expected) - { - // Arrange - var sut = new HeightRule(usePadding); - var context = new VersionContext - { - Result = - { - Height = height - } - }; - - // Act - var result = sut.Resolve(context, input); - - // Assert - result.Should().Be(expected); - } - - public static IEnumerable ApplyData() - { - // Version in string, Do not add to label - yield return new object[] { "1.*", new[] { "this" }, new[] { "this" } }; - // No release label, Do not add to label - yield return new object[] { "1.0", Array.Empty(), Array.Empty() }; - // Not in version and release, append to end - yield return new object[] { "1.0", new[] { "this" }, new[] { "this", "*" } }; - } - - - [Theory] - [MemberData(nameof(ApplyData))] - public void Apply_Appends_IfRequired(string version, IEnumerable input, IEnumerable expected) - { - // Arrange - var sut = new HeightRule(); - var context = new VersionContext - { - Configuration = - { - Version = version - } - }; - - // Act - var result = sut.Apply(context, input); - - // Assert - result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering()); - } - - } + public class HeightRuleFixture + { + [Fact] + public void Instance_Padded_IsFalse() + { + // Arrange + var sut = HeightRule.Instance; + + // Act + var result = sut.Padded; + + // Assert + result.Should().BeFalse(); + } + + [Fact] + public void Token_Is_Asterisk() + { + // Arrange / Act + var sut = new HeightRule(); + + // Assert + sut.Token.Should().Be("*"); + } + + [Fact] + public void Padded_ByDefault_IsFalse() + { + // Arrange / Act + var sut = new HeightRule(); + + // Assert + sut.Padded.Should().BeFalse(); + } + + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Padded_WhenSet_SetsCorrectly(bool usePadding) + { + // Arrange / Act + var sut = new HeightRule(usePadding); + + // Assert + sut.Padded.Should().Be(usePadding); + } + + [Theory] + [InlineData(true, 10, "myString-*", "myString-0010")] + [InlineData(false, 15, "myString-*", "myString-15")] + [InlineData(true, 10, "myString-*.*", "myString-0010.0010")] + [InlineData(false, 15, "myString-*-*", "myString-15-15")] + [InlineData(true, 10, "myString", "myString")] + [InlineData(false, 15, "myString", "myString")] + public void Resolve_ReplacesToken_IfNeeded(bool usePadding, int height, string input, string expected) + { + // Arrange + var sut = new HeightRule(usePadding); + var context = new VersionContext + { + Result = + { + Height = height + } + }; + + // Act + var result = sut.Resolve(context, input); + + // Assert + result.Should().Be(expected); + } + + public static IEnumerable ApplyData() + { + // Version in string, Do not add to label + yield return new object[] { "1.*", new[] { "this" }, new[] { "this" } }; + // No release label, Do not add to label + yield return new object[] { "1.0", Array.Empty(), Array.Empty() }; + // Not in version and release, append to end + yield return new object[] { "1.0", new[] { "this" }, new[] { "this", "*" } }; + } + + + [Theory] + [MemberData(nameof(ApplyData))] + public void Apply_Appends_IfRequired(string version, IEnumerable input, IEnumerable expected) + { + // Arrange + var sut = new HeightRule(); + var context = new VersionContext + { + Configuration = + { + Version = version + } + }; + + // Act + var result = sut.Apply(context, input); + + // Assert + result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering()); + } + + } } diff --git a/test/SimpleVersion.Core.Tests/Rules/ShortBranchNameRuleFixture.cs b/test/SimpleVersion.Core.Tests/Rules/ShortBranchNameRuleFixture.cs index 0618b69..29c075b 100644 --- a/test/SimpleVersion.Core.Tests/Rules/ShortBranchNameRuleFixture.cs +++ b/test/SimpleVersion.Core.Tests/Rules/ShortBranchNameRuleFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,84 +9,84 @@ namespace SimpleVersion.Core.Tests.Rules { - public class ShortBranchNameRuleFixture - { - [Fact] - public void Instance_SetsDefaults() - { - // Arrange / Act - var sut = ShortBranchNameRule.Instance; + public class ShortBranchNameRuleFixture + { + [Fact] + public void Instance_SetsDefaults() + { + // Arrange / Act + var sut = ShortBranchNameRule.Instance; - // Assert - sut.Pattern.Should().NotBeNull(); - sut.Token.Should().Be("{shortbranchname}"); - } + // Assert + sut.Pattern.Should().NotBeNull(); + sut.Token.Should().Be("{shortbranchname}"); + } - public static IEnumerable ApplyData() - { - yield return new object[] { null, null }; - yield return new object[] { null, Array.Empty() }; - yield return new object[] { new VersionContext(), new[] { "this" } }; - } + public static IEnumerable ApplyData() + { + yield return new object[] { null, null }; + yield return new object[] { null, Array.Empty() }; + yield return new object[] { new VersionContext(), new[] { "this" } }; + } - [Theory] - [MemberData(nameof(ApplyData))] - public void Apply_Returns_Input(VersionContext context, IEnumerable input) - { - // Arrange - var sut = new ShortBranchNameRule(); + [Theory] + [MemberData(nameof(ApplyData))] + public void Apply_Returns_Input(VersionContext context, IEnumerable input) + { + // Arrange + var sut = new ShortBranchNameRule(); - // Act - var result = sut.Apply(context, input); + // Act + var result = sut.Apply(context, input); - // Assert - result.Should().BeSameAs(input); - } + // Assert + result.Should().BeSameAs(input); + } - [Theory] - [InlineData("master", "{shortBranchName}", "master")] - [InlineData("master", "{SHORTBRANCHNAME}", "master")] - [InlineData("release/1.0", "{shortBRANCHNAME}", "release10")] - [InlineData("release-1.0", "{shortBRANCHNAME}", "release10")] - public void Resolve_Replaces_BranchName(string branchName, string input, string expected) - { - // Arrange - var sut = new ShortBranchNameRule(); - var context = new VersionContext - { - Result = - { - BranchName = branchName - } - }; + [Theory] + [InlineData("master", "{shortBranchName}", "master")] + [InlineData("master", "{SHORTBRANCHNAME}", "master")] + [InlineData("release/1.0", "{shortBRANCHNAME}", "release10")] + [InlineData("release-1.0", "{shortBRANCHNAME}", "release10")] + public void Resolve_Replaces_BranchName(string branchName, string input, string expected) + { + // Arrange + var sut = new ShortBranchNameRule(); + var context = new VersionContext + { + Result = + { + BranchName = branchName + } + }; - // Act - var result = sut.Resolve(context, input); + // Act + var result = sut.Resolve(context, input); - // Assert - result.Should().Be(expected); - } + // Assert + result.Should().Be(expected); + } - - [Theory] - [InlineData("master", "{shortbranchName}", "[mr]", "aste")] - public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) - { - // Arrange - var sut = new ShortBranchNameRule(pattern); - var context = new VersionContext - { - Result = - { - BranchName = branchName - } - }; - // Act - var result = sut.Resolve(context, input); + [Theory] + [InlineData("master", "{shortbranchName}", "[mr]", "aste")] + public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected) + { + // Arrange + var sut = new ShortBranchNameRule(pattern); + var context = new VersionContext + { + Result = + { + BranchName = branchName + } + }; - // Assert - result.Should().Be(expected); - } - } + // Act + var result = sut.Resolve(context, input); + + // Assert + result.Should().Be(expected); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Rules/ShortShaRuleFixture.cs b/test/SimpleVersion.Core.Tests/Rules/ShortShaRuleFixture.cs index b718c85..27e4ba6 100644 --- a/test/SimpleVersion.Core.Tests/Rules/ShortShaRuleFixture.cs +++ b/test/SimpleVersion.Core.Tests/Rules/ShortShaRuleFixture.cs @@ -1,4 +1,4 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using SimpleVersion.Pipeline; @@ -9,70 +9,70 @@ namespace SimpleVersion.Core.Tests.Rules { - public class ShortShaRuleFixture - { - private ShortShaRule _sut; + public class ShortShaRuleFixture + { + private readonly ShortShaRule _sut; - public ShortShaRuleFixture() - { - _sut = new ShortShaRule(); - } + public ShortShaRuleFixture() + { + _sut = new ShortShaRule(); + } - [Fact] - public void Token_Is_Correct() - { - // Act / Assert - _sut.Token.Should().Be("{shortsha}"); - } + [Fact] + public void Token_Is_Correct() + { + // Act / Assert + _sut.Token.Should().Be("{shortsha}"); + } - [Theory] - [InlineData("{shortSha}", "c4ca82d2")] - [InlineData("{SHORTSHA}", "c4ca82d2")] - [InlineData("this-{shortsha}", "this-c4ca82d2")] - [InlineData("this", "this")] - public void Resolve_ReplacesToken_IfNeeded(string input, string expected) - { - // Arrange - var context = new VersionContext - { - Result = Utils.GetVersionResult(10) - }; + [Theory] + [InlineData("{shortSha}", "c4ca82d2")] + [InlineData("{SHORTSHA}", "c4ca82d2")] + [InlineData("this-{shortsha}", "this-c4ca82d2")] + [InlineData("this", "this")] + public void Resolve_ReplacesToken_IfNeeded(string input, string expected) + { + // Arrange + var context = new VersionContext + { + Result = Utils.GetVersionResult(10) + }; - // Act - var result = _sut.Resolve(context, input); + // Act + var result = _sut.Resolve(context, input); - // Assert - result.Should().Be(expected); - } + // Assert + result.Should().Be(expected); + } - public static IEnumerable ApplyData() - { - // release branch does not include sha - yield return new object[] { true, new[] { "this" }, new[] { "this" } }; - // non-release sha appends - yield return new object[] { false, new[] { "this" }, new[] { "this", "{shortsha}" } }; - // non-release sha does not append if already there - yield return new object[] { false, new[] { "{shortsha}", "this" }, new[] { "{shortsha}", "this" } }; - // empty array appends - yield return new object[] { false, Array.Empty(), new[] { "{shortsha}" } }; - } + public static IEnumerable ApplyData() + { + // release branch does not include sha + yield return new object[] { true, new[] { "this" }, new[] { "this" } }; + // non-release sha appends + yield return new object[] { false, new[] { "this" }, new[] { "this", "{shortsha}" } }; + // non-release sha does not append if already there + yield return new object[] { false, new[] { "{shortsha}", "this" }, new[] { "{shortsha}", "this" } }; + // empty array appends + yield return new object[] { false, Array.Empty(), new[] { "{shortsha}" } }; + } - [Theory] - [MemberData(nameof(ApplyData))] - public void Apply_AppendsToken_IfNeeded(bool isRelease, IEnumerable input, IEnumerable expected) - { - // Arrange - var context = new VersionContext - { - Configuration = Utils.GetConfiguration("1.2.3"), - Result = Utils.GetVersionResult(10, isRelease) - }; + [Theory] + [MemberData(nameof(ApplyData))] + public void Apply_AppendsToken_IfNeeded(bool isRelease, IEnumerable input, IEnumerable expected) + { + // Arrange + var context = new VersionContext + { + Configuration = Utils.GetConfiguration("1.2.3"), + Result = Utils.GetVersionResult(10, isRelease) + }; - // Act - var result = _sut.Apply(context, input); + // Act + var result = _sut.Apply(context, input); - // Assert - result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering()); - } - } + // Assert + result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering()); + } + } } diff --git a/test/SimpleVersion.Core.Tests/SimpleVersion.Core.Tests.csproj b/test/SimpleVersion.Core.Tests/SimpleVersion.Core.Tests.csproj index 7f96aa7..36a63fa 100644 --- a/test/SimpleVersion.Core.Tests/SimpleVersion.Core.Tests.csproj +++ b/test/SimpleVersion.Core.Tests/SimpleVersion.Core.Tests.csproj @@ -1,11 +1,11 @@ - - + + - - - + + + - - - + + + diff --git a/test/SimpleVersion.Core.Tests/StringExtensionsFixture.cs b/test/SimpleVersion.Core.Tests/StringExtensionsFixture.cs index 5eade8b..dec5eab 100644 --- a/test/SimpleVersion.Core.Tests/StringExtensionsFixture.cs +++ b/test/SimpleVersion.Core.Tests/StringExtensionsFixture.cs @@ -1,48 +1,48 @@ -// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. +// Licensed under the MIT license. See https://kieranties.mit-license.org/ for full license information. using FluentAssertions; using Xunit; namespace SimpleVersion.Core.Tests { - public class StringExtensionsFixture - { - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - [InlineData("\t\t")] - [InlineData("FALSE")] - [InlineData("false")] - [InlineData("False")] - [InlineData("Nope")] - [InlineData("1")] - [InlineData("-1")] - [InlineData("00001")] - [InlineData("0.1")] - public void ToBool_FalseValues_ReturnsFalse(string value) - { - // Arrange / Act - var result = StringExtensions.ToBool(value); + public class StringExtensionsFixture + { + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + [InlineData("\t\t")] + [InlineData("FALSE")] + [InlineData("false")] + [InlineData("False")] + [InlineData("Nope")] + [InlineData("1")] + [InlineData("-1")] + [InlineData("00001")] + [InlineData("0.1")] + public void ToBool_FalseValues_ReturnsFalse(string value) + { + // Arrange / Act + var result = StringExtensions.ToBool(value); - // Assert - result.Should().BeFalse(); - } + // Assert + result.Should().BeFalse(); + } - [Theory] - [InlineData("TRUE")] - [InlineData("true")] - [InlineData("True")] - [InlineData("0")] - [InlineData("-0")] - [InlineData("00000")] - public void ToBool_TrueValues_ReturnsTrue(string value) - { - // Arrange / Act - var result = StringExtensions.ToBool(value); - - // Assert - result.Should().BeTrue(); - } - } + [Theory] + [InlineData("TRUE")] + [InlineData("true")] + [InlineData("True")] + [InlineData("0")] + [InlineData("-0")] + [InlineData("00000")] + public void ToBool_TrueValues_ReturnsTrue(string value) + { + // Arrange / Act + var result = StringExtensions.ToBool(value); + + // Assert + result.Should().BeTrue(); + } + } } diff --git a/test/SimpleVersion.Core.Tests/Utils.cs b/test/SimpleVersion.Core.Tests/Utils.cs index 1bbaf08..9b769f3 100644 --- a/test/SimpleVersion.Core.Tests/Utils.cs +++ b/test/SimpleVersion.Core.Tests/Utils.cs @@ -1,4 +1,4 @@ -using GitTools.Testing; +using GitTools.Testing; using Newtonsoft.Json; using SimpleVersion.Model; using System; @@ -7,55 +7,55 @@ namespace SimpleVersion.Core.Tests { - public static class Utils - { - public static Configuration GetConfiguration(string version, IEnumerable label = null, IEnumerable meta = null) - { - var info = new Configuration - { - Version = version, - Branches = new BranchInfo - { - Release = - { - "^refs/heads/master$", - "^refs/heads/release/.+$" - } - } - }; + public static class Utils + { + public static Configuration GetConfiguration(string version, IEnumerable label = null, IEnumerable meta = null) + { + var info = new Configuration + { + Version = version, + Branches = new BranchInfo + { + Release = + { + "^refs/heads/master$", + "^refs/heads/release/.+$" + } + } + }; - if (label != null) - info.Label.AddRange(label); + if (label != null) + info.Label.AddRange(label); - if (meta != null) - info.MetaData.AddRange(meta); + if (meta != null) + info.MetaData.AddRange(meta); - return info; - } + return info; + } - public static void WriteConfiguration(Configuration config, RepositoryFixtureBase fixture, bool commit = true) - { - // write the version file - var json = JsonConvert.SerializeObject(config, Formatting.Indented); - var fullPath = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); - File.WriteAllText(fullPath, json); - fixture.Repository.Index.Add(Constants.VersionFileName); - fixture.Repository.Index.Write(); - if (commit) - fixture.MakeACommit(); - } + public static void WriteConfiguration(Configuration config, RepositoryFixtureBase fixture, bool commit = true) + { + // write the version file + var json = JsonConvert.SerializeObject(config, Formatting.Indented); + var fullPath = Path.Combine(fixture.RepositoryPath, Constants.VersionFileName); + File.WriteAllText(fullPath, json); + fixture.Repository.Index.Add(Constants.VersionFileName); + fixture.Repository.Index.Write(); + if (commit) + fixture.MakeACommit(); + } - public static VersionResult GetVersionResult(int height, bool release = true) - { - var branchName = release ? "release/example" : "feature/example"; + public static VersionResult GetVersionResult(int height, bool release = true) + { + var branchName = release ? "release/example" : "feature/example"; - return new VersionResult - { - BranchName = branchName, - CanonicalBranchName = "refs/heads/" + branchName, - Sha = "4ca82d2c58f48007bf16d69ebf036fc4ebfdd059", - Height = height - }; - } - } + return new VersionResult + { + BranchName = branchName, + CanonicalBranchName = "refs/heads/" + branchName, + Sha = "4ca82d2c58f48007bf16d69ebf036fc4ebfdd059", + Height = height + }; + } + } }