diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 00000000..ce4d76e0 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,269 @@ +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = true + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = true +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:warning +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_property = false:warning + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning + +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Field preferences +dotnet_style_readonly_field = true:suggestion + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false:silent +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_prefer_static_local_function = true:suggestion +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent + +# Code-block preferences +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:warning + +#### C# Formatting Rules #### + +# New line preferences +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 + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_labels = flush_left +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +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_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = false + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = warning +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.method_should_be_pascal_case.severity = warning +dotnet_naming_rule.method_should_be_pascal_case.symbols = method +dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.severity = warning +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.symbols = public_or_protected_field +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.severity = warning +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.symbols = private_or_internal_static_field +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.severity = warning +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.symbols = private_or_internal_field +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.style = camelcase + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.method.applicable_kinds = method +dotnet_naming_symbols.method.applicable_accessibilities = public +dotnet_naming_symbols.method.required_modifiers = + +dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field +dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected +dotnet_naming_symbols.public_or_protected_field.required_modifiers = + +dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected +dotnet_naming_symbols.private_or_internal_field.required_modifiers = + +dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected +dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = +dotnet_naming_style.camelcase.capitalization = camel_case + +## IDE + +# IDE0005: Using directive is unnecessary. (but ignore on auto-generated) +dotnet_diagnostic.IDE0005.severity = warning +dotnet_diagnostic.IDE0005_gen.severity = none + +# IDE0061: Misplaced using directive +dotnet_diagnostic.IDE0061.severity = suggestion + +## SA... StyleCop + +# SA1200: Using directives should be placed correctly +dotnet_diagnostic.SA1200.severity = none + +# SA1101: Prefix local calls with this +dotnet_diagnostic.SA1101.severity = none + +# SA1633: File should have header +dotnet_diagnostic.SA1633.severity = none + +## CA... FxCop + +# CA1062: Validate arguments of public methods +dotnet_diagnostic.CA1062.severity = none + +# CA1303: Do not pass literals as localized parameters +dotnet_diagnostic.CA1303.severity = none + +# CA1040: Avoid empty interfaces +dotnet_diagnostic.CA1040.severity = none + +# CA1044: collides with r# - rules. +dotnet_diagnostic.CA1044.severity = none diff --git a/src/Cake.7zip.Tests/Cake.7zip.Tests.csproj b/src/Cake.7zip.Tests/Cake.7zip.Tests.csproj index 7fa1d4c7..935d168c 100644 --- a/src/Cake.7zip.Tests/Cake.7zip.Tests.csproj +++ b/src/Cake.7zip.Tests/Cake.7zip.Tests.csproj @@ -1,26 +1,33 @@ - - netcoreapp2.0 - $(TargetFrameworks);net461 + + netcoreapp2.1 + $(TargetFrameworks);net461 - false + false - Cake.SevenZip.Tests - + Cake.SevenZip.Tests + - - - - - - - runtime; build; native; contentfiles; analyzers - all - - + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + runtime; build; native; contentfiles; analyzers + all + + - - - + + + \ No newline at end of file diff --git a/src/Cake.7zip.Tests/Parsers/AbstractOutpuCommandTests.cs b/src/Cake.7zip.Tests/Commands/AbstractOutputCommandTests.cs similarity index 63% rename from src/Cake.7zip.Tests/Parsers/AbstractOutpuCommandTests.cs rename to src/Cake.7zip.Tests/Commands/AbstractOutputCommandTests.cs index ef4899ea..8d471610 100644 --- a/src/Cake.7zip.Tests/Parsers/AbstractOutpuCommandTests.cs +++ b/src/Cake.7zip.Tests/Commands/AbstractOutputCommandTests.cs @@ -1,16 +1,21 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Moq; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; + +using FluentAssertions; - using Xunit; +using Moq; - public class AbstractOutpuCommandTests +using Xunit; + +namespace Cake.SevenZip.Tests.Commands +{ + public class AbstractOutputCommandTests { [Fact] public void AbstractOutputCommand_sets_raw_output() { - var command = new Mock>(); - var parser = new Mock>(); + var command = new Mock>(); + var parser = new Mock>(); command.Setup(c => c.OutputParser).Returns(parser.Object); var expected = new[] { "this", "was", "the", "output" }; var partialMock = command.Object; @@ -19,14 +24,14 @@ public void AbstractOutputCommand_sets_raw_output() ((ICanParseOutput)partialMock).SetRawOutput(expected); - Assert.Equal(expected, actual); + actual.Should().BeEquivalentTo(expected); } [Fact] public void AbstractOutputCommand_sets_nothing_when_called_with_null() { - var command = new Mock>(); - var parser = new Mock>(); + var command = new Mock>(); + var parser = new Mock>(); command.Setup(c => c.OutputParser).Returns(parser.Object); var partialMock = command.Object; string[] actual = null; @@ -34,16 +39,16 @@ public void AbstractOutputCommand_sets_nothing_when_called_with_null() ((ICanParseOutput)partialMock).SetRawOutput(null); - Assert.Null(actual); + actual.Should().BeNull(); } [Fact] public void AbstractOutputCommand_uses_parser_to_set_non_raw_output() { - var expected = new object(); - var command = new Mock>(); - var parser = new Mock>(); - parser.Setup(p => p.Parse(It.IsAny())).Returns(expected); + var expected = new Mock(); + var command = new Mock>(); + var parser = new Mock>(); + parser.Setup(p => p.Parse(It.IsAny())).Returns(expected.Object); command.Setup(c => c.OutputParser).Returns(parser.Object); var partialMock = command.Object; object actual = null; @@ -51,7 +56,7 @@ public void AbstractOutputCommand_uses_parser_to_set_non_raw_output() ((ICanParseOutput)partialMock).SetRawOutput(new string[] { }); - Assert.Equal(expected, actual); + actual.Should().Be(expected.Object); } } } diff --git a/src/Cake.7zip.Tests/Commands/GeneralOutputCommandTests.cs b/src/Cake.7zip.Tests/Commands/GeneralOutputCommandTests.cs new file mode 100644 index 00000000..7fb1deee --- /dev/null +++ b/src/Cake.7zip.Tests/Commands/GeneralOutputCommandTests.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; + +using FluentAssertions; + +using Xunit; + +namespace Cake.SevenZip.Tests.Commands +{ + public class GeneralOutputCommandTests + { + [Theory] + [ClassData(typeof(TestData))] + public void OutputCommand_uses_its_own_parser(OutputCommand command, Type expectedParserType) + where T : IOutput + { + var actual = command.OutputParser; + actual.Should().NotBeNull(); + actual.Should().BeOfType(expectedParserType); + } + + private class TestData : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return new object[] { new InformationCommand(), typeof(InformationOutputParser) }; + yield return new object[] { new TestCommand(), typeof(TestOutputParser) }; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + } +} diff --git a/src/Cake.7zip.Tests/Fixtures/FluentBuilderFixture.cs b/src/Cake.7zip.Tests/Fixtures/FluentBuilderFixture.cs index e9aaf648..0ab9ac48 100644 --- a/src/Cake.7zip.Tests/Fixtures/FluentBuilderFixture.cs +++ b/src/Cake.7zip.Tests/Fixtures/FluentBuilderFixture.cs @@ -1,13 +1,11 @@ -namespace Cake.SevenZip.Tests -{ - using Cake.Core.IO; - using Cake.SevenZip; - - using Moq; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Tests.Fixtures +{ public class FluentBuilderFixture { - internal CommandBuilder Context { get; private set; } + internal CommandBuilder Context { get; } public FluentBuilderFixture() { diff --git a/src/Cake.7zip.Tests/Fixtures/Outputs.cs b/src/Cake.7zip.Tests/Fixtures/Outputs.cs index d6469f9f..49120adb 100644 --- a/src/Cake.7zip.Tests/Fixtures/Outputs.cs +++ b/src/Cake.7zip.Tests/Fixtures/Outputs.cs @@ -1,7 +1,5 @@ -namespace Cake.SevenZip.Tests +namespace Cake.SevenZip.Tests.Fixtures { - using System; - public static class Outputs { public static string[] Information @@ -104,5 +102,41 @@ 0 8 4 CRC64 return demoOutput.ToArrayOfLines(); } } + + public static string[] Test + { + get + { + const string testOutput = @" +7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21 + +Scanning the drive for archives: +2 files, 2201618 bytes (2151 KiB) + +Testing archive: foo.zip +ERROR: foo.zip +foo.zip +Open ERROR: Can not open the file as [zip] archive + +ERRORS: +Is not archive + +Testing archive: .\nested.zip +-- +Path = .\nested.zip +Type = zip +Physical Size = 2198368 + +Everything is Ok + +Archives: 2 +OK archives: 1 +Can't open as archive: 1 +Files: 3 +Size: 2359279 +Compressed: 2198368"; + return testOutput.ToArrayOfLines(); + } + } } } diff --git a/src/Cake.7zip.Tests/Fixtures/SevenZipAliasesFixture.cs b/src/Cake.7zip.Tests/Fixtures/SevenZipAliasesFixture.cs index 9a6d0332..e37d3c2c 100644 --- a/src/Cake.7zip.Tests/Fixtures/SevenZipAliasesFixture.cs +++ b/src/Cake.7zip.Tests/Fixtures/SevenZipAliasesFixture.cs @@ -1,14 +1,14 @@ -namespace Cake.SevenZip.Tests -{ - using Cake.Core; - using Cake.Core.IO; - using Cake.Testing; +using Cake.Core; +using Cake.Core.IO; +using Cake.Testing; - using Moq; +using Moq; +namespace Cake.SevenZip.Tests.Fixtures +{ public class SevenZipAliasesFixture : SevenZipRunnerFixture { - internal ICakeContext Context { get; private set; } + internal ICakeContext Context { get; } public SevenZipAliasesFixture() { @@ -29,7 +29,7 @@ public SevenZipAliasesFixture() protected override void RunTool() { - SevenZipAliases.SevenZip(Context, Settings); + Context.SevenZip(Settings); } } } diff --git a/src/Cake.7zip.Tests/Fixtures/SevenZipFluentRunnerFixture.cs b/src/Cake.7zip.Tests/Fixtures/SevenZipFluentRunnerFixture.cs index 7bf79caa..31b08a04 100644 --- a/src/Cake.7zip.Tests/Fixtures/SevenZipFluentRunnerFixture.cs +++ b/src/Cake.7zip.Tests/Fixtures/SevenZipFluentRunnerFixture.cs @@ -1,6 +1,8 @@ using System; -namespace Cake.SevenZip.Tests +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Tests.Fixtures { public class SevenZipFluentRunnerFixture : SevenZipRunnerFixture { diff --git a/src/Cake.7zip.Tests/Fixtures/SevenZipRunnerFixture.cs b/src/Cake.7zip.Tests/Fixtures/SevenZipRunnerFixture.cs index 3c637075..0ef8f3aa 100644 --- a/src/Cake.7zip.Tests/Fixtures/SevenZipRunnerFixture.cs +++ b/src/Cake.7zip.Tests/Fixtures/SevenZipRunnerFixture.cs @@ -1,15 +1,15 @@ -namespace Cake.SevenZip.Tests -{ - using Cake.Core.IO; - using Cake.Testing; - using Cake.Testing.Fixtures; +using Cake.Core.IO; +using Cake.Testing; +using Cake.Testing.Fixtures; - using Moq; +using Moq; +namespace Cake.SevenZip.Tests.Fixtures +{ public class SevenZipRunnerFixture : ToolFixture { - internal Mock Registry { get; set; } - internal FakeLog Log { get; } + internal Mock Registry { get; } + private FakeLog Log { get; } public SevenZipRunnerFixture() : base("7za.exe") diff --git a/src/Cake.7zip.Tests/Fixtures/SevenZipSettingsFixture.cs b/src/Cake.7zip.Tests/Fixtures/SevenZipSettingsFixture.cs index 523fdc7c..e4e75b56 100644 --- a/src/Cake.7zip.Tests/Fixtures/SevenZipSettingsFixture.cs +++ b/src/Cake.7zip.Tests/Fixtures/SevenZipSettingsFixture.cs @@ -1,9 +1,9 @@ -namespace Cake.SevenZip.Tests.Settings -{ - using System; +using System; - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Tests.Fixtures +{ public class SevenZipSettingsFixture { public string Parse(Action action) diff --git a/src/Cake.7zip.Tests/FluentBuilder/SevenZipAddCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/AddCommandBuilderTests.cs similarity index 89% rename from src/Cake.7zip.Tests/FluentBuilder/SevenZipAddCommandBuilderTests.cs rename to src/Cake.7zip.Tests/FluentBuilder/AddCommandBuilderTests.cs index ad9f9220..ed5f2377 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/SevenZipAddCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/AddCommandBuilderTests.cs @@ -1,12 +1,17 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Cake.Core.IO; +using System; + +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using System; +using FluentAssertions; - using Xunit; +using Xunit; - public class SevenZipAddCommandBuilderTests +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class AddCommandBuilderTests { [Fact] public void Add_can_use_Archive_and_file() @@ -21,7 +26,7 @@ public void Add_can_use_Archive_and_file() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -37,7 +42,7 @@ public void Add_can_use_Archive_and_directory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -48,9 +53,12 @@ public void Add_throws_on_missing_archive() .InAddMode() .WithFiles(new FilePath("in.txt")); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -61,9 +69,12 @@ public void Add_throws_on_missing_fileOrDirectory() .InAddMode() .WithArchive(new FilePath("out.zip")); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -79,7 +90,7 @@ public void Add_can_use_Archive_and_file_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -95,7 +106,7 @@ public void Add_can_use_Archive_and_directory_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -111,7 +122,7 @@ public void Add_can_use_Archive_and_directoryContent() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -127,7 +138,7 @@ public void Add_can_use_Archive_and_directoryContent_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -144,7 +155,7 @@ public void Add_can_use_ArchiveType() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -165,7 +176,7 @@ public void Add_can_use_CompressionMethod() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -183,7 +194,7 @@ public void Add_can_use_CompressionMethod_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -200,7 +211,7 @@ public void Add_can_use_Sns() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -217,7 +228,7 @@ public void Add_can_use_Snsi() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -234,7 +245,7 @@ public void Add_can_use_Password() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -251,7 +262,7 @@ public void Add_can_use_Volume() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -269,7 +280,7 @@ public void Add_can_use_multiple_Volumes() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -286,7 +297,7 @@ public void Add_can_use_Ssw() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -303,7 +314,7 @@ public void Add_can_use_Stl() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -320,7 +331,7 @@ public void Add_can_use_WorkingDirectory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -337,7 +348,7 @@ public void Add_can_use_Recurse() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -354,7 +365,7 @@ public void Add_can_use_IncludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -371,7 +382,7 @@ public void Add_can_use_IncludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -389,7 +400,7 @@ public void Add_can_use_IncludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -406,7 +417,7 @@ public void Add_can_use_ExcludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -423,7 +434,7 @@ public void Add_can_use_ExcludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -441,7 +452,7 @@ public void Add_can_use_ExcludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -459,7 +470,7 @@ public void Add_can_use_UpdateOptions() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -476,7 +487,7 @@ public void Add_can_use_DeleteAfterCompression() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -493,7 +504,7 @@ public void Add_can_use_Sfx_without_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -510,7 +521,7 @@ public void Add_can_use_Sfx_with_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -527,7 +538,7 @@ public void Add_can_use_FullQualifiedPaths_with_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -544,7 +555,7 @@ public void Add_can_use_FullQualifiedPaths_without_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/FluentBuilder/ArgumentArchiveBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/ArgumentArchiveBuilderTests.cs new file mode 100644 index 00000000..984c12b5 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/ArgumentArchiveBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class ArgumentArchiveBuilderTests + { + [Fact] + public void WithArchive_returns_the_builder() + { + var expected = new Mock>(); + expected.Setup(x => x.Command).Returns(new Mock().Object); + + var actual = expected.Object.WithArchive(new FilePath("foo")); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithArchive_sets_the_archive() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupSet(c => c.Archive = It.IsAny()).Verifiable(); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new FilePath("foo"); + + builder.Object.WithArchive(expected); + + command.VerifySet(c => c.Archive = expected, Times.Once); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/ArgumentDirectoriesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/ArgumentDirectoriesBuilderTests.cs new file mode 100644 index 00000000..a83a4c4e --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/ArgumentDirectoriesBuilderTests.cs @@ -0,0 +1,124 @@ +using System.Linq; + +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class ArgumentDirectoriesBuilderTests + { + [Fact] + public void WithDirectories_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Directories); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDirectories(new DirectoryPath("foo")); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithDirectories_collection_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Directories); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDirectories(new DirectoryPathCollection()); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithDirectoryContents_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DirectoryContents); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDirectoryContents(new DirectoryPath("foo")); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithDirectoryContents_collection_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DirectoryContents); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDirectoryContents(new DirectoryPathCollection()); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithDirectoryContents_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DirectoryContents); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new DirectoryPath("foo"); + + builder.Object.WithDirectoryContents(expected); + command.Object.DirectoryContents.Single().Should().Be(expected); + } + + [Fact] + public void WithDirectoryContents_collection_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DirectoryContents); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new DirectoryPath("foo"); + + builder.Object.WithDirectoryContents(new DirectoryPathCollection(new[] { expected })); + + command.Object.DirectoryContents.Single().Should().Be(expected); + } + + [Fact] + public void WithDirectories_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Directories); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new DirectoryPath("foo"); + + builder.Object.WithDirectories(expected); + + command.Object.Directories.Single().Should().Be(expected); + } + + [Fact] + public void WithDirectories_collection_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Directories); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new DirectoryPath("foo"); + + builder.Object.WithDirectories(new DirectoryPathCollection(new[] { expected })); + + command.Object.Directories.Single().Should().Be(expected); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/ArgumentFilesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/ArgumentFilesBuilderTests.cs new file mode 100644 index 00000000..adc34ccc --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/ArgumentFilesBuilderTests.cs @@ -0,0 +1,71 @@ +using System.Linq; + +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class ArgumentFilesBuilderTests + { + [Fact] + public void WithFiles_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Files); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithFiles(new FilePath("foo")); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithFiles_collection_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Files); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithFiles(new FilePathCollection()); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithFiles_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Files); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new FilePath("foo"); + + builder.Object.WithFiles(expected); + + command.Object.Files.Single().Should().Be(expected); + } + + [Fact] + public void WithFiles_collection_sets_the_directoryContents() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Files); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = new FilePath("foo"); + + builder.Object.WithFiles(new FilePathCollection(new[] { expected })); + + command.Object.Files.Single().Should().Be(expected); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/BaseOutputBuilderTest.cs b/src/Cake.7zip.Tests/FluentBuilder/BaseOutputBuilderTest.cs new file mode 100644 index 00000000..6c7ddd07 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/BaseOutputBuilderTest.cs @@ -0,0 +1,115 @@ +using System; +using System.Linq; +using System.Reflection; + +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class BaseOutputBuilderTest + { + [Fact] + public void WithCommandOutput_returns_the_builder() + { + var expected = new MockOutputBuilder(); + var command = new Mock>(); + expected.MockCommand = command.Object; + + var actual = expected.WithCommandOutput(null); + + actual.Should().Be(expected); + } + + [Fact] + public void WithCommandRawOutput_returns_the_builder() + { + var expected = new MockOutputBuilder(); + var command = new Mock>(); + expected.MockCommand = command.Object; + + var actual = expected.WithCommandRawOutput(null); + + actual.Should().Be(expected); + } + + [Fact] + public void WithCommandOutput_sets_the_outputAction_on_the_command() + { + var builder = new MockOutputBuilder(); + var command = new Mock>(); + builder.MockCommand = command.Object; + Action expected = x => { }; + + builder.WithCommandOutput(expected); + + command.Object.OutputAction.Should().Be(expected); + } + + [Fact] + public void WithCommandRawOutput_sets_the_rawOutputAction_on_the_command() + { + var builder = new MockOutputBuilder(); + var command = new Mock>(); + builder.MockCommand = command.Object; + Action expected = x => { }; + + builder.WithCommandRawOutput(expected); + + command.Object.RawOutputAction.Should().Be(expected); + } + + [Fact] + public void All_outputBuilders_are_implementing_the_interface() + { + var baseOutputCommandType = typeof(OutputCommand<>); + var outputCommandTypes = baseOutputCommandType.Assembly.GetTypes().Where(t => + { + if (t.BaseType == null) // isn't this "object" as a "minimum" and never null? + { + return false; + } + + if (!t.BaseType.IsGenericType) + { + return false; + } + + return t.BaseType.GetGenericTypeDefinition() == baseOutputCommandType; + }); + + foreach (var commandType in outputCommandTypes) + { + var builderTypeName = commandType.Name + "Builder"; + var builderType = baseOutputCommandType.Assembly.GetTypes().Single(t => t.Name == builderTypeName); + var expected = Activator.CreateInstance(commandType); + var builder = builderType.GetConstructor( + BindingFlags.Instance | BindingFlags.NonPublic, + null, + new[] { commandType.MakeByRefType() }, + null).Invoke(new[] { expected }); + + var commandProperty = builderType.BaseType + .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic) + .Single(); + var commandPropertyGetter = commandProperty.GetMethod; + var actual = commandPropertyGetter.Invoke(builder, new object[0]); + + actual.Should().Be(expected); + } + } + + private class MockOutputBuilder : BaseOutputBuilder + { + public OutputCommand MockCommand { private get; set; } + protected override OutputCommand OutputCommand => MockCommand; + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/CommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/CommandBuilderTests.cs new file mode 100644 index 00000000..ed8b6ff3 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/CommandBuilderTests.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; + +using FluentAssertions; +using FluentAssertions.Common; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class CommandBuilderTests + { + [Theory] + [ClassData(typeof(CommandData))] + public void All_commands_have_a_builder(Type command) + { + var assembly = GetAssembly(); + var builderTypeName = command.Name + "Builder"; + var builderType = assembly.GetTypes().FirstOrDefault(t => t.Name == builderTypeName); + + builderType.Should().NotBeNull($"the command {command.Name} needs a builder named {builderTypeName}"); + + // commandBuilder supports the command as a mode. + var commandBuilderType = typeof(CommandBuilder); + var commandName = command.Name.Substring(0, command.Name.Length - 7); // FooCommand -> Foo + var modeName = $"In{commandName}Mode"; + var modeMethod = commandBuilderType + .GetMethods(BindingFlags.Public | BindingFlags.Instance) + .FirstOrDefault(m => m.Name == modeName); + modeMethod.Should().NotBeNull($"the CommandBuilder should have a method named {modeName} for the {command.Name}"); + // ReSharper disable PossibleNullReferenceException + modeMethod.ReturnType.Should().Be(builderType, $"the {modeName} of CommandBuilder should"); + // ReSharper enable PossibleNullReferenceException + } + + [Theory] + [ClassData(typeof(SwitchData))] + public void All_command_switches_should_be_supported_by_the_builder(Type command, Type @switch) + { + var assembly = GetAssembly(); + var builderTypeName = command.Name + "Builder"; + var builderType = assembly.GetTypes().Single(t => t.Name == builderTypeName); + var genericSwitchBuilder = typeof(ISupportSwitchBuilder<>); + + var switchBuilder = genericSwitchBuilder.MakeGenericType(@switch); + + builderType.Should().Implement(switchBuilder, because: $"the command {command.Name} implements {@switch.Name}, so {builderTypeName} should implement {switchBuilder}"); + + // test the interface was really implemented... + var expected = Activator.CreateInstance(command); + var builder = builderType.GetConstructor( + BindingFlags.Instance | BindingFlags.NonPublic, + null, + new[] { command.MakeByRefType() }, + null).Invoke(new[] { expected }); + var property = switchBuilder.Properties().Single(); + var actual = property.GetGetMethod().Invoke(builder, new object[0]); + actual.Should().Be(expected); + } + + [Theory] + [ClassData(typeof(ArgumentData))] + public void All_command_arguments_should_be_supported_by_the_builder(Type command, Type arg) + { + var assembly = GetAssembly(); + var builderTypeName = command.Name + "Builder"; + var builderType = assembly.GetTypes().Single(t => t.Name == builderTypeName); + var genericArgumentBuilder = typeof(ISupportArgumentBuilder<>); + + var argumentBuilder = genericArgumentBuilder.MakeGenericType(arg); + + builderType.Should().Implement(argumentBuilder, because: $"the command {command.Name} implements {arg.Name}, so {builderTypeName} should implement {argumentBuilder}"); + + // test the interface was really implemented... + var expected = Activator.CreateInstance(command); + var builder = builderType.GetConstructor( + BindingFlags.Instance | BindingFlags.NonPublic, + null, + new[] { command.MakeByRefType() }, + null).Invoke(new[] { expected }); + var property = argumentBuilder.Properties().Single(); + var actual = property.GetGetMethod().Invoke(builder, new object[0]); + actual.Should().Be(expected); + } + + private static Assembly GetAssembly() + { + return typeof(AddCommand).Assembly; + } + + private class ArgumentData : IEnumerable + { + public IEnumerator GetEnumerator() + { + var commands = new CommandData().Select(x => (Type)x[0]); + foreach (var c in commands) + { + var supportedArguments = c.GetInterfaces().Where(i => i.Implements(typeof(IHaveArgument))); + foreach (var arg in supportedArguments) + { + yield return new object[] { c, arg }; + } + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + + private class SwitchData : IEnumerable + { + public IEnumerator GetEnumerator() + { + var commands = new CommandData().Select(x => (Type)x[0]); + foreach (var c in commands) + { + var supportedSwitches = c.GetInterfaces().Where(i => i.Implements(typeof(ISupportSwitch))); + foreach (var @switch in supportedSwitches) + { + yield return new object[] { c, @switch }; + } + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + + private class CommandData : IEnumerable + { + public IEnumerator GetEnumerator() + { + var assembly = GetAssembly(); + var commands = assembly.GetTypes() + .Where(t => t.Implements(typeof(ICommand))) + .Where(t => !t.IsAbstract); + + return commands.Select(c => new object[] { c }).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SevenZipDeleteCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/DeleteCommandBuilderTests.cs similarity index 87% rename from src/Cake.7zip.Tests/FluentBuilder/SevenZipDeleteCommandBuilderTests.cs rename to src/Cake.7zip.Tests/FluentBuilder/DeleteCommandBuilderTests.cs index b193cdff..9a482665 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/SevenZipDeleteCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/DeleteCommandBuilderTests.cs @@ -1,12 +1,17 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Cake.Core.IO; +using System; + +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using System; +using FluentAssertions; - using Xunit; +using Xunit; - public class SevenZipDeleteCommandBuilderTests +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class DeleteCommandBuilderTests { [Fact] public void Delete_can_use_Archive_and_files() @@ -21,7 +26,7 @@ public void Delete_can_use_Archive_and_files() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -37,7 +42,7 @@ public void Delete_can_use_Archive_and_directories() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -47,9 +52,12 @@ public void Delete_throws_on_missing_archive() fixture.Context .InDeleteMode(); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -64,7 +72,7 @@ public void Delete_can_use_archive_without_files_or_directories() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -85,7 +93,7 @@ public void Delete_can_use_CompressionMethod() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -102,7 +110,7 @@ public void Delete_can_use_CompressionMethod_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -118,7 +126,7 @@ public void Delete_can_use_Sns() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -134,7 +142,7 @@ public void Delete_can_use_Password() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -150,7 +158,7 @@ public void Delete_can_use_WorkingDirectory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -166,7 +174,7 @@ public void Delete_can_use_Recurse() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -182,7 +190,7 @@ public void Delete_can_use_IncludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -198,7 +206,7 @@ public void Delete_can_use_IncludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -215,7 +223,7 @@ public void Delete_can_use_IncludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -231,7 +239,7 @@ public void Delete_can_use_ExcludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -247,7 +255,7 @@ public void Delete_can_use_ExcludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -264,7 +272,7 @@ public void Delete_can_use_ExcludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -281,7 +289,7 @@ public void Delete_can_use_UpdateOptions() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -297,7 +305,7 @@ public void Delete_can_use_Sfx_without_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -313,7 +321,7 @@ public void Delete_can_use_Sfx_with_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -329,7 +337,7 @@ public void Delete_can_use_FullQualifiedPaths_with_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -345,7 +353,7 @@ public void Delete_can_use_FullQualifiedPaths_without_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/FluentBuilder/SevenZipExtractCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/ExtractCommandBuilderTests.cs similarity index 78% rename from src/Cake.7zip.Tests/FluentBuilder/SevenZipExtractCommandBuilderTests.cs rename to src/Cake.7zip.Tests/FluentBuilder/ExtractCommandBuilderTests.cs index e43fb7e6..a86323a0 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/SevenZipExtractCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/ExtractCommandBuilderTests.cs @@ -1,13 +1,61 @@ -namespace Cake.SevenZip.Tests.Builder +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Tests.Fixtures; + +using Xunit; +using System; +using Cake.SevenZip.Switches; +using FluentAssertions; + +namespace Cake.SevenZip.Tests.FluentBuilder { - using Cake.Core.IO; + public class ExtractCommandBuilderTests + { + [Fact] + public void WithFullPathExtraction_returns_the_builder() + { + var command = new ExtractCommand(); + var sut = new ExtractCommandBuilder(ref command); - using System; + var actual = sut.WithFullPathExtraction(); - using Xunit; + actual.Should().Be(sut); + } + + [Fact] + public void WithoutFullPathExtraction_returns_the_builder() + { + var command = new ExtractCommand(); + var sut = new ExtractCommandBuilder(ref command); + + var actual = sut.WithoutFullPathExtraction(); + + actual.Should().Be(sut); + } + + [Fact] + public void WithFullPathExtraction_sets_UseFullPaths_to_true_on_the_command() + { + var command = new ExtractCommand(); + var sut = new ExtractCommandBuilder(ref command); + + sut.WithFullPathExtraction(); + + command.UseFullPaths.Should().BeTrue(); + } + + [Fact] + public void WithoutFullPathExtraction_sets_UseFullPaths_to_false_on_the_command() + { + var command = new ExtractCommand(); + var sut = new ExtractCommandBuilder(ref command); + + sut.WithoutFullPathExtraction(); + + command.UseFullPaths.Should().BeFalse(); + } - public class SevenZipExtractCommandBuilderTests - { [Fact] public void Extract_can_use_Archive() { @@ -20,7 +68,7 @@ public void Extract_can_use_Archive() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -36,7 +84,7 @@ public void Extract_can_use_full_path_mode() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -52,7 +100,7 @@ public void Extract_can_use_single_output_directory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -62,9 +110,12 @@ public void Extract_throws_on_missing_archive() fixture.Context .InExtractMode(); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -80,7 +131,7 @@ public void Extract_can_use_ArchiveType() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -100,7 +151,7 @@ public void Extract_can_use_CompressionMethod() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -116,7 +167,7 @@ public void Extract_can_use_Sns() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -132,7 +183,7 @@ public void Extract_can_use_Snsi() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -148,7 +199,7 @@ public void Extract_can_use_Password() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -164,7 +215,7 @@ public void Extract_can_use_Recurse() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -180,7 +231,7 @@ public void Extract_can_use_IncludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -196,7 +247,7 @@ public void Extract_can_use_ExcludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -212,7 +263,7 @@ public void Extract_can_use_IncludeArchiveFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -228,7 +279,7 @@ public void Extract_can_use_IncludeArchiveFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -245,7 +296,7 @@ public void Extract_can_use_IncludeArchiveFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -261,7 +312,7 @@ public void Extract_can_use_ExcludeArchiveFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -277,7 +328,7 @@ public void Extract_can_use_ExcludeArchiveFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -294,7 +345,7 @@ public void Extract_can_use_ExcludeArchiveFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -310,7 +361,7 @@ public void Extract_can_use_DisableParsingOfArchiveName() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -326,7 +377,7 @@ public void Extract_can_use_OverwireMode() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -342,7 +393,7 @@ public void Extract_can_use_OutputDirectory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -358,7 +409,7 @@ public void Extract_can_use_FullQualifiedPaths_with_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -374,7 +425,7 @@ public void Extract_can_use_FullQualifiedPaths_without_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/FluentBuilder/GeneralCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/GeneralCommandBuilderTests.cs index 14e83cff..a5d1958d 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/GeneralCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/GeneralCommandBuilderTests.cs @@ -1,13 +1,18 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Cake.Core; +using Cake.Core; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; + +using FluentAssertions; - using System; - using System.Linq; - using System.Reflection; +using System; +using System.Linq; +using System.Reflection; - using Xunit; +using Xunit; +namespace Cake.SevenZip.Tests.FluentBuilder +{ public class GeneralCommandBuilderTests { [Theory] @@ -26,7 +31,7 @@ public void Builders_support_needed_switches(Type commandType, Type builderType) { var expectedInterface = supportBuilder.MakeGenericType(supportSwitch); - Assert.Contains(expectedInterface, builerInterfaces); + builerInterfaces.Should().Contain(expectedInterface); } } @@ -46,7 +51,7 @@ public void Builders_support_needed_arguments(Type commandType, Type builderType { var expectedInterface = supportBuilder.MakeGenericType(hasArgument); - Assert.Contains(expectedInterface, builerInterfaces); + builerInterfaces.Should().Contain(expectedInterface); } } @@ -69,7 +74,7 @@ public void Every_switch_has_a_supportsSwitch() foreach (var @switch in allSwitches) { - Assert.Contains(@switch, allSwitchesUsedInSupportSwitches); + allSwitchesUsedInSupportSwitches.Should().Contain(@switch); } } @@ -93,7 +98,7 @@ public void Every_supportsSwitch_has_a_builder() { var expectedType = supportBuilder.MakeGenericType(@switch); - Assert.Contains(expectedType, allSupportBuilderExtensionMethodTypes); + allSupportBuilderExtensionMethodTypes.Should().Contain(expectedType); } } } diff --git a/src/Cake.7zip.Tests/FluentBuilder/SevenZipInformationCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/InformationCommandBuilderTests.cs similarity index 79% rename from src/Cake.7zip.Tests/FluentBuilder/SevenZipInformationCommandBuilderTests.cs rename to src/Cake.7zip.Tests/FluentBuilder/InformationCommandBuilderTests.cs index daaf0d22..0eabe58c 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/SevenZipInformationCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/InformationCommandBuilderTests.cs @@ -1,8 +1,12 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Xunit; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; - public class SevenZipInformationCommandBuilderTests +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class InformationCommandBuilderTests { [Fact] public void Information_can_be_used() @@ -15,7 +19,7 @@ public void Information_can_be_used() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -32,7 +36,7 @@ public void Information_parses_and_sets_the_output() info = o.Information; })); - Assert.NotNull(info); + info.Should().NotBeNull(); } [Fact] @@ -49,7 +53,7 @@ public void Information_sets_rawoutput() output = r; })); - Assert.Equal(Outputs.Information, output); + output.Should().BeEquivalentTo(Outputs.Information); } } } diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchArchiveTypeBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchArchiveTypeBuilderTests.cs new file mode 100644 index 00000000..1928bc17 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchArchiveTypeBuilderTests.cs @@ -0,0 +1,41 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchArchiveTypeBuilderTests + { + [Fact] + public void WithArchiveType_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ArchiveType); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithArchiveType(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithArchiveType_sets_archiveType_on_command() + { + var builder = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ArchiveType); + builder.Setup(x => x.Command).Returns(command.Object); + var expected = SwitchArchiveType.Lzma; + + builder.Object.WithArchiveType(expected); + + command.Object.ArchiveType.Should().Be(expected); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressFilesOpenForWritingBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressFilesOpenForWritingBuilderTests.cs new file mode 100644 index 00000000..28e32da4 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressFilesOpenForWritingBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchCompressFilesOpenForWritingBuilderTests + { + [Fact] + public void WithCompressFilesOpenForWriting_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.CompressFilesOpenForWriting); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithCompressFilesOpenForWriting(); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithCompressFilesOpenForWriting_sets_switch_CompressFilesOpenForWriting() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.CompressFilesOpenForWriting); + expected.Setup(x => x.Command).Returns(command.Object); + + expected.Object.WithCompressFilesOpenForWriting(); + + command.Object.CompressFilesOpenForWriting.Should().NotBeNull(); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressionMethodBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressionMethodBuilderTests.cs new file mode 100644 index 00000000..7f9c5061 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchCompressionMethodBuilderTests.cs @@ -0,0 +1,53 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchCompressionMethodBuilderTests + { + [Fact] + public void WithCompressionMethod_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.CompressionMethod); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithCompressionMethod(c => { }); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithCompressionMethodLevel_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.CompressionMethod); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithCompressionMethodLevel(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithCompressionMethodMethod_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.CompressionMethod); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithCompressionMethodMethod(default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchDeleteAfterCompressionBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchDeleteAfterCompressionBuilderTests.cs new file mode 100644 index 00000000..a48dca33 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchDeleteAfterCompressionBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchDeleteAfterCompressionBuilderTests + { + [Fact] + public void WithDeleteAfterCompression_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DeleteAfterCompression); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDeleteAfterCompression(); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchDisableParsingOfArchiveNameBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchDisableParsingOfArchiveNameBuilderTests.cs new file mode 100644 index 00000000..a2a99815 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchDisableParsingOfArchiveNameBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchDisableParsingOfArchiveNameBuilderTests + { + [Fact] + public void WithDisableParsingOfArchiveName_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.DisableParsingOfArchiveName); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithDisableParsingOfArchiveName(); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeArchiveFilenamesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeArchiveFilenamesBuilderTests.cs new file mode 100644 index 00000000..d0311b25 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeArchiveFilenamesBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchExcludeArchiveFilenamesBuilderTests + { + [Fact] + public void WithDeleteAfterCompression_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ExcludeArchiveFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithExcludeArchiveFilenames(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithDeleteAfterCompression__with_recurseType_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ExcludeArchiveFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithExcludeArchiveFilenames((RecurseType)default, default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeFilenamesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeFilenamesBuilderTests.cs new file mode 100644 index 00000000..9ff969b8 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchExcludeFilenamesBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchExcludeFilenamesBuilderTests + { + [Fact] + public void WithExcludeFilenames_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ExcludeFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithExcludeFilenames(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithExcludeFilenames_with_recursetype_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.ExcludeFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithExcludeFilenames((RecurseType)default, default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchFullyQualifiedFilePathsBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchFullyQualifiedFilePathsBuilderTests.cs new file mode 100644 index 00000000..53a17897 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchFullyQualifiedFilePathsBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchFullyQualifiedFilePathsBuilderTests + { + [Fact] + public void WithFullyQualifiedFilePaths_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.FullyQualifiedFilePaths); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithFullyQualifiedFilePaths(default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeArchiveFilenamesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeArchiveFilenamesBuilderTests.cs new file mode 100644 index 00000000..75530c78 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeArchiveFilenamesBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchIncludeArchiveFilenamesBuilderTests + { + [Fact] + public void WithIncludeArchiveFilenames_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.IncludeArchiveFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithIncludeArchiveFilenames(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithIncludeArchiveFilenames_with_recursetype_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.IncludeArchiveFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithIncludeArchiveFilenames((RecurseType)default, default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeFilenamesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeFilenamesBuilderTests.cs new file mode 100644 index 00000000..5f07ae5f --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchIncludeFilenamesBuilderTests.cs @@ -0,0 +1,40 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchIncludeFilenamesBuilderTests + { + [Fact] + public void WithIncludeFilenames_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.IncludeFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithIncludeFilenames(default); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithIncludeFilenames_with_recursetype_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.IncludeFilenames); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithIncludeFilenames((RecurseType)default, default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchNtSecurityInformationBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchNtSecurityInformationBuilderTests.cs new file mode 100644 index 00000000..4718d093 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchNtSecurityInformationBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchNtSecurityInformationBuilderTests + { + [Fact] + public void WithNtSecurityInformation_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.NtSecurityInformation); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithNtSecurityInformation(); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchNtfsAlternateStreamsBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchNtfsAlternateStreamsBuilderTests.cs new file mode 100644 index 00000000..e3e0746d --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchNtfsAlternateStreamsBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchNtfsAlternateStreamsBuilderTests + { + [Fact] + public void WithNtfsAlternateStreams_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.NtfsAlternateStreams); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithNtfsAlternateStreams(); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchOutputDirectoryBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchOutputDirectoryBuilderTests.cs new file mode 100644 index 00000000..da1a52b2 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchOutputDirectoryBuilderTests.cs @@ -0,0 +1,28 @@ +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchOutputDirectoryBuilderTests + { + [Fact] + public void WithOutputDirectory_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.OutputDirectory); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithOutputDirectory(new DirectoryPath("foo")); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchOverwriteModeBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchOverwriteModeBuilderTests.cs new file mode 100644 index 00000000..428aa24e --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchOverwriteModeBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchOverwriteModeBuilderTests + { + [Fact] + public void WithOverwriteMode_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.OverwriteMode); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithOverwriteMode(default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchPasswordBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchPasswordBuilderTests.cs new file mode 100644 index 00000000..b5df6279 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchPasswordBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchPasswordBuilderTests + { + [Fact] + public void WithPassword_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Password); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithPassword("x"); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchRecurseSubdirectoriesBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchRecurseSubdirectoriesBuilderTests.cs new file mode 100644 index 00000000..531912b7 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchRecurseSubdirectoriesBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchRecurseSubdirectoriesBuilderTests + { + [Fact] + public void WithRecurseSubdirectories_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.RecurseSubdirectories); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithRecurseSubdirectories(default); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchSelfExtractingArchiveBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchSelfExtractingArchiveBuilderTests.cs new file mode 100644 index 00000000..dc93bfcf --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchSelfExtractingArchiveBuilderTests.cs @@ -0,0 +1,41 @@ +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchSelfExtractingArchiveBuilderTests + { + [Fact] + public void WithSelfExtractingArchive_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.SelfExtractingArchive); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithSelfExtractingArchive(); + + actual.Should().Be(expected.Object); + } + + [Fact] + public void WithSelfExtractingArchive_and_module_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.SelfExtractingArchive); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithSelfExtractingArchive(new FilePath("foo")); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchSetTimestampFromMostRecentFileBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchSetTimestampFromMostRecentFileBuilderTests.cs new file mode 100644 index 00000000..d1b4957a --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchSetTimestampFromMostRecentFileBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchSetTimestampFromMostRecentFileBuilderTests + { + [Fact] + public void WithSetTimestampFromMostRecentFile_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.TimestampFromMostRecentFile); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithSetTimestampFromMostRecentFile(); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchUpdateOptionsBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchUpdateOptionsBuilderTests.cs new file mode 100644 index 00000000..b0eea726 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchUpdateOptionsBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchUpdateOptionsBuilderTests + { + [Fact] + public void WithUpdateOptions_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.UpdateOptions); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithUpdateOptions(o => { }); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchVolumeBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchVolumeBuilderTests.cs new file mode 100644 index 00000000..39634437 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchVolumeBuilderTests.cs @@ -0,0 +1,27 @@ +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchVolumeBuilderTests + { + [Fact] + public void WithVolume_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.Volumes); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithVolume(1); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SwitchWorkingDirectoryBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/SwitchWorkingDirectoryBuilderTests.cs new file mode 100644 index 00000000..a83e3947 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/SwitchWorkingDirectoryBuilderTests.cs @@ -0,0 +1,28 @@ +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Switches; + +using FluentAssertions; + +using Moq; + +using Xunit; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class SwitchWorkingDirectoryBuilderTests + { + [Fact] + public void WithWorkingDirectory_returns_the_builder() + { + var expected = new Mock>(); + var command = new Mock(); + command.SetupProperty(c => c.WorkingDirectory); + expected.Setup(x => x.Command).Returns(command.Object); + + var actual = expected.Object.WithWorkingDirectory(new DirectoryPath("foo")); + + actual.Should().Be(expected.Object); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/TestCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/TestCommandBuilderTests.cs new file mode 100644 index 00000000..1548c2f3 --- /dev/null +++ b/src/Cake.7zip.Tests/FluentBuilder/TestCommandBuilderTests.cs @@ -0,0 +1,253 @@ +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Tests.Fixtures; + +using Xunit; +using System; +using FluentAssertions; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class TestCommandBuilderTests + { + [Fact] + public void TestCommand_without_archive_should_throw() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode(); + + Action action = () => fixture.EvaluateArgs(); + + action.Should().Throw(); + } + + [Fact] + public void TestCommand_with_archive_should_work() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")); + + const string expected = @"t ""in.zip"""; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_with_archive_and_file_should_work() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithFiles(new FilePath("*.doc")); + + const string expected = @"t ""in.zip"" ""*.doc"""; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithDisableParsingOfArchiveName() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithDisableParsingOfArchiveName(); + + const string expected = @"t ""in.zip"" -an"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithExcludeArchiveFilenames() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithExcludeArchiveFilenames("*.docx"); + + const string expected = @"t ""in.zip"" -ax!*.docx"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_ExcludeArchiveFiles_multiple_times() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithExcludeArchiveFilenames(RecurseType.Enable, "*.pdf", "*.xps") + .WithExcludeArchiveFilenames("*.txt", "*.ini"); + + const string expected = @"t ""in.zip"" -axr!*.pdf -axr!*.xps -ax!*.txt -ax!*.ini"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithExcludeFilenames() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithExcludeFilenames("*.docx"); + + const string expected = @"t ""in.zip"" -x!*.docx"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_ExcludeFiles_multiple_times() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithExcludeFilenames(RecurseType.Enable, "*.pdf", "*.xps") + .WithExcludeFilenames("*.txt", "*.ini"); + + const string expected = @"t ""in.zip"" -xr!*.pdf -xr!*.xps -x!*.txt -x!*.ini"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithIncludeArchiveFilenames() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithIncludeArchiveFilenames("*.docx"); + + const string expected = @"t ""in.zip"" -ai!*.docx"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_IncludeArchiveFiles_multiple_times() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithIncludeArchiveFilenames(RecurseType.Enable, "*.pdf", "*.xps") + .WithIncludeArchiveFilenames("*.txt", "*.ini"); + + const string expected = @"t ""in.zip"" -air!*.pdf -air!*.xps -ai!*.txt -ai!*.ini"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithIncludeFilenames() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithIncludeFilenames("*.docx"); + + const string expected = @"t ""in.zip"" -i!*.docx"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_IncludeFiles_multiple_times() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithIncludeFilenames(RecurseType.Enable, "*.pdf", "*.xps") + .WithIncludeFilenames("*.txt", "*.ini"); + + const string expected = @"t ""in.zip"" -ir!*.pdf -ir!*.xps -i!*.txt -i!*.ini"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithNtfsAlternateStreams() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithNtfsAlternateStreams(); + + const string expected = @"t ""in.zip"" -sns"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithPassword() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithPassword("password"); + + const string expected = @"t ""in.zip"" -p""password"""; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + + [Fact] + public void TestCommand_can_use_WithRecurseSubdirectories() + { + var fixture = new FluentBuilderFixture(); + fixture.Context + .InTestMode() + .WithArchive(new FilePath("in.zip")) + .WithRecurseSubdirectories(RecurseType.Enable); + + const string expected = @"t ""in.zip"" -r"; + + var actual = fixture.EvaluateArgs(); + + actual.Should().Be(expected); + } + } +} diff --git a/src/Cake.7zip.Tests/FluentBuilder/SevenZipUpdateCommandBuilderTests.cs b/src/Cake.7zip.Tests/FluentBuilder/UpdateCommandBuilderTests.cs similarity index 89% rename from src/Cake.7zip.Tests/FluentBuilder/SevenZipUpdateCommandBuilderTests.cs rename to src/Cake.7zip.Tests/FluentBuilder/UpdateCommandBuilderTests.cs index c9291947..b88a25fa 100644 --- a/src/Cake.7zip.Tests/FluentBuilder/SevenZipUpdateCommandBuilderTests.cs +++ b/src/Cake.7zip.Tests/FluentBuilder/UpdateCommandBuilderTests.cs @@ -1,12 +1,15 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using Cake.Core.IO; - - using System; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Tests.Fixtures; - using Xunit; +using Xunit; +using System; +using Cake.SevenZip.Switches; +using FluentAssertions; - public class SevenZipUpdateCommandBuilderTests +namespace Cake.SevenZip.Tests.FluentBuilder +{ + public class UpdateCommandBuilderTests { [Fact] public void Update_can_use_Archive_and_file() @@ -21,7 +24,7 @@ public void Update_can_use_Archive_and_file() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -37,7 +40,7 @@ public void Update_can_use_Archive_and_directory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -48,9 +51,12 @@ public void Update_throws_on_missing_archive() .InUpdateMode() .WithFiles(new FilePath("in.txt")); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -61,9 +67,12 @@ public void Update_throws_on_missing_fileOrDirectory() .InUpdateMode() .WithArchive(new FilePath("old.zip")); - void result() => fixture.EvaluateArgs(); + Action result = () => + { + fixture.EvaluateArgs(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -79,7 +88,7 @@ public void Update_can_use_Archive_and_file_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -95,7 +104,7 @@ public void Update_can_use_Archive_and_directory_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -111,7 +120,7 @@ public void Update_can_use_Archive_and_directoryContent() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -127,7 +136,7 @@ public void Update_can_use_Archive_and_directoryContent_using_collection() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -144,7 +153,7 @@ public void Update_can_use_ArchiveType() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -165,7 +174,7 @@ public void Update_can_use_CompressionMethod() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -183,7 +192,7 @@ public void Update_can_use_CompressionMethod_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -200,7 +209,7 @@ public void Update_can_use_Sns() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -217,7 +226,7 @@ public void Update_can_use_Snsi() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -234,7 +243,7 @@ public void Update_can_use_Password() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -251,7 +260,7 @@ public void Update_can_use_Ssw() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -268,7 +277,7 @@ public void Update_can_use_Stl() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -285,7 +294,7 @@ public void Update_can_use_WorkingDirectory() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -302,7 +311,7 @@ public void Update_can_use_Recurse() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -319,7 +328,7 @@ public void Update_can_use_IncludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -336,7 +345,7 @@ public void Update_can_use_IncludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -354,7 +363,7 @@ public void Update_can_use_IncludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -371,7 +380,7 @@ public void Update_can_use_ExcludeFiles() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -388,7 +397,7 @@ public void Update_can_use_ExcludeFiles_with_recusion() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -406,7 +415,7 @@ public void Update_can_use_ExcludeFiles_multiple_times() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -424,7 +433,7 @@ public void Update_can_use_UpdateOptions() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -441,7 +450,7 @@ public void Update_can_use_Sfx_without_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -458,7 +467,7 @@ public void Update_can_use_Sfx_with_module() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -475,7 +484,7 @@ public void Update_can_use_FullQualifiedPaths_with_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -492,7 +501,7 @@ public void Update_can_use_FullQualifiedPaths_without_driveletter() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Parsers/InformationOutputParserTests.cs b/src/Cake.7zip.Tests/Parsers/InformationOutputParserTests.cs index 4e893940..4d007d88 100644 --- a/src/Cake.7zip.Tests/Parsers/InformationOutputParserTests.cs +++ b/src/Cake.7zip.Tests/Parsers/InformationOutputParserTests.cs @@ -1,23 +1,16 @@ -namespace Cake.SevenZip.Tests.Builder -{ - using System; - using System.Linq; +using System.Linq; - using Xunit; +using Cake.SevenZip.Parsers; +using Cake.SevenZip.Tests.Fixtures; - public class InformationOutputParserTests - { - [Fact] - public void InformactionCommand_uses_InformationParser() - { - var command = new InformationCommand(); +using FluentAssertions; - var actual = command.OutputParser; - - Assert.NotNull(actual); - Assert.IsType(actual); - } +using Xunit; +namespace Cake.SevenZip.Tests.Parsers +{ + public class InformationOutputParserTests + { [Fact] public void InformationParser_parses_InfoLine() { @@ -26,7 +19,7 @@ public void InformationParser_parses_InfoLine() var actual = parser.Parse(Outputs.Information); const string expected = "7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21"; - Assert.Equal(expected, actual.Information); + actual.Information.Should().Be(expected); } [Fact] @@ -60,11 +53,7 @@ 0 D 40305 Rar5 0 ED 6F10701 7zAES 0 ED 6F00181 AES256CBC".ToArrayOfLines(); - Assert.Equal(expected.Length, actual.Count); - foreach (var codec in expected) - { - Assert.Contains(codec, actual); - } + actual.Should().BeEquivalentTo(expected); } [Fact] @@ -75,11 +64,7 @@ public void InformationParser_parses_Libs() var actual = parser.Parse(Outputs.Information).Libs.ToList(); var expected = new[] { @" 0 C:\Program Files\7-Zip\7z.dll" }; - Assert.Equal(expected.Length, actual.Count); - foreach (var lib in expected) - { - Assert.Contains(lib, actual); - } + actual.Should().BeEquivalentTo(expected); } [Fact] @@ -94,11 +79,8 @@ 0 20 201 SHA1 0 32 A SHA256 0 8 4 CRC64 0 32 202 BLAKE2sp".ToArrayOfLines(); - Assert.Equal(expected.Length, actual.Count); - foreach (var hasher in expected) - { - Assert.Contains(hasher, actual); - } + + actual.Should().BeEquivalentTo(expected); } [Fact] @@ -164,11 +146,7 @@ 0 C SN LH wim wim swm esd ppkg M S W I M 00 00 00 0 C FMG zip zip z01 zipx jar xpi odt ods docx xlsx epub ipa apk appx P K 03 04 || P K 05 06 || P K 06 06 || P K 07 08 P K || P K 0 0 P K" .ToArrayOfLines(); - Assert.Equal(expected.Length, actual.Count); - foreach (var format in expected) - { - Assert.Contains(format, actual); - } + actual.Should().BeEquivalentTo(expected); } } } diff --git a/src/Cake.7zip.Tests/Parsers/TestOutputParserTests.cs b/src/Cake.7zip.Tests/Parsers/TestOutputParserTests.cs new file mode 100644 index 00000000..31c260b7 --- /dev/null +++ b/src/Cake.7zip.Tests/Parsers/TestOutputParserTests.cs @@ -0,0 +1,59 @@ +using System.Linq; + +using Cake.SevenZip.Parsers; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + +namespace Cake.SevenZip.Tests.Parsers +{ + public class TestOutputParserTests + { + [Fact] + public void TestParser_parses_InfoLine() + { + var parser = new TestOutputParser(); + + var actual = parser.Parse(Outputs.Test); + const string expected = "7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21"; + + actual.Information.Should().Be(expected); + } + + [Fact] + public void TestParser_parses_Archives_isOk() + { + var parser = new TestOutputParser(); + string expected = @"Path = .\nested.zip +Type = zip +Physical Size = 2198368 +Everything is Ok +".UnifyLineEndings(); + + var actual = parser.Parse(Outputs.Test).Archives.Single(x => x.IsOk); + + actual.FileName.Should().Be(".\\nested.zip"); + actual.Output.UnifyLineEndings().Should().Be(expected); + } + + [Fact] + public void TestParser_parses_Archives_isNotOk() + { + var parser = new TestOutputParser(); + string expected = @"ERROR: foo.zip +foo.zip +Open ERROR: Can not open the file as [zip] archive +ERRORS: +Is not archive +".UnifyLineEndings(); + ; + + var actual = parser.Parse(Outputs.Test).Archives.Single(x => !x.IsOk); + + actual.FileName.Should().Be("foo.zip"); + actual.Output.UnifyLineEndings().Should().Be(expected); + } + } +} diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchArchiveTypeTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchArchiveTypeTests.cs index 963f0586..87e0d150 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchArchiveTypeTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchArchiveTypeTests.cs @@ -1,43 +1,47 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using System.Reflection; +using System.Collections; +using System.Collections.Generic; + +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using Xunit; +using FluentAssertions; +using Xunit; + +namespace Cake.SevenZip.Tests.Settings.Switches +{ public class SwitchArchiveTypeTests { - [Fact] - public void ArchiveType_works_in_general() + [Theory] + [ClassData(typeof(TestData))] + public void ArchiveType_StaticProps_works(SwitchArchiveType type, string expectedType) { var fixture = new SevenZipSettingsFixture(); - const string type = "SomeArchiveType"; - var sut = new SwitchArchiveType(type); - const string expected = "-t" + type; + var expected = "-t" + expectedType; - var actual = fixture.Parse(b => sut.BuildArguments(ref b)); + var actual = fixture.Parse(b => type.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } - [Theory] - [InlineData("Zip", "zip")] - [InlineData("SevenZip", "7z")] - [InlineData("Xz", "xz")] - [InlineData("Lzma", "lzma")] - [InlineData("Cab", "cab")] - [InlineData("Gzip", "gzip")] - [InlineData("Tar", "tar")] - [InlineData("Bzip2", "bzip2")] - public void ArchiveType_StaticProps_works(string propertyName, string expectedType) + private class TestData : IEnumerable { - var fixture = new SevenZipSettingsFixture(); - var property = typeof(SwitchArchiveType).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static); - var sut = (SwitchArchiveType)property.GetValue(null); - var expected = "-t" + expectedType; - - var actual = fixture.Parse(b => sut.BuildArguments(ref b)); + public IEnumerator GetEnumerator() + { + yield return new object[] { SwitchArchiveType.Zip, "zip" }; + yield return new object[] { SwitchArchiveType.SevenZip, "7z" }; + yield return new object[] { SwitchArchiveType.Xz, "xz" }; + yield return new object[] { SwitchArchiveType.Lzma, "lzma" }; + yield return new object[] { SwitchArchiveType.Cab, "cab" }; + yield return new object[] { SwitchArchiveType.Gzip, "gzip" }; + yield return new object[] { SwitchArchiveType.Tar, "tar" }; + yield return new object[] { SwitchArchiveType.Bzip2, "bzip2" }; + } - Assert.Equal(expected, actual); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchCompressionMethodTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchCompressionMethodTests.cs index 55e3dbae..c668e79f 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchCompressionMethodTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchCompressionMethodTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchCompressionMethodTests { [Fact] @@ -16,7 +21,7 @@ public void CompressionMethod_level_works() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -31,7 +36,7 @@ public void CompressionMethod_method_works() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -47,7 +52,7 @@ public void CompressionMethod_combining_method_and_level() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchDeleteAfterCompressionTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchDeleteAfterCompressionTests.cs index 0091d991..2b2ac805 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchDeleteAfterCompressionTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchDeleteAfterCompressionTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchDeleteAfterCompressionTests { [Fact] @@ -13,7 +18,7 @@ public void Sdel_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Sdel_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchDisableParsingOfArchiveNameTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchDisableParsingOfArchiveNameTests.cs index 8ecbfe10..b12bdafb 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchDisableParsingOfArchiveNameTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchDisableParsingOfArchiveNameTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchDisableParsingOfArchiveNameTests { [Fact] @@ -13,7 +18,7 @@ public void DisableParsingOfArchiveName_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void DisableParsingOfArchiveName_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeArchiveFilenamesTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeArchiveFilenamesTests.cs index ff2e4d25..deee09a3 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeArchiveFilenamesTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeArchiveFilenamesTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchExcludeArchiveFilenamesTests { [Fact] @@ -15,7 +20,7 @@ public void Exclude_multiple_files_outputs_multiple_switches() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -27,7 +32,7 @@ public void Exclude_with_Recurse_enabled__outputs_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -39,7 +44,7 @@ public void Exclude_with_Recurse_disabled_outputs_r_minus() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -51,7 +56,7 @@ public void Exclude_with_Recurse_Wildcards_outputs_r_zero() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -63,7 +68,7 @@ public void Exclude_without_Recurse_outputs_no_recurse() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeFilenamesTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeFilenamesTests.cs index 42820019..63c96367 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeFilenamesTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchExcludeFilenamesTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchExcludeFilenamesTests { [Fact] @@ -15,7 +20,7 @@ public void Exclude_multiple_files_outputs_multiple_switches() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -27,7 +32,7 @@ public void Exclude_with_Recurse_enabled__outputs_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -39,7 +44,7 @@ public void Exclude_with_Recurse_disabled_outputs_r_minus() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -51,7 +56,7 @@ public void Exclude_with_Recurse_Wildcards_outputs_r_zero() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -63,7 +68,7 @@ public void Exclude_without_Recurse_outputs_no_recurse() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeArchiveFilenamesTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeArchiveFilenamesTests.cs index bb100367..1a6e83ac 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeArchiveFilenamesTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeArchiveFilenamesTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchIncludeArchiveFilenamesTests { [Fact] @@ -15,7 +20,7 @@ public void Include_multiple_files_outputs_multiple_switches() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -27,7 +32,7 @@ public void Include_with_Recurse_enabled__outputs_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -39,7 +44,7 @@ public void Include_with_Recurse_disabled_outputs_r_minus() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -51,7 +56,7 @@ public void Include_with_Recurse_Wildcards_outputs_r_zero() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -63,7 +68,7 @@ public void Include_without_Recurse_outputs_no_recurse() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeFilenamesTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeFilenamesTests.cs index 3003f43e..7bed4b2c 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeFilenamesTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchIncludeFilenamesTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchIncludeFilenamesTests { [Fact] @@ -15,7 +20,7 @@ public void Include_multiple_files_outputs_multiple_switches() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -27,7 +32,7 @@ public void Include_with_Recurse_enabled__outputs_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -39,7 +44,7 @@ public void Include_with_Recurse_disabled_outputs_r_minus() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -51,7 +56,7 @@ public void Include_with_Recurse_Wildcards_outputs_r_zero() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -63,7 +68,7 @@ public void Include_without_Recurse_outputs_no_recurse() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchOutputDirectoryTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchOutputDirectoryTests.cs index 95375df1..e80f4d0b 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchOutputDirectoryTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchOutputDirectoryTests.cs @@ -1,9 +1,13 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; - using Xunit; +using Xunit; +namespace Cake.SevenZip.Tests.Settings.Switches +{ public class SwitchOutputDirectoryTests { [Fact] @@ -15,7 +19,7 @@ public void OutputDirectory_works() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchOverwriteModeTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchOverwriteModeTests.cs index 9d748355..9d150b23 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchOverwriteModeTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchOverwriteModeTests.cs @@ -1,9 +1,15 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using System.Reflection; +using System.Collections; +using System.Collections.Generic; + +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using Xunit; +using FluentAssertions; +using Xunit; + +namespace Cake.SevenZip.Tests.Settings.Switches +{ public class SwitchOverwriteModeTests { [Fact] @@ -15,21 +21,30 @@ public void OverwriteMode_sets_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Theory] - [InlineData("Overwrite", "a")] - [InlineData("RenameExisting", "t")] - [InlineData("RenameExtracting", "u")] - [InlineData("Skip", "s")] - public void OverwriteMode_work(string propertyName, string expected) + [ClassData(typeof(TestData))] + public void OverwriteMode_work(OverwriteMode mode, string expected) + { + mode.ToString().Should().Be(expected); + } + + private class TestData : IEnumerable { - var overwriteModeProp = typeof(OverwriteMode).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static); - var overwriteMode = overwriteModeProp.GetValue(null); - Assert.NotNull(overwriteMode); + public IEnumerator GetEnumerator() + { + yield return new object[] { OverwriteMode.Overwrite, "a" }; + yield return new object[] { OverwriteMode.RenameExisting, "t" }; + yield return new object[] { OverwriteMode.RenameExtracting, "u" }; + yield return new object[] { OverwriteMode.Skip, "s" }; + } - Assert.Equal(expected, overwriteMode.ToString()); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchPasswordTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchPasswordTests.cs index 79eb60ca..c3298353 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchPasswordTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchPasswordTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchPasswordTests { [Fact] @@ -13,7 +18,7 @@ public void Password_works() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Password_is_secret() var actual = fixture.ParseSafe(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchRecurseSubdirectoriesTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchRecurseSubdirectoriesTests.cs index 7dede90d..32842720 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchRecurseSubdirectoriesTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchRecurseSubdirectoriesTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchRecurseSubdirectoriesTests { [Fact] @@ -13,7 +18,7 @@ public void Recurse_set_outputs_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Recurse_unset_outputs_r_minus() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -37,7 +42,7 @@ public void Recurse_wildcard_outputs_r_zero() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchSniTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchSniTests.cs index abff3ea9..3d0cb8a4 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchSniTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchSniTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchSniTests { [Fact] @@ -13,7 +18,7 @@ public void Sni_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Sni_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchSnsTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchSnsTests.cs index 2c8b0c78..9ab81ec2 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchSnsTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchSnsTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchSnsTests { [Fact] @@ -13,7 +18,7 @@ public void Sns_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Sns_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchSswTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchSswTests.cs index ef377072..6c954335 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchSswTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchSswTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchSswTests { [Fact] @@ -13,7 +18,7 @@ public void Ssw_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Ssw_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchStlTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchStlTests.cs index 9507cc75..368dd285 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchStlTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchStlTests.cs @@ -1,7 +1,12 @@ +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.SevenZip.Tests.Settings.Switches { - using Xunit; - public class SwitchStlTests { [Fact] @@ -13,7 +18,7 @@ public void Stl_set_outputs_switch() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -25,7 +30,7 @@ public void Stl_not_set_outputs_nothing() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchUpdateOptionsTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchUpdateOptionsTests.cs index 91c6e9ed..cf400638 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchUpdateOptionsTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchUpdateOptionsTests.cs @@ -1,9 +1,14 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using System.Reflection; +using System.Reflection; + +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using Xunit; +using FluentAssertions; +using Xunit; + +namespace Cake.SevenZip.Tests.Settings.Switches +{ public class SwitchUpdateOptionsTests { [Fact] @@ -18,7 +23,7 @@ public void UpdateAction_sets_p() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -33,7 +38,7 @@ public void UpdateAction_sets_q() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -48,7 +53,7 @@ public void UpdateAction_sets_r() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -63,7 +68,7 @@ public void UpdateAction_sets_x() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -78,7 +83,7 @@ public void UpdateAction_sets_y() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -93,7 +98,7 @@ public void UpdateAction_sets_z() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -108,7 +113,7 @@ public void UpdateAction_sets_w() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -123,7 +128,7 @@ public void UpdateAction_sets_NewName() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -145,7 +150,7 @@ public void UpdateAction_sets_CombinedValues() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Theory] @@ -157,9 +162,9 @@ public void UpdateActions_work(string propertyName, string expected) { var updateActionProp = typeof(UpdateAction).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static); var updateAction = updateActionProp.GetValue(null); - Assert.NotNull(updateAction); - Assert.Equal(expected, updateAction.ToString()); + updateAction.Should().NotBeNull(); + updateAction.ToString().Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchVolumeTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchVolumeTests.cs index 81a21790..b54d6fc5 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchVolumeTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchVolumeTests.cs @@ -1,9 +1,16 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using System; +using System; +using System.Diagnostics.CodeAnalysis; + +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; - using Xunit; +using FluentAssertions; +using Xunit; + +namespace Cake.SevenZip.Tests.Settings.Switches +{ + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "I like my 'local functions' camelCase.")] public class SwitchVolumeTests { [Fact] @@ -19,7 +26,7 @@ public void Volumes_with_Bytes_work() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -35,7 +42,7 @@ public void Volumes_with_Kilobytes_work() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -51,7 +58,7 @@ public void Volumes_with_Megabytes_work() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -67,7 +74,7 @@ public void Volumes_with_Gigabytes_work() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -82,7 +89,7 @@ public void Volumes_without_Units_work() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -92,10 +99,12 @@ public void Should_Throw_On_Volumes_without_Site() var sut = new SwitchVolume(); const string expectedMessage = "Can not create volumes with size < 1"; - void result() => fixture.Parse(b => sut.BuildArguments(ref b)); + Action result = () => + { + fixture.Parse(b => sut.BuildArguments(ref b)); + }; - var ex = Assert.Throws(result); - Assert.Equal(expectedMessage, ex.Message); + result.Should().Throw().WithMessage(expectedMessage); } [Fact] @@ -108,10 +117,12 @@ public void Should_Throw_On_Volumes_with_negative_Site() }; const string expectedMessage = "Can not create volumes with size < 1"; - void result() => fixture.Parse(b => sut.BuildArguments(ref b)); + Action result = () => + { + fixture.Parse(b => sut.BuildArguments(ref b)); + }; - var ex = Assert.Throws(result); - Assert.Equal(expectedMessage, ex.Message); + result.Should().Throw().WithMessage(expectedMessage); } } } diff --git a/src/Cake.7zip.Tests/Settings/Switches/SwitchWorkingDirectoryTests.cs b/src/Cake.7zip.Tests/Settings/Switches/SwitchWorkingDirectoryTests.cs index db1625b7..2bb598e0 100644 --- a/src/Cake.7zip.Tests/Settings/Switches/SwitchWorkingDirectoryTests.cs +++ b/src/Cake.7zip.Tests/Settings/Switches/SwitchWorkingDirectoryTests.cs @@ -1,9 +1,13 @@ -namespace Cake.SevenZip.Tests.Settings.Switches -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; + +using FluentAssertions; - using Xunit; +using Xunit; +namespace Cake.SevenZip.Tests.Settings.Switches +{ public class SwitchWorkingDirectoryTests { [Fact] @@ -15,7 +19,7 @@ public void WorkingDirectory_works() var actual = fixture.Parse(b => sut.BuildArguments(ref b)); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } } } diff --git a/src/Cake.7zip.Tests/SevenZipAliasesTests.cs b/src/Cake.7zip.Tests/SevenZipAliasesTests.cs index 33159bd1..b9f95dbc 100644 --- a/src/Cake.7zip.Tests/SevenZipAliasesTests.cs +++ b/src/Cake.7zip.Tests/SevenZipAliasesTests.cs @@ -1,10 +1,10 @@ using Cake.Core.IO; -using Cake.Testing; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Tests.Fixtures; using Moq; -using System.Text; - using Xunit; namespace Cake.SevenZip.Tests @@ -36,5 +36,20 @@ public void Should_support_using_fluent_add() // TODO WHAT TO TEST?! - and how?! } + + [Fact] + public void Should_Override_Command_when_using_settings_and_builder() + { + var fixture = new SevenZipAliasesFixture(); + var dotNotUseCommand = new Mock(); + fixture.Settings.Command = dotNotUseCommand.Object; + + fixture.Context.SevenZip(fixture.Settings, s => s + .InAddMode() + .WithArchive("zip.zip") + .WithFiles("in.txt")); + + dotNotUseCommand.Verify(x => x.BuildArguments(ref It.Ref.IsAny), Times.Never); + } } } diff --git a/src/Cake.7zip.Tests/SevenZipRunnerTests.cs b/src/Cake.7zip.Tests/SevenZipRunnerTests.cs index 6334bafa..ab8661b4 100644 --- a/src/Cake.7zip.Tests/SevenZipRunnerTests.cs +++ b/src/Cake.7zip.Tests/SevenZipRunnerTests.cs @@ -1,17 +1,23 @@ -namespace Cake.SevenZip.Tests -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; +using System; +using System.Diagnostics.CodeAnalysis; - using Cake.Core; - using Cake.Core.IO; - using Cake.Testing; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; +using Cake.SevenZip.Switches; +using Cake.SevenZip.Tests.Fixtures; +using Cake.Testing; - using Moq; +using FluentAssertions; - using Xunit; +using Moq; +using Xunit; + +namespace Cake.SevenZip.Tests +{ + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "I like my 'local functions' camelCase.")] public class SevenZipRunnerTests { [Fact] @@ -19,9 +25,12 @@ public void Should_Throw_If_Settings_Are_Null() { var fixture = new SevenZipRunnerFixture { Settings = null }; - void result() => fixture.Run(); + Action result = () => + { + fixture.Run(); + }; - Assert.Throws(result); + result.Should().Throw(); } [Fact] @@ -37,10 +46,12 @@ public void Should_Throw_If_SevenZip_Executable_Was_Not_Found() fixture.GivenDefaultToolDoNotExist(); const string expectedMessage = "7-Zip: Could not locate executable."; - void result() => fixture.Run(); + Action result = () => + { + fixture.Run(); + }; - var ex = Assert.Throws(result); - Assert.Equal(expectedMessage, ex.Message); + result.Should().Throw().WithMessage(expectedMessage); } [Fact] @@ -55,10 +66,12 @@ public void Should_Throw_If_Command_is_null() }; const string expectedMessage = "7-Zip: Command can not be null - a command is needed to run!"; - void result() => fixture.Run(); + Action result = () => + { + fixture.Run(); + }; - var ex = Assert.Throws(result); - Assert.Equal(expectedMessage, ex.Message); + result.Should().Throw().WithMessage(expectedMessage); } [Fact] @@ -90,7 +103,7 @@ public void Should_Access_registry() sevenZipKey.Verify(k => k.GetValue("Path"), Times.Once); sevenZipKey.Verify(k => k.GetValue("Path64"), Times.Once); - Assert.Equal(file.Path.FullPath, result.Path.FullPath); + result.Path.FullPath.Should().Be(file.Path.FullPath); } [Fact] @@ -121,7 +134,7 @@ public void Should_Access_64bit_tool_from_registry() var result = fixture.Run(); - Assert.Equal(file.Path.FullPath, result.Path.FullPath); + result.Path.FullPath.Should().Be(file.Path.FullPath); } [Fact] @@ -139,7 +152,7 @@ public void Should_not_access_registry_if_Default_exists() var sevenZipKey = new Mock(); sevenZipKey.Setup(k => k.GetValue("Path")).Returns(string.Empty); - sevenZipKey.Setup(k => k.GetValue("Path64")).Returns(String.Empty); + sevenZipKey.Setup(k => k.GetValue("Path64")).Returns(string.Empty); var softwareKey = new Mock(); softwareKey.Setup(k => k.OpenKey("7-Zip")).Returns(sevenZipKey.Object); var hklm = new Mock(); @@ -149,7 +162,7 @@ public void Should_not_access_registry_if_Default_exists() var result = fixture.Run(); sevenZipKey.Verify(k => k.GetValue("Path"), Times.Never); - Assert.Equal(fixture.DefaultToolPath.FullPath, result.Path.FullPath); + result.Path.FullPath.Should().Be(fixture.DefaultToolPath.FullPath); } [Fact] @@ -168,9 +181,12 @@ public void Should_throw_ToolNotFound_if_registry_throws() hklm.Setup(k => k.OpenKey("Software")).Throws(new AccessViolationException("No!")); fixture.Registry.Setup(r => r.LocalMachine).Returns(hklm.Object); - void action() => fixture.Run(); + Action action = () => + { + fixture.Run(); + }; - Assert.Throws(action); + action.Should().Throw(); } [Fact] @@ -191,7 +207,7 @@ public void Can_zip_some_Files() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -223,7 +239,7 @@ public void Can_zip_and_split_some_Files() var actual = fixture.EvaluateArgs(); - Assert.Equal(expected, actual); + actual.Should().Be(expected); } [Fact] @@ -241,16 +257,18 @@ public void Should_Throw_CakeException_If_Command_throws() }; const string expectedMessage = "7-Zip: Intentionally not implemented."; - void result() => fixture.Run(); + Action result = () => + { + fixture.Run(); + }; - var ex = Assert.Throws(result); - Assert.Equal(expectedMessage, ex.Message); + result.Should().Throw().WithMessage(expectedMessage); } [Fact] public void Should_Set_output_null_on_outputCommand_whithout_output() { - var command = new Mock>(); + var command = new Mock>(); var outputParseCommand = command.As(); var fixture = new SevenZipRunnerFixture { @@ -269,9 +287,9 @@ public void Should_Set_output_null_on_outputCommand_whithout_output() [Fact] public void Should_Set_output_on_outputCommand() { - var command = new Mock>(); + var command = new Mock>(); var outputParseCommand = command.As(); - var parser = new Mock>(); + var parser = new Mock>(); command.Setup(c => c.OutputParser).Returns(parser.Object); var fixture = new SevenZipRunnerFixture { diff --git a/src/Cake.7zip.Tests/TestExtensions.cs b/src/Cake.7zip.Tests/TestExtensions.cs index 2c69075d..6dee1daa 100644 --- a/src/Cake.7zip.Tests/TestExtensions.cs +++ b/src/Cake.7zip.Tests/TestExtensions.cs @@ -1,13 +1,17 @@ +using System; + namespace Cake.SevenZip.Tests { - using System; - using System.Linq; - internal static class TestExtensions { internal static string[] ToArrayOfLines(this string @this) { - return @this.Split(new[] { "\n" }, StringSplitOptions.None).Select(x => x.TrimEnd('\r')).ToArray(); + return @this.UnifyLineEndings().Split(new[] { "\n" }, StringSplitOptions.None); + } + + internal static string UnifyLineEndings(this string @this) + { + return @this.Replace("\r\n", "\n"); } } } diff --git a/src/Cake.7zip.sln b/src/Cake.7zip.sln index 92c3834f..ae096cfb 100644 --- a/src/Cake.7zip.sln +++ b/src/Cake.7zip.sln @@ -6,6 +6,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.7zip", "Cake.7zip\Cake EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.7zip.Tests", "Cake.7zip.Tests\Cake.7zip.Tests.csproj", "{6F2FDEF2-F7D3-4A7D-BF68-6A76AE030AA9}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5AD2C813-1A4A-4F65-9C5A-B22EF216CABD}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Cake.7zip.sln.vsspell = Cake.7zip.sln.vsspell + vsspell.ignoredWords.txt = vsspell.ignoredWords.txt + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/Cake.7zip.sln.DotSettings b/src/Cake.7zip.sln.DotSettings new file mode 100644 index 00000000..ed3964a6 --- /dev/null +++ b/src/Cake.7zip.sln.DotSettings @@ -0,0 +1,3 @@ + + DO_NOT_SHOW + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> \ No newline at end of file diff --git a/src/Cake.7zip.sln.vsspell b/src/Cake.7zip.sln.vsspell new file mode 100644 index 00000000..158b2c3f --- /dev/null +++ b/src/Cake.7zip.sln.vsspell @@ -0,0 +1,33 @@ + + + + True + True + + en-US + + + False + False + False + False + False + False + False + + True + + False + + vsspell.ignoredWords.txt + True + False + + *Tests.cs + Outputs.cs + + False + + + \ No newline at end of file diff --git a/src/Cake.7zip/AssemblyAttributes.cs b/src/Cake.7zip/AssemblyAttributes.cs new file mode 100644 index 00000000..d8211658 --- /dev/null +++ b/src/Cake.7zip/AssemblyAttributes.cs @@ -0,0 +1,10 @@ +using System.Runtime.CompilerServices; + +using Cake.Core.Annotations; + +[assembly: InternalsVisibleTo("Cake.7zip.Tests")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: CakeNamespaceImport("Cake.SevenZip.Switches")] +[assembly: CakeNamespaceImport("Cake.SevenZip.Commands")] +[assembly: CakeNamespaceImport("Cake.SevenZip.Builder")] +[assembly: CakeNamespaceImport("Cake.SevenZip.Parsers")] diff --git a/src/Cake.7zip/Builder/AddCommandBuilder.cs b/src/Cake.7zip/Builder/AddCommandBuilder.cs index 09e9de6d..d71d879f 100644 --- a/src/Cake.7zip/Builder/AddCommandBuilder.cs +++ b/src/Cake.7zip/Builder/AddCommandBuilder.cs @@ -1,4 +1,7 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Builder for . diff --git a/src/Cake.7zip/Builder/ArgumentArchiveBuilder.cs b/src/Cake.7zip/Builder/ArgumentArchiveBuilder.cs index 6e86da49..93bf0fa9 100644 --- a/src/Cake.7zip/Builder/ArgumentArchiveBuilder.cs +++ b/src/Cake.7zip/Builder/ArgumentArchiveBuilder.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Commands; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/ArgumentDirectoriesBuilder.cs b/src/Cake.7zip/Builder/ArgumentDirectoriesBuilder.cs index af7a38f3..6037e8b2 100644 --- a/src/Cake.7zip/Builder/ArgumentDirectoriesBuilder.cs +++ b/src/Cake.7zip/Builder/ArgumentDirectoriesBuilder.cs @@ -1,9 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Linq; +using System.Linq; - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Commands; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// @@ -48,7 +49,7 @@ public static T WithDirectories(this T @this, params DirectoryPath[] director public static T WithDirectories(this T @this, DirectoryPathCollection directories) where T : ISupportArgumentBuilder { - return WithDirectories(@this, directories.ToArray()); + return WithDirectories(@this, directories.ToArray()); } /// @@ -89,7 +90,7 @@ public static T WithDirectoryContents(this T @this, params DirectoryPath[] di public static T WithDirectoryContents(this T @this, DirectoryPathCollection directories) where T : ISupportArgumentBuilder { - return WithDirectoryContents(@this, directories.ToArray()); + return WithDirectoryContents(@this, directories.ToArray()); } } } diff --git a/src/Cake.7zip/Builder/ArgumentFilesBuilder.cs b/src/Cake.7zip/Builder/ArgumentFilesBuilder.cs index 209f5322..34dd9be8 100644 --- a/src/Cake.7zip/Builder/ArgumentFilesBuilder.cs +++ b/src/Cake.7zip/Builder/ArgumentFilesBuilder.cs @@ -1,9 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Linq; +using System.Linq; - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Commands; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// @@ -48,7 +49,7 @@ public static T WithFiles(this T @this, params FilePath[] files) public static T WithFiles(this T @this, FilePathCollection files) where T : ISupportArgumentBuilder { - return WithFiles(@this, files.ToArray()); + return WithFiles(@this, files.ToArray()); } } } diff --git a/src/Cake.7zip/Builder/BaseOutputBuilder.cs b/src/Cake.7zip/Builder/BaseOutputBuilder.cs new file mode 100644 index 00000000..4a9717ae --- /dev/null +++ b/src/Cake.7zip/Builder/BaseOutputBuilder.cs @@ -0,0 +1,50 @@ +using System; + +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; + +namespace Cake.SevenZip.Builder +{ + /// + /// Base for builders that support . + /// + /// the command-builder that extends this base-class. Only needed for "nice" fluid-tying. + /// the output of the supported by this builder. + public abstract class BaseOutputBuilder + where TBuilder : BaseOutputBuilder + where TOutput : IOutput + { + /// + /// Gets the output command. + /// + /// + /// The output command. + /// + protected abstract OutputCommand OutputCommand { get; } + + // the following are no extensions (and this is no interface), because all those crazy generics can't be + // automatically resolved in an extension. That would lead to bad non-fluid-typing in the DSL... + + /// + /// fluent action to set the output-action of . + /// + /// the action to perform on the output. + /// The builder-instance for fluent re-use. + public TBuilder WithCommandOutput(Action outputAction) + { + OutputCommand.OutputAction = outputAction; + return (TBuilder)this; + } + + /// + /// fluent action to set the raw-output of . + /// + /// the action to perform on the output. + /// The builder-instance for fluent re-use. + public TBuilder WithCommandRawOutput(Action rawOutputAction) + { + OutputCommand.RawOutputAction = rawOutputAction; + return (TBuilder)this; + } + } +} diff --git a/src/Cake.7zip/Builder/CommandBuilder.cs b/src/Cake.7zip/Builder/CommandBuilder.cs index a2957278..7712beaa 100644 --- a/src/Cake.7zip/Builder/CommandBuilder.cs +++ b/src/Cake.7zip/Builder/CommandBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; + +namespace Cake.SevenZip.Builder { /// /// Builder for all s. @@ -7,12 +9,12 @@ namespace Cake.SevenZip public sealed class CommandBuilder { /// - /// Gets or sets the Command. + /// Gets the Command. /// /// /// The Command. /// - internal ICommand Command { get; set; } + internal ICommand Command { get; private set; } /// /// Makes this Builder an AddCommand-Builder. @@ -68,5 +70,16 @@ public InformationCommandBuilder InInformationMode() Command = command; return new InformationCommandBuilder(ref command); } + + /// + /// Makes this Builder a TestCommand-Builder. + /// + /// . + public TestCommandBuilder InTestMode() + { + var command = new TestCommand(); + Command = command; + return new TestCommandBuilder(ref command); + } } } diff --git a/src/Cake.7zip/Builder/DeleteCommandBuilder.cs b/src/Cake.7zip/Builder/DeleteCommandBuilder.cs index c4a4f29e..7d4dce91 100644 --- a/src/Cake.7zip/Builder/DeleteCommandBuilder.cs +++ b/src/Cake.7zip/Builder/DeleteCommandBuilder.cs @@ -1,4 +1,7 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Builder for . diff --git a/src/Cake.7zip/Builder/ExtractCommandBuilder.cs b/src/Cake.7zip/Builder/ExtractCommandBuilder.cs index 3da4b642..2b702459 100644 --- a/src/Cake.7zip/Builder/ExtractCommandBuilder.cs +++ b/src/Cake.7zip/Builder/ExtractCommandBuilder.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Builder for . /// @@ -21,7 +22,7 @@ namespace Cake.SevenZip /// ]]> /// /// - public class ExtractCommandBuilder : + public sealed class ExtractCommandBuilder : ISupportArgumentBuilder, ISupportSwitchBuilder, ISupportSwitchBuilder, @@ -44,7 +45,7 @@ public class ExtractCommandBuilder : /// Initializes a new instance of the class. /// /// The command. - public ExtractCommandBuilder(ref ExtractCommand command) + internal ExtractCommandBuilder(ref ExtractCommand command) { this.command = command; } @@ -95,7 +96,7 @@ public ExtractCommandBuilder(ref ExtractCommand command) ISupportSwitchFullyQualifiedFilePaths ISupportSwitchBuilder.Command => command; /// - /// Sets UseFullPaths to true on the . + /// Sets UseFullPaths to true on the . /// /// The builder, for fluent use. public ExtractCommandBuilder WithFullPathExtraction() @@ -105,7 +106,7 @@ public ExtractCommandBuilder WithFullPathExtraction() } /// - /// Sets UseFullPaths to false on the . + /// Sets UseFullPaths to false on the . /// (copies all extracted files to one directory). /// /// The builder, for fluent use. diff --git a/src/Cake.7zip/Builder/ISupportArgumentBuilder.cs b/src/Cake.7zip/Builder/ISupportArgumentBuilder.cs index f43b6462..b673203c 100644 --- a/src/Cake.7zip/Builder/ISupportArgumentBuilder.cs +++ b/src/Cake.7zip/Builder/ISupportArgumentBuilder.cs @@ -1,17 +1,19 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; + +namespace Cake.SevenZip.Builder { /// /// Base for builders that support arguments. /// - /// the suppored by this builder. - public interface ISupportArgumentBuilder + /// the supported by this builder. + public interface ISupportArgumentBuilder where T : IHaveArgument { /// /// Gets the command that supports the given argument. /// /// - /// The agument. + /// The argument. /// T Command { get; } } diff --git a/src/Cake.7zip/Builder/ISupportOutputBuilder.cs b/src/Cake.7zip/Builder/ISupportOutputBuilder.cs deleted file mode 100644 index dcb51d8e..00000000 --- a/src/Cake.7zip/Builder/ISupportOutputBuilder.cs +++ /dev/null @@ -1,83 +0,0 @@ -namespace Cake.SevenZip -{ - using System; - - /// - /// Internal interface to make the extensions more type-able. - /// - /// the output of the supported by this builder. - public interface ISupportOutputBuilder - { - /// - /// Sets the output-action from the command. - /// - /// - /// The output. - /// - Action OutputAction { set; } - - /// - /// Sets the raw output-action from the command. - /// - /// - /// The raw output. - /// - Action RawOutputAction { set; } - } - - /// - /// Base for builders that support . - /// - /// the command-builder that extends this base-class. Only needed for "nice" fluid-tying. - /// the supported by this builder. - /// the output of the supported by this builder. - public abstract class BaseOutputBuilder : ISupportOutputBuilder - where TBuilder : BaseOutputBuilder, ISupportOutputBuilder - where TCommand : OutputCommand - { - /// - public Action OutputAction - { - set { OutputCommand.OutputAction = value; } - } - - /// - public Action RawOutputAction - { - set { OutputCommand.RawOutputAction = value; } - } - - /// - /// Gets the output command. - /// - /// - /// The output command. - /// - protected abstract OutputCommand OutputCommand { get; } - - // the following are no extensions, because all those crazy generics can't be - // automatically resolved in an extension. That would lead to bad non-fluid-typing... - - /// - /// fluent action to set the output-action of . - /// - /// the action to perform on the output. - /// The builder-instance for fluent re-use. - public TBuilder WithCommandOutput(Action outputAction) - { - OutputAction = outputAction; - return (TBuilder)this; - } - - /// - /// fluent action to set the raw-output of . - /// - /// the action to perform on the output. - /// The builder-instance for fluent re-use. - public TBuilder WithCommandRawOutput(Action rawOutputAction) - { - RawOutputAction = rawOutputAction; - return (TBuilder)this; - } - } -} diff --git a/src/Cake.7zip/Builder/ISupportSwitchBuilder.cs b/src/Cake.7zip/Builder/ISupportSwitchBuilder.cs index 5b4e042c..6b63ce90 100644 --- a/src/Cake.7zip/Builder/ISupportSwitchBuilder.cs +++ b/src/Cake.7zip/Builder/ISupportSwitchBuilder.cs @@ -1,10 +1,12 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Base for builders that support switches. /// - /// the suppored by this builder. - public interface ISupportSwitchBuilder + /// the supported by this builder. + public interface ISupportSwitchBuilder where T : ISupportSwitch { /// diff --git a/src/Cake.7zip/Builder/InformationCommandBuilder.cs b/src/Cake.7zip/Builder/InformationCommandBuilder.cs index dba95b1c..86860243 100644 --- a/src/Cake.7zip/Builder/InformationCommandBuilder.cs +++ b/src/Cake.7zip/Builder/InformationCommandBuilder.cs @@ -1,4 +1,7 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; + +namespace Cake.SevenZip.Builder { /// /// Builder for . @@ -12,7 +15,7 @@ namespace Cake.SevenZip /// { /// SevenZip(m => m /// .InInformationMode() - /// .WithCommandOutput((IInformationOutput o) => + /// .WithCommandOutput(o => /// { /// Information("7Zip version is:" + o.Information); /// Information("7Zip supports QCOW:" + (o.Formats.Any(x => x.IndexOf("QCOW") > -1))); @@ -22,7 +25,7 @@ namespace Cake.SevenZip /// /// public sealed class InformationCommandBuilder : - BaseOutputBuilder + BaseOutputBuilder { private readonly InformationCommand command; diff --git a/src/Cake.7zip/Builder/SwitchArchiveTypeBuilder.cs b/src/Cake.7zip/Builder/SwitchArchiveTypeBuilder.cs index 4cc71f58..240bf3e8 100644 --- a/src/Cake.7zip/Builder/SwitchArchiveTypeBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchArchiveTypeBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . @@ -13,10 +15,10 @@ public static class SwitchArchiveTypeBuilder /// The builder-instance. /// The type to set. /// The builder-instance for fluent re-use. - public static T WithArchiveType(this T @this, SwitchArchiveType @type) + public static T WithArchiveType(this T @this, SwitchArchiveType type) where T : ISupportSwitchBuilder { - @this.Command.ArchiveType = @type; + @this.Command.ArchiveType = type; return @this; } diff --git a/src/Cake.7zip/Builder/SwitchCompressFilesOpenForWritingBuilder.cs b/src/Cake.7zip/Builder/SwitchCompressFilesOpenForWritingBuilder.cs index 943fd490..befdf204 100644 --- a/src/Cake.7zip/Builder/SwitchCompressFilesOpenForWritingBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchCompressFilesOpenForWritingBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchCompressionMethodBuilder.cs b/src/Cake.7zip/Builder/SwitchCompressionMethodBuilder.cs index 87350c51..5106dd5a 100644 --- a/src/Cake.7zip/Builder/SwitchCompressionMethodBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchCompressionMethodBuilder.cs @@ -1,7 +1,9 @@ -namespace Cake.SevenZip -{ - using System; +using System; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchDeleteAfterCompressionBuilder.cs b/src/Cake.7zip/Builder/SwitchDeleteAfterCompressionBuilder.cs index a9bd6adb..12b713b3 100644 --- a/src/Cake.7zip/Builder/SwitchDeleteAfterCompressionBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchDeleteAfterCompressionBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchDisableParsingOfArchiveNameBuilder.cs b/src/Cake.7zip/Builder/SwitchDisableParsingOfArchiveNameBuilder.cs index ce84cafa..8ecb69a0 100644 --- a/src/Cake.7zip/Builder/SwitchDisableParsingOfArchiveNameBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchDisableParsingOfArchiveNameBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchExcludeArchiveFilenamesBuilder.cs b/src/Cake.7zip/Builder/SwitchExcludeArchiveFilenamesBuilder.cs index ffb7aa86..15201f56 100644 --- a/src/Cake.7zip/Builder/SwitchExcludeArchiveFilenamesBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchExcludeArchiveFilenamesBuilder.cs @@ -1,8 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; - using System.Linq; +using System.Collections.Generic; +using System.Linq; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchExcludeFilenamesBuilder.cs b/src/Cake.7zip/Builder/SwitchExcludeFilenamesBuilder.cs index 722b427b..0628735e 100644 --- a/src/Cake.7zip/Builder/SwitchExcludeFilenamesBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchExcludeFilenamesBuilder.cs @@ -1,8 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; - using System.Linq; +using System.Collections.Generic; +using System.Linq; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchFullyQualifiedFilePathsBuilder.cs b/src/Cake.7zip/Builder/SwitchFullyQualifiedFilePathsBuilder.cs index 10adcf8e..92788ad7 100644 --- a/src/Cake.7zip/Builder/SwitchFullyQualifiedFilePathsBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchFullyQualifiedFilePathsBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . @@ -11,7 +13,7 @@ public static class SwitchFullyQualifiedFilePathsBuilder /// /// the builder to support the . /// The builder-instance. - /// Whether to include driveletters or not. + /// Whether to include drive-letters or not. /// The builder-instance for fluent re-use. public static T WithFullyQualifiedFilePaths(this T @this, bool includeDriveLetters) where T : ISupportSwitchBuilder diff --git a/src/Cake.7zip/Builder/SwitchIncludeArchiveFilenamesBuilder.cs b/src/Cake.7zip/Builder/SwitchIncludeArchiveFilenamesBuilder.cs index 0167e0c0..b184d31e 100644 --- a/src/Cake.7zip/Builder/SwitchIncludeArchiveFilenamesBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchIncludeArchiveFilenamesBuilder.cs @@ -1,8 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; - using System.Linq; +using System.Collections.Generic; +using System.Linq; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchIncludeFilenamesBuilder.cs b/src/Cake.7zip/Builder/SwitchIncludeFilenamesBuilder.cs index c1333701..5e185fbc 100644 --- a/src/Cake.7zip/Builder/SwitchIncludeFilenamesBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchIncludeFilenamesBuilder.cs @@ -1,8 +1,10 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; - using System.Linq; +using System.Collections.Generic; +using System.Linq; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchNtSecurityInformationBuilder.cs b/src/Cake.7zip/Builder/SwitchNtSecurityInformationBuilder.cs index 3bed46cd..4e620cb4 100644 --- a/src/Cake.7zip/Builder/SwitchNtSecurityInformationBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchNtSecurityInformationBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchNtfsAlternateStreamsBuilder.cs b/src/Cake.7zip/Builder/SwitchNtfsAlternateStreamsBuilder.cs index 27fcd961..b2912699 100644 --- a/src/Cake.7zip/Builder/SwitchNtfsAlternateStreamsBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchNtfsAlternateStreamsBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchOutputDirectoryBuilder.cs b/src/Cake.7zip/Builder/SwitchOutputDirectoryBuilder.cs index a7b9692e..33e7980e 100644 --- a/src/Cake.7zip/Builder/SwitchOutputDirectoryBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchOutputDirectoryBuilder.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchOverwriteModeBuilder.cs b/src/Cake.7zip/Builder/SwitchOverwriteModeBuilder.cs index 55b21843..ec8c4588 100644 --- a/src/Cake.7zip/Builder/SwitchOverwriteModeBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchOverwriteModeBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchPasswordBuilder.cs b/src/Cake.7zip/Builder/SwitchPasswordBuilder.cs index 56324cc7..9bcbed15 100644 --- a/src/Cake.7zip/Builder/SwitchPasswordBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchPasswordBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchRecurseSubdirectoriesBuilder.cs b/src/Cake.7zip/Builder/SwitchRecurseSubdirectoriesBuilder.cs index d8bd1e10..caf97387 100644 --- a/src/Cake.7zip/Builder/SwitchRecurseSubdirectoriesBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchRecurseSubdirectoriesBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchSelfExtractingArchiveBuilder.cs b/src/Cake.7zip/Builder/SwitchSelfExtractingArchiveBuilder.cs index ce489610..db4fb0a9 100644 --- a/src/Cake.7zip/Builder/SwitchSelfExtractingArchiveBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchSelfExtractingArchiveBuilder.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// @@ -13,9 +14,9 @@ public static class SwitchSelfExtractingArchiveBuilder /// /// the builder to support the . /// The builder-instance. - /// The sfx-module to set. + /// The sfx-module to set. If omitted, the default is used. /// The builder-instance for fluent re-use. - public static T WithSelfExtractingArchive(this T @this, FilePath module) + public static T WithSelfExtractingArchive(this T @this, FilePath module = null) where T : ISupportSwitchBuilder { if (@this.Command.SelfExtractingArchive == null) @@ -27,17 +28,5 @@ public static T WithSelfExtractingArchive(this T @this, FilePath module) return @this; } - - /// - /// . - /// - /// the builder to support the . - /// The builder-instance. - /// The builder-instance for fluent re-use. - public static T WithSelfExtractingArchive(this T @this) - where T : ISupportSwitchBuilder - { - return WithSelfExtractingArchive(@this, null); - } } } diff --git a/src/Cake.7zip/Builder/SwitchSetTimestampFromMostRecentFileBuilder.cs b/src/Cake.7zip/Builder/SwitchSetTimestampFromMostRecentFileBuilder.cs index 2d507db9..6fa1235b 100644 --- a/src/Cake.7zip/Builder/SwitchSetTimestampFromMostRecentFileBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchSetTimestampFromMostRecentFileBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchUpdateOptionsBuilder.cs b/src/Cake.7zip/Builder/SwitchUpdateOptionsBuilder.cs index 99c63383..160d8537 100644 --- a/src/Cake.7zip/Builder/SwitchUpdateOptionsBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchUpdateOptionsBuilder.cs @@ -1,7 +1,9 @@ -namespace Cake.SevenZip -{ - using System; +using System; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/SwitchVolumeBuilder.cs b/src/Cake.7zip/Builder/SwitchVolumeBuilder.cs index 7d3e39b8..93ceff63 100644 --- a/src/Cake.7zip/Builder/SwitchVolumeBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchVolumeBuilder.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Extensions for all Builders that support . diff --git a/src/Cake.7zip/Builder/SwitchWorkingDirectoryBuilder.cs b/src/Cake.7zip/Builder/SwitchWorkingDirectoryBuilder.cs index 282abbb6..a4b3401a 100644 --- a/src/Cake.7zip/Builder/SwitchWorkingDirectoryBuilder.cs +++ b/src/Cake.7zip/Builder/SwitchWorkingDirectoryBuilder.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Builder +{ /// /// Extensions for all Builders that support . /// diff --git a/src/Cake.7zip/Builder/TestCommandBuilder.cs b/src/Cake.7zip/Builder/TestCommandBuilder.cs new file mode 100644 index 00000000..0b2b1934 --- /dev/null +++ b/src/Cake.7zip/Builder/TestCommandBuilder.cs @@ -0,0 +1,89 @@ +using Cake.SevenZip.Commands; +using Cake.SevenZip.Parsers; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder +{ + /// + /// Builder for . + /// + /// + /// + /// + /// + /// { + /// SevenZip(m => m + /// .InTestMode() + /// .WithArchive(File("path/to/file.zip")) + /// .WithCommandOutput(o => + /// { + /// Information("7Zip version is:" + o.Information); + /// foreach (var archiveTestResult in o.Archives) + /// { + /// var isOk = archiveTestResult.IsOk ? "OK" : "not OK"; + /// Information($" - {archiveTestResult.FileName} test is { isOk }"); + /// } + /// })); + /// ]]> + /// + /// + public sealed class TestCommandBuilder : + BaseOutputBuilder, + ISupportArgumentBuilder, + ISupportArgumentBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder, + ISupportSwitchBuilder + { + private readonly TestCommand command; + + /// + /// Initializes a new instance of the class. + /// + /// The command. + internal TestCommandBuilder(ref TestCommand command) + { + this.command = command; + } + + /// + IHaveArgumentArchive ISupportArgumentBuilder.Command => command; + + /// + IHaveArgumentFiles ISupportArgumentBuilder.Command => command; + + /// + ISupportSwitchIncludeArchiveFilenames ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchExcludeArchiveFilenames ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchDisableParsingOfArchiveName ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchIncludeFilenames ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchExcludeFilenames ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchPassword ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchNtfsAlternateStreams ISupportSwitchBuilder.Command => command; + + /// + ISupportSwitchRecurseSubdirectories ISupportSwitchBuilder.Command => command; + + /// + protected override OutputCommand OutputCommand => command; + } +} diff --git a/src/Cake.7zip/Builder/UpdateCommandBuilder.cs b/src/Cake.7zip/Builder/UpdateCommandBuilder.cs index 28ef616b..635c0c05 100644 --- a/src/Cake.7zip/Builder/UpdateCommandBuilder.cs +++ b/src/Cake.7zip/Builder/UpdateCommandBuilder.cs @@ -1,4 +1,7 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Commands; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Builder { /// /// Builder for . diff --git a/src/Cake.7zip/Cake.7zip.csproj b/src/Cake.7zip/Cake.7zip.csproj index 31268fac..41cf9b2b 100644 --- a/src/Cake.7zip/Cake.7zip.csproj +++ b/src/Cake.7zip/Cake.7zip.csproj @@ -2,9 +2,9 @@ netstandard2.0;net461 true - true - snupkg true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true @@ -30,11 +30,27 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -43,4 +59,4 @@ - + \ No newline at end of file diff --git a/src/Cake.7zip/Commands/AddCommand.cs b/src/Cake.7zip/Commands/AddCommand.cs index 635c90d8..9f2698f1 100644 --- a/src/Cake.7zip/Commands/AddCommand.cs +++ b/src/Cake.7zip/Commands/AddCommand.cs @@ -1,7 +1,9 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// Adds files to archive. /// (Command: a). diff --git a/src/Cake.7zip/Commands/BaseAddLikeSyntaxCommand.cs b/src/Cake.7zip/Commands/BaseAddLikeSyntaxCommand.cs index 7bc51710..87687be1 100644 --- a/src/Cake.7zip/Commands/BaseAddLikeSyntaxCommand.cs +++ b/src/Cake.7zip/Commands/BaseAddLikeSyntaxCommand.cs @@ -1,11 +1,12 @@ -namespace Cake.SevenZip -{ - using System; - using System.Collections.Generic; +using System; +using System.Collections.Generic; - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// BaseClass for add,update,delete. /// @@ -24,7 +25,7 @@ public abstract class BaseAddLikeSyntaxCommand : public DirectoryPathCollection DirectoryContents { get; set; } /// - public FilePath Archive { get; set; } + public FilePath Archive { private get; set; } /// /// Gets the name of the command. (i.e. "add", "update" or "extract".) @@ -83,12 +84,7 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) foreach (var sw in Switches) { - if (sw == null) - { - continue; - } - - sw.BuildArguments(ref builder); + sw?.BuildArguments(ref builder); } builder.AppendQuoted(Archive.FullPath); diff --git a/src/Cake.7zip/Commands/DeleteCommand.cs b/src/Cake.7zip/Commands/DeleteCommand.cs index 87bf5253..bad738ec 100644 --- a/src/Cake.7zip/Commands/DeleteCommand.cs +++ b/src/Cake.7zip/Commands/DeleteCommand.cs @@ -1,7 +1,9 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// Deletes files from the archive. /// (Command: d). diff --git a/src/Cake.7zip/Commands/ExtractCommand.cs b/src/Cake.7zip/Commands/ExtractCommand.cs index 74366bc8..beba48e4 100644 --- a/src/Cake.7zip/Commands/ExtractCommand.cs +++ b/src/Cake.7zip/Commands/ExtractCommand.cs @@ -1,10 +1,11 @@ -namespace Cake.SevenZip -{ - using System; +using System; - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// Extract files from archive - with or without full path /// (Commands: e and x). @@ -46,7 +47,7 @@ public ExtractCommand() } /// - public FilePath Archive { get; set; } + public FilePath Archive { private get; set; } /// /// Gets or sets a value indicating whether to use full paths. @@ -130,12 +131,7 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) FullyQualifiedFilePaths, }) { - if (sw == null) - { - continue; - } - - sw.BuildArguments(ref builder); + sw?.BuildArguments(ref builder); } } } diff --git a/src/Cake.7zip/Commands/ICommand.cs b/src/Cake.7zip/Commands/ICommand.cs index b7c7f236..b66e5d20 100644 --- a/src/Cake.7zip/Commands/ICommand.cs +++ b/src/Cake.7zip/Commands/ICommand.cs @@ -1,7 +1,7 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Commands +{ /// /// Interface for all commands. (E.g. ). /// diff --git a/src/Cake.7zip/Commands/IHaveArgument.cs b/src/Cake.7zip/Commands/IHaveArgument.cs index f140a2a4..439a2a91 100644 --- a/src/Cake.7zip/Commands/IHaveArgument.cs +++ b/src/Cake.7zip/Commands/IHaveArgument.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Commands { /// /// Base for all argument. diff --git a/src/Cake.7zip/Commands/IHaveArgumentArchive.cs b/src/Cake.7zip/Commands/IHaveArgumentArchive.cs index e9f1d7c1..145296c0 100644 --- a/src/Cake.7zip/Commands/IHaveArgumentArchive.cs +++ b/src/Cake.7zip/Commands/IHaveArgumentArchive.cs @@ -1,18 +1,18 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Commands +{ /// /// Interface for all commands supporting the Archive-Argument. /// public interface IHaveArgumentArchive : IHaveArgument { /// - /// Gets or sets the archive the command operates on. + /// Sets the archive the command operates on. /// /// /// The archive. /// - FilePath Archive { get; set; } + FilePath Archive { set; } } } diff --git a/src/Cake.7zip/Commands/IHaveArgumentDirectories.cs b/src/Cake.7zip/Commands/IHaveArgumentDirectories.cs index bcbf39d7..5877db7d 100644 --- a/src/Cake.7zip/Commands/IHaveArgumentDirectories.cs +++ b/src/Cake.7zip/Commands/IHaveArgumentDirectories.cs @@ -1,7 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// Interface for all commands supporting multiple directories as arguments. /// diff --git a/src/Cake.7zip/Commands/IHaveArgumentFiles.cs b/src/Cake.7zip/Commands/IHaveArgumentFiles.cs index f64da644..fda89654 100644 --- a/src/Cake.7zip/Commands/IHaveArgumentFiles.cs +++ b/src/Cake.7zip/Commands/IHaveArgumentFiles.cs @@ -1,7 +1,7 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Commands +{ /// /// Interface for all commands supporting multiple files as arguments. /// @@ -9,9 +9,9 @@ public interface IHaveArgumentFiles : IHaveArgument { /// /// Gets or sets the list of files this command operates on. - /// Theese are single files. (I.e. to add to, or to remove from the archive). + /// These are single files. (I.e. to add to, or to remove from the archive). /// - /// For Add and update, single files from the filesystems will always be + /// For add and update, single files from the file-system will always be /// placed directly into the archive without any directory-structure. /// /// Setting Files like this in add/update: diff --git a/src/Cake.7zip/Commands/InformationCommand.cs b/src/Cake.7zip/Commands/InformationCommand.cs index 31e7dc69..cf33757d 100644 --- a/src/Cake.7zip/Commands/InformationCommand.cs +++ b/src/Cake.7zip/Commands/InformationCommand.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Parsers; +namespace Cake.SevenZip.Commands +{ /// /// Show information about supported formats /// (Command: i). diff --git a/src/Cake.7zip/Commands/OutputCommand.cs b/src/Cake.7zip/Commands/OutputCommand.cs index 975de83e..2e0443bc 100644 --- a/src/Cake.7zip/Commands/OutputCommand.cs +++ b/src/Cake.7zip/Commands/OutputCommand.cs @@ -1,18 +1,20 @@ -namespace Cake.SevenZip -{ - using System; - using System.Collections.Generic; - using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; - using Cake.Core.IO; +using Cake.Core.IO; +using Cake.SevenZip.Parsers; +namespace Cake.SevenZip.Commands +{ /// /// base for all commands that have output. (E.g. ). /// - /// /// The type on the output. + /// The type on the output. public abstract class OutputCommand : ICommand, ICanParseOutput + where T : IOutput { /// /// Gets or sets the output-action, to be called when output is available. diff --git a/src/Cake.7zip/Commands/TestCommand.cs b/src/Cake.7zip/Commands/TestCommand.cs new file mode 100644 index 00000000..7573774c --- /dev/null +++ b/src/Cake.7zip/Commands/TestCommand.cs @@ -0,0 +1,105 @@ +using System; + +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Parsers; +using Cake.SevenZip.Switches; + +namespace Cake.SevenZip.Commands +{ + /// + /// Test one or more archives + /// (Command: t). + /// + public sealed class TestCommand : + OutputCommand, + IHaveArgumentArchive, + IHaveArgumentFiles, + ISupportSwitchIncludeArchiveFilenames, + ISupportSwitchExcludeArchiveFilenames, + ISupportSwitchDisableParsingOfArchiveName, + ISupportSwitchIncludeFilenames, + ISupportSwitchExcludeFilenames, + ISupportSwitchPassword, + ISupportSwitchNtfsAlternateStreams, + ISupportSwitchRecurseSubdirectories + { + private readonly TestOutputParser outputParser; + + /// + /// Initializes a new instance of the class. + /// + public TestCommand() + { + outputParser = new TestOutputParser(); + } + + /// + public FilePath Archive { private get; set; } + + /// + public SwitchIncludeArchiveFilenameCollection IncludeArchiveFilenames { get; set; } + + /// + public SwitchExcludeArchiveFilenameCollection ExcludeArchiveFilenames { get; set; } + + /// + public SwitchDisableParsingOfArchiveName DisableParsingOfArchiveName { get; set; } + + /// + public SwitchIncludeFilenameCollection IncludeFilenames { get; set; } + + /// + public SwitchExcludeFilenameCollection ExcludeFilenames { get; set; } + + /// + public SwitchPassword Password { get; set; } + + /// + public SwitchNtfsAlternateStreams NtfsAlternateStreams { get; set; } + + /// + public SwitchRecurseSubdirectories RecurseSubdirectories { get; set; } + + /// + public FilePathCollection Files { get; set; } + + /// + internal override IOutputParser OutputParser => outputParser; + + /// + public override void BuildArguments(ref ProcessArgumentBuilder builder) + { + if (Archive == null) + { + throw new ArgumentException("Archive is required for extract."); + } + + builder.Append("t"); + builder.AppendQuoted(Archive.FullPath); + + if (Files != null) + { + foreach (var file in Files) + { + builder.AppendQuoted(file.FullPath); + } + } + + foreach (var sw in new ISwitch[] + { + IncludeArchiveFilenames, + ExcludeArchiveFilenames, + DisableParsingOfArchiveName, + IncludeFilenames, + ExcludeFilenames, + Password, + NtfsAlternateStreams, + RecurseSubdirectories, + }) + { + sw?.BuildArguments(ref builder); + } + } + } +} diff --git a/src/Cake.7zip/Commands/UpdateCommand.cs b/src/Cake.7zip/Commands/UpdateCommand.cs index e9120425..c3131fc8 100644 --- a/src/Cake.7zip/Commands/UpdateCommand.cs +++ b/src/Cake.7zip/Commands/UpdateCommand.cs @@ -1,11 +1,13 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; + +using Cake.SevenZip.Switches; +namespace Cake.SevenZip.Commands +{ /// /// Update older files in the archive and add files that are not already in the archive. /// (Command: u) - /// Note: the updating of solid .7z archives can be slow, since it can require some recompression. + /// Note: the updating of solid .7z archives can be slow, since it can require some re-compression. /// public sealed class UpdateCommand : BaseAddLikeSyntaxCommand, ICommand, diff --git a/src/Cake.7zip/GlobalSuppressions.cs b/src/Cake.7zip/GlobalSuppressions.cs deleted file mode 100644 index e6637ea1..00000000 --- a/src/Cake.7zip/GlobalSuppressions.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Cake.7zip.Tests")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] -[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Not required")] -[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "I don't like it", Scope = "namespaceanddescendants", Target = "Cake.SevenZip")] diff --git a/src/Cake.7zip/Parsers/IArchiveTestOutput.cs b/src/Cake.7zip/Parsers/IArchiveTestOutput.cs new file mode 100644 index 00000000..f590dee8 --- /dev/null +++ b/src/Cake.7zip/Parsers/IArchiveTestOutput.cs @@ -0,0 +1,35 @@ +using Cake.SevenZip.Commands; + +namespace Cake.SevenZip.Parsers +{ + /// + /// The parsed output of individual archives the . + /// + /// + public interface IArchiveTestOutput + { + /// + /// Gets the filename of the archive. + /// + /// + /// The filename of the archive. + /// + string FileName { get; } + + /// + /// Gets a value indicating whether the test for this archive was OK. + /// + /// + /// true if this archive is OK; otherwise, false. + /// + bool IsOk { get; } + + /// + /// Gets the output. + /// + /// + /// The output. + /// + string Output { get; } + } +} diff --git a/src/Cake.7zip/Parsers/ICanParseOutput.cs b/src/Cake.7zip/Parsers/ICanParseOutput.cs index 5c084321..6c88f65f 100644 --- a/src/Cake.7zip/Parsers/ICanParseOutput.cs +++ b/src/Cake.7zip/Parsers/ICanParseOutput.cs @@ -1,7 +1,7 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; +namespace Cake.SevenZip.Parsers +{ /// /// Internal Interface for Commands that can parse the output of the run. /// diff --git a/src/Cake.7zip/Parsers/IInformationOutput.cs b/src/Cake.7zip/Parsers/IInformationOutput.cs index 68629ffa..d900812d 100644 --- a/src/Cake.7zip/Parsers/IInformationOutput.cs +++ b/src/Cake.7zip/Parsers/IInformationOutput.cs @@ -1,20 +1,14 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; + +using Cake.SevenZip.Commands; +namespace Cake.SevenZip.Parsers +{ /// /// The parsed Output of the . /// - public interface IInformationOutput + public interface IInformationOutput : IOutput { - /// - /// Gets the information (version etc.) from 7z. - /// - /// - /// The information. - /// - string Information { get; } - /// /// Gets the codecs. /// diff --git a/src/Cake.7zip/Parsers/IOutput.cs b/src/Cake.7zip/Parsers/IOutput.cs new file mode 100644 index 00000000..bd7623bf --- /dev/null +++ b/src/Cake.7zip/Parsers/IOutput.cs @@ -0,0 +1,16 @@ +namespace Cake.SevenZip.Parsers +{ + /// + /// General output. Common to all s. + /// + public interface IOutput + { + /// + /// Gets the information (version etc.) from 7z. + /// + /// + /// The information. + /// + string Information { get; } + } +} diff --git a/src/Cake.7zip/Parsers/IOutputParser.cs b/src/Cake.7zip/Parsers/IOutputParser.cs index da5f5a69..47279541 100644 --- a/src/Cake.7zip/Parsers/IOutputParser.cs +++ b/src/Cake.7zip/Parsers/IOutputParser.cs @@ -1,10 +1,11 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Parsers { /// /// Interface for all commands supporting a parsed output. /// - /// The output obkect. - internal interface IOutputParser + /// The output object. + internal interface IOutputParser + where T : IOutput { /// /// Parses the stream. diff --git a/src/Cake.7zip/Parsers/ITestOutput.cs b/src/Cake.7zip/Parsers/ITestOutput.cs new file mode 100644 index 00000000..db1f5c85 --- /dev/null +++ b/src/Cake.7zip/Parsers/ITestOutput.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using Cake.SevenZip.Commands; + +namespace Cake.SevenZip.Parsers +{ + /// + /// The parsed output of the . + /// + public interface ITestOutput : IOutput + { + /// + /// Gets the output for all individual archives. + /// + /// + /// The individual outputs. + /// + IEnumerable Archives { get; } + } +} diff --git a/src/Cake.7zip/Parsers/InformationOutputParser.cs b/src/Cake.7zip/Parsers/InformationOutputParser.cs index 58b7ea65..02f8220e 100644 --- a/src/Cake.7zip/Parsers/InformationOutputParser.cs +++ b/src/Cake.7zip/Parsers/InformationOutputParser.cs @@ -1,7 +1,9 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; + +using Cake.SevenZip.Commands; +namespace Cake.SevenZip.Parsers +{ /// /// Parses outputs of the . /// @@ -24,7 +26,7 @@ public IInformationOutput Parse(string[] rawOutput) }; var firstLine = true; - List current = null; + var current = new List(); foreach (var line in rawOutput) { if (string.IsNullOrWhiteSpace(line)) @@ -69,7 +71,7 @@ public IInformationOutput Parse(string[] rawOutput) /// /// Implements . /// - protected class InformationOutput : IInformationOutput + private class InformationOutput : IInformationOutput { /// public string Information { get; internal set; } diff --git a/src/Cake.7zip/Parsers/TestOutputParser.cs b/src/Cake.7zip/Parsers/TestOutputParser.cs new file mode 100644 index 00000000..a475884a --- /dev/null +++ b/src/Cake.7zip/Parsers/TestOutputParser.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +using Cake.SevenZip.Commands; + +namespace Cake.SevenZip.Parsers +{ + /// + /// Parses outputs of the . + /// + /// + internal class TestOutputParser : IOutputParser + { + /// + public ITestOutput Parse(string[] rawOutput) + { + string information = null; + var archives = new List(); + var currentArchive = new ArchiveOutput(); + var currentOutput = new StringBuilder(); + var summaryLineMatcher = new Regex("(Archives|Files|Folders): [0-9]+$", RegexOptions.Compiled); + foreach (var line in rawOutput) + { + if (string.IsNullOrWhiteSpace(line) || line.Trim().Equals("--", StringComparison.InvariantCulture)) + { + continue; + } + + if (information == null) + { + information = line; + continue; + } + + if (line.StartsWith("Testing archive:", StringComparison.InvariantCulture)) + { + // one archive is finished: Set output and start the next + currentArchive.Output = currentOutput.ToString(); + currentOutput.Clear(); + + currentArchive = new ArchiveOutput + { + FileName = line.Substring(16).Trim(), + IsOk = true, + }; + archives.Add(currentArchive); + continue; + } + + if (summaryLineMatcher.IsMatch(line)) + { + // last archive is finished: Set output and break early (i.e. ignore the summary) + currentArchive.Output = currentOutput.ToString(); + currentOutput.Clear(); + break; + } + + currentOutput.AppendLine(line.Trim()); + if (line.StartsWith("ERROR:", StringComparison.InvariantCulture)) + { + currentArchive.IsOk = false; + } + } + + return new TestOutput + { + Information = information, + Archives = archives, + }; + } + + private class TestOutput : ITestOutput + { + public IEnumerable Archives { get; set; } + + public string Information { get; set; } + } + + private class ArchiveOutput : IArchiveTestOutput + { + public string FileName { get; set; } + + public bool IsOk { get; set; } + + public string Output { get; set; } + } + } +} diff --git a/src/Cake.7zip/SevenZipAliases.cs b/src/Cake.7zip/SevenZipAliases.cs index 1eb760f5..72294593 100644 --- a/src/Cake.7zip/SevenZipAliases.cs +++ b/src/Cake.7zip/SevenZipAliases.cs @@ -1,14 +1,16 @@ -namespace Cake.SevenZip -{ - using System; +using System; - using Cake.Core; - using Cake.Core.Annotations; +using Cake.Core; +using Cake.Core.Annotations; +using Cake.SevenZip.Builder; +using Cake.SevenZip.Commands; +namespace Cake.SevenZip +{ /// /// Functions to call 7-Zip. /// - /// In order to use this addin, 7z.exe or 7za.exe has to be available. + /// In order to use this add-in, 7z.exe or 7za.exe has to be available. /// One option is using /// 7-Zip.CommandLine from nuget. /// The other option is to have 7z installed on your system (I.e. There is a registry-key HKLM/Software/7-Zip/Path @@ -87,7 +89,7 @@ public static void SevenZip(this ICakeContext context, Action ac /// for fluent configuration of the Command. /// /// - /// Works exactly like + /// Works exactly like /// However, the settings are supplied to set e.g. the ToolPath or something else. /// /// diff --git a/src/Cake.7zip/SevenZipRunner.cs b/src/Cake.7zip/SevenZipRunner.cs index 825ced96..05e1ae7a 100644 --- a/src/Cake.7zip/SevenZipRunner.cs +++ b/src/Cake.7zip/SevenZipRunner.cs @@ -1,14 +1,15 @@ -namespace Cake.SevenZip -{ - using System; - using System.Collections.Generic; - using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; - using Cake.Core; - using Cake.Core.Diagnostics; - using Cake.Core.IO; - using Cake.Core.Tooling; +using Cake.Core; +using Cake.Core.Diagnostics; +using Cake.Core.IO; +using Cake.Core.Tooling; +using Cake.SevenZip.Parsers; +namespace Cake.SevenZip +{ /// /// The Tool-Runner for 7zip. /// @@ -97,31 +98,35 @@ protected override IEnumerable GetAlternativeToolPaths(SevenZipSetting log.Debug("Trying to detect 7zip from Registry"); try { - var software = registry.LocalMachine.OpenKey("Software"); - var sevenZip = software.OpenKey("7-Zip"); - var path32 = sevenZip.GetValue("Path")?.ToString() ?? string.Empty; - log.Debug("7zip path in registry:" + path32); - var path64 = sevenZip.GetValue("Path64")?.ToString() ?? string.Empty; - log.Debug("7zip 64bit-path in registry:" + path64); - var dirs = new List(new[] { new DirectoryPath(path32) }); - if (cakeEnvironment.Platform.Is64Bit - && path64 != path32) + using (var software = registry.LocalMachine.OpenKey("Software")) + using (var sevenZip = software.OpenKey("7-Zip")) { - dirs.Add(new DirectoryPath(path64)); + var path32 = sevenZip.GetValue("Path")?.ToString() ?? string.Empty; + log.Debug("7zip path in registry:" + path32); + var path64 = sevenZip.GetValue("Path64")?.ToString() ?? string.Empty; + log.Debug("7zip 64bit-path in registry:" + path64); + var dirs = new List(new[] { new DirectoryPath(path32) }); + if (cakeEnvironment.Platform.Is64Bit + && path64 != path32) + { + dirs.Add(new DirectoryPath(path64)); + } + + var names = GetToolExecutableNames().ToList(); + + names + .SelectMany(n => dirs + .Select(d => d.CombineWithFilePath(n))) + .Where(p => fileSystem.Exist(p)) + .ToList().ForEach(p => paths.Add(p.FullPath)); } - - var names = GetToolExecutableNames().ToList(); - - names - .SelectMany(n => dirs - .Select(d => d.CombineWithFilePath(n))) - .Where(p => fileSystem.Exist(p)) - .ToList().ForEach(p => paths.Add(p.FullPath)); } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) +#pragma warning restore CA1031 // Do not catch general exception types { log.Debug($"{e.GetType()}: {e.Message}"); - log.Debug($"7zip not found in registry."); + log.Debug("7zip not found in registry."); } } diff --git a/src/Cake.7zip/SevenZipSettings.cs b/src/Cake.7zip/SevenZipSettings.cs index b1654b61..9a818675 100644 --- a/src/Cake.7zip/SevenZipSettings.cs +++ b/src/Cake.7zip/SevenZipSettings.cs @@ -1,7 +1,8 @@ +using Cake.Core.Tooling; +using Cake.SevenZip.Commands; + namespace Cake.SevenZip { - using Cake.Core.Tooling; - /// /// Settings for running 7zip. /// diff --git a/src/Cake.7zip/Switches/BaseBoolSwitch.cs b/src/Cake.7zip/Switches/BaseBoolSwitch.cs index ba2d8b70..787437d1 100644 --- a/src/Cake.7zip/Switches/BaseBoolSwitch.cs +++ b/src/Cake.7zip/Switches/BaseBoolSwitch.cs @@ -1,8 +1,8 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +namespace Cake.SevenZip.Switches +{ /// /// BaseClass for simple boolean switches. /// diff --git a/src/Cake.7zip/Switches/BaseSwitchCollection.cs b/src/Cake.7zip/Switches/BaseSwitchCollection.cs index 7b4567be..a9047464 100644 --- a/src/Cake.7zip/Switches/BaseSwitchCollection.cs +++ b/src/Cake.7zip/Switches/BaseSwitchCollection.cs @@ -1,11 +1,11 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; +using System.Collections.Generic; - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Switches +{ /// - /// Base for for switches that can be given multiple times. + /// Base for switches that can be given multiple times. /// An example is (-x!*.pdf -x!*.xml) which uses /// (which implements this BaseCollection) to set /// multiple . @@ -13,7 +13,7 @@ namespace Cake.SevenZip /// /// The Switch-Type. public abstract class BaseSwitchCollection : ISwitch - where T : ISwitch + where T : ISwitch { /// /// Initializes a new instance of the class. @@ -29,7 +29,7 @@ protected BaseSwitchCollection() /// /// The switches. /// - protected List Switches { get; private set; } + protected List Switches { get; } /// /// Adds the specified switch. diff --git a/src/Cake.7zip/Switches/ISupportSwitch.cs b/src/Cake.7zip/Switches/ISupportSwitch.cs index 5ba9dee5..0900b5dc 100644 --- a/src/Cake.7zip/Switches/ISupportSwitch.cs +++ b/src/Cake.7zip/Switches/ISupportSwitch.cs @@ -1,10 +1,10 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// Interfaces for all switches. - /// Commands "support" swithches by implementing an ISupportSwitch + /// Commands "support" switches by implementing an ISupportSwitch /// (e.g. is implemented in all commands - /// that support setting a passeword (-p). + /// that support setting a password (-p). /// public interface ISupportSwitch { diff --git a/src/Cake.7zip/Switches/ISupportSwitchArchiveType.cs b/src/Cake.7zip/Switches/ISupportSwitchArchiveType.cs index 72d56f06..472af566 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchArchiveType.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchArchiveType.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchCompressFilesOpenForWriting.cs b/src/Cake.7zip/Switches/ISupportSwitchCompressFilesOpenForWriting.cs index b3839e49..4f991318 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchCompressFilesOpenForWriting.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchCompressFilesOpenForWriting.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchCompressionMethod.cs b/src/Cake.7zip/Switches/ISupportSwitchCompressionMethod.cs index d6e5fe0d..fdfe65cb 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchCompressionMethod.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchCompressionMethod.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchDeleteAfterCompression.cs b/src/Cake.7zip/Switches/ISupportSwitchDeleteAfterCompression.cs index 3791547a..86de34eb 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchDeleteAfterCompression.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchDeleteAfterCompression.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchDisableParsingOfArchiveName.cs b/src/Cake.7zip/Switches/ISupportSwitchDisableParsingOfArchiveName.cs index 45d8658c..dbb93e0a 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchDisableParsingOfArchiveName.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchDisableParsingOfArchiveName.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchExcludeArchiveFilenames.cs b/src/Cake.7zip/Switches/ISupportSwitchExcludeArchiveFilenames.cs index 3d0f0945..448d2c02 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchExcludeArchiveFilenames.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchExcludeArchiveFilenames.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchExcludeFilenames.cs b/src/Cake.7zip/Switches/ISupportSwitchExcludeFilenames.cs index 89e33cce..bd99c54e 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchExcludeFilenames.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchExcludeFilenames.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchFullyQualifiedFilePaths.cs b/src/Cake.7zip/Switches/ISupportSwitchFullyQualifiedFilePaths.cs index 266747cf..4bbb5c0a 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchFullyQualifiedFilePaths.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchFullyQualifiedFilePaths.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchIncludeArchiveFilenames.cs b/src/Cake.7zip/Switches/ISupportSwitchIncludeArchiveFilenames.cs index d55b52fb..3c25359d 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchIncludeArchiveFilenames.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchIncludeArchiveFilenames.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchIncludeFilenames.cs b/src/Cake.7zip/Switches/ISupportSwitchIncludeFilenames.cs index 83c7f2a0..0ba7c8cc 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchIncludeFilenames.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchIncludeFilenames.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchNtSecurityInformation.cs b/src/Cake.7zip/Switches/ISupportSwitchNtSecurityInformation.cs index f9bf7e48..eda13531 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchNtSecurityInformation.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchNtSecurityInformation.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchNtfsAlternateStreams.cs b/src/Cake.7zip/Switches/ISupportSwitchNtfsAlternateStreams.cs index e71fb0a9..cabb8649 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchNtfsAlternateStreams.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchNtfsAlternateStreams.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchOutputDirectory.cs b/src/Cake.7zip/Switches/ISupportSwitchOutputDirectory.cs index 931ef76c..067beeeb 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchOutputDirectory.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchOutputDirectory.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchOverwriteMode.cs b/src/Cake.7zip/Switches/ISupportSwitchOverwriteMode.cs index 2da09b0f..a241624f 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchOverwriteMode.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchOverwriteMode.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchPassword.cs b/src/Cake.7zip/Switches/ISupportSwitchPassword.cs index 2b92c1e7..c707aafb 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchPassword.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchPassword.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchRecurseSubdirectories.cs b/src/Cake.7zip/Switches/ISupportSwitchRecurseSubdirectories.cs index 13fa192f..d43ee0f9 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchRecurseSubdirectories.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchRecurseSubdirectories.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchSelfExtractingArchive.cs b/src/Cake.7zip/Switches/ISupportSwitchSelfExtractingArchive.cs index 5b17435b..17be60a1 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchSelfExtractingArchive.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchSelfExtractingArchive.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchTimestampFromMostRecentFile.cs b/src/Cake.7zip/Switches/ISupportSwitchTimestampFromMostRecentFile.cs index 4d78ab7b..75be1e52 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchTimestampFromMostRecentFile.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchTimestampFromMostRecentFile.cs @@ -1,8 +1,10 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// - /// Command supports switch -stl (Set archive timestamp from the most recently modified file). + /// Command supports switch -stl (Set archive time-stamp from the most recently modified file). /// /// /// The Switch is . diff --git a/src/Cake.7zip/Switches/ISupportSwitchUpdateOptions.cs b/src/Cake.7zip/Switches/ISupportSwitchUpdateOptions.cs index 5c77675b..7adaf86b 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchUpdateOptions.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchUpdateOptions.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchVolume.cs b/src/Cake.7zip/Switches/ISupportSwitchVolume.cs index f49bd3bc..6e061c94 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchVolume.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchVolume.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/ISupportSwitchWorkingDirectory.cs b/src/Cake.7zip/Switches/ISupportSwitchWorkingDirectory.cs index 9e6461e0..644efdf8 100644 --- a/src/Cake.7zip/Switches/ISupportSwitchWorkingDirectory.cs +++ b/src/Cake.7zip/Switches/ISupportSwitchWorkingDirectory.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// . /// diff --git a/src/Cake.7zip/Switches/ISwitch.cs b/src/Cake.7zip/Switches/ISwitch.cs index 99dc5910..188ae24b 100644 --- a/src/Cake.7zip/Switches/ISwitch.cs +++ b/src/Cake.7zip/Switches/ISwitch.cs @@ -1,7 +1,7 @@ -namespace Cake.SevenZip -{ - using Cake.Core.IO; +using Cake.Core.IO; +namespace Cake.SevenZip.Switches +{ /// /// Base for all Switches. /// diff --git a/src/Cake.7zip/Switches/OverwriteMode.cs b/src/Cake.7zip/Switches/OverwriteMode.cs index 461bf4ff..e67aee68 100644 --- a/src/Cake.7zip/Switches/OverwriteMode.cs +++ b/src/Cake.7zip/Switches/OverwriteMode.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// diff --git a/src/Cake.7zip/Switches/RecurseType.cs b/src/Cake.7zip/Switches/RecurseType.cs index 4460c014..7ecaab2b 100644 --- a/src/Cake.7zip/Switches/RecurseType.cs +++ b/src/Cake.7zip/Switches/RecurseType.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// @@ -56,4 +56,4 @@ public override string ToString() return type; } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchArchiveType.cs b/src/Cake.7zip/Switches/SwitchArchiveType.cs index 521884d4..2fe1fed8 100644 --- a/src/Cake.7zip/Switches/SwitchArchiveType.cs +++ b/src/Cake.7zip/Switches/SwitchArchiveType.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -t (set Type of archive) switch. @@ -26,7 +27,7 @@ public class SwitchArchiveType : ISwitch /// Initializes a new instance of the class. /// /// The type. - internal SwitchArchiveType(string type) + private SwitchArchiveType(string type) { this.type = type; } @@ -36,42 +37,42 @@ internal SwitchArchiveType(string type) /// /// Gets the type: 7-Zip. /// - public static SwitchArchiveType SevenZip => new SwitchArchiveType("7z"); + public static SwitchArchiveType SevenZip { get; } = new SwitchArchiveType("7z"); /// /// Gets the type: XZ. /// - public static SwitchArchiveType Xz => new SwitchArchiveType("xz"); + public static SwitchArchiveType Xz { get; } = new SwitchArchiveType("xz"); /// /// Gets the type: lzma. /// - public static SwitchArchiveType Lzma => new SwitchArchiveType("lzma"); + public static SwitchArchiveType Lzma { get; } = new SwitchArchiveType("lzma"); /// /// Gets the type: CAB. /// - public static SwitchArchiveType Cab => new SwitchArchiveType("cab"); + public static SwitchArchiveType Cab { get; } = new SwitchArchiveType("cab"); /// /// Gets the type: Zip. /// - public static SwitchArchiveType Zip => new SwitchArchiveType("zip"); + public static SwitchArchiveType Zip { get; } = new SwitchArchiveType("zip"); /// /// Gets the type: GZip. /// - public static SwitchArchiveType Gzip => new SwitchArchiveType("gzip"); + public static SwitchArchiveType Gzip { get; } = new SwitchArchiveType("gzip"); /// /// Gets the type: tar. /// - public static SwitchArchiveType Tar => new SwitchArchiveType("tar"); + public static SwitchArchiveType Tar { get; } = new SwitchArchiveType("tar"); /// /// Gets the type: BZip2. /// - public static SwitchArchiveType Bzip2 => new SwitchArchiveType("bzip2"); + public static SwitchArchiveType Bzip2 { get; } = new SwitchArchiveType("bzip2"); /// public void BuildArguments(ref ProcessArgumentBuilder builder) @@ -79,4 +80,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-t{type}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchCompressFilesOpenForWriting.cs b/src/Cake.7zip/Switches/SwitchCompressFilesOpenForWriting.cs index b46590d1..d24789f9 100644 --- a/src/Cake.7zip/Switches/SwitchCompressFilesOpenForWriting.cs +++ b/src/Cake.7zip/Switches/SwitchCompressFilesOpenForWriting.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// @@ -27,4 +29,4 @@ public SwitchCompressFilesOpenForWriting(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchCompressionMethod.cs b/src/Cake.7zip/Switches/SwitchCompressionMethod.cs index 8410d029..8ad3985b 100644 --- a/src/Cake.7zip/Switches/SwitchCompressionMethod.cs +++ b/src/Cake.7zip/Switches/SwitchCompressionMethod.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -m (Set compression Method) switch. @@ -21,23 +22,23 @@ namespace Cake.SevenZip public class SwitchCompressionMethod : ISwitch { /// - /// Gets or sets the level. + /// Sets the level. /// parameter: x. /// /// /// The level. /// - public int? Level { get; set; } + public int? Level { private get; set; } /// - /// Gets or sets the method. + /// Sets the method. /// parameter: m. /// /// /// The method. /// - // TODO: Enum or static Props? - public string Method { get; set; } + // TODO: Better use Enum or static Props instead of the free string? + public string Method { private get; set; } /// public void BuildArguments(ref ProcessArgumentBuilder builder) diff --git a/src/Cake.7zip/Switches/SwitchDeleteAfterCompression.cs b/src/Cake.7zip/Switches/SwitchDeleteAfterCompression.cs index 12ff6d17..afc89326 100644 --- a/src/Cake.7zip/Switches/SwitchDeleteAfterCompression.cs +++ b/src/Cake.7zip/Switches/SwitchDeleteAfterCompression.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// @@ -28,4 +30,4 @@ public SwitchDeleteAfterCompression(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchDisableParsingOfArchiveName.cs b/src/Cake.7zip/Switches/SwitchDisableParsingOfArchiveName.cs index 37434239..9867dc4a 100644 --- a/src/Cake.7zip/Switches/SwitchDisableParsingOfArchiveName.cs +++ b/src/Cake.7zip/Switches/SwitchDisableParsingOfArchiveName.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// @@ -29,4 +31,4 @@ public SwitchDisableParsingOfArchiveName(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchExcludeArchiveFilename.cs b/src/Cake.7zip/Switches/SwitchExcludeArchiveFilename.cs index 8533fe0e..34d8c5f5 100644 --- a/src/Cake.7zip/Switches/SwitchExcludeArchiveFilename.cs +++ b/src/Cake.7zip/Switches/SwitchExcludeArchiveFilename.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -ax (Exclude archive filenames) switch. @@ -30,21 +31,12 @@ public class SwitchExcludeArchiveFilename : ISwitch /// /// The wildcard. /// Type of the recurse. - public SwitchExcludeArchiveFilename(string wildcard, RecurseType recurseType) + public SwitchExcludeArchiveFilename(string wildcard, RecurseType recurseType = null) { this.wildcard = wildcard; this.recurseType = recurseType; } - /// - /// Initializes a new instance of the class. - /// - /// The wildcard. - public SwitchExcludeArchiveFilename(string wildcard) - : this(wildcard, null) - { - } - /// public void BuildArguments(ref ProcessArgumentBuilder builder) { @@ -52,4 +44,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-ax{recurse}!{wildcard}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchExcludeArchiveFilenameCollection.cs b/src/Cake.7zip/Switches/SwitchExcludeArchiveFilenameCollection.cs index 32434a22..f330becb 100644 --- a/src/Cake.7zip/Switches/SwitchExcludeArchiveFilenameCollection.cs +++ b/src/Cake.7zip/Switches/SwitchExcludeArchiveFilenameCollection.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// A Collection of . @@ -14,7 +14,6 @@ public class SwitchExcludeArchiveFilenameCollection : BaseSwitchCollection /// /// -x (Exclude filenames) switch. /// /// - /// Specifies which filenames or wildcarded names must be excluded from the operation. + /// Specifies which filenames or wildcard-names must be excluded from the operation. /// Multiple exclude switches are supported. /// /// @@ -30,21 +31,12 @@ public class SwitchExcludeFilename : ISwitch /// /// The wildcard. /// Type of the recurse. - public SwitchExcludeFilename(string wildcard, RecurseType recurseType) + public SwitchExcludeFilename(string wildcard, RecurseType recurseType = null) { this.wildcard = wildcard; this.recurseType = recurseType; } - /// - /// Initializes a new instance of the class. - /// - /// The wildcard. - public SwitchExcludeFilename(string wildcard) - : this(wildcard, null) - { - } - /// public void BuildArguments(ref ProcessArgumentBuilder builder) { @@ -52,4 +44,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-x{recurse}!{wildcard}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchExcludeFilenameCollection.cs b/src/Cake.7zip/Switches/SwitchExcludeFilenameCollection.cs index daf27f6e..c912f9c6 100644 --- a/src/Cake.7zip/Switches/SwitchExcludeFilenameCollection.cs +++ b/src/Cake.7zip/Switches/SwitchExcludeFilenameCollection.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// A Collection of . @@ -12,7 +12,6 @@ public class SwitchExcludeFilenameCollection : BaseSwitchCollectionThe initial. /// The additional. public SwitchExcludeFilenameCollection(SwitchExcludeFilename initial, params SwitchExcludeFilename[] additional) - : base() { Switches.Add(initial); Switches.AddRange(additional); diff --git a/src/Cake.7zip/Switches/SwitchFullyQualifiedFilePaths.cs b/src/Cake.7zip/Switches/SwitchFullyQualifiedFilePaths.cs index b2ff778e..1f45c7a5 100644 --- a/src/Cake.7zip/Switches/SwitchFullyQualifiedFilePaths.cs +++ b/src/Cake.7zip/Switches/SwitchFullyQualifiedFilePaths.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// -spf (Use fully qualified file paths) switch. /// (Also, -spf2 for full paths without drive letters.) @@ -32,12 +33,12 @@ public SwitchFullyQualifiedFilePaths() } /// - /// Gets or sets a value indicating whether to include drive letter. + /// Sets a value indicating whether to include drive letter. /// /// /// true to include drive letter (switch -spf); otherwise, false (switch -spf2). /// - public bool IncludeDriveLetter { get; set; } + public bool IncludeDriveLetter { private get; set; } /// public void BuildArguments(ref ProcessArgumentBuilder builder) diff --git a/src/Cake.7zip/Switches/SwitchIncludeArchiveFilename.cs b/src/Cake.7zip/Switches/SwitchIncludeArchiveFilename.cs index 457655b7..95ce21d0 100644 --- a/src/Cake.7zip/Switches/SwitchIncludeArchiveFilename.cs +++ b/src/Cake.7zip/Switches/SwitchIncludeArchiveFilename.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -ai (Include archive filenames) switch. @@ -30,21 +31,12 @@ public class SwitchIncludeArchiveFilename : ISwitch /// /// The wildcard. /// Type of the recurse. - public SwitchIncludeArchiveFilename(string wildcard, RecurseType recurseType) + public SwitchIncludeArchiveFilename(string wildcard, RecurseType recurseType = null) { this.wildcard = wildcard; this.recurseType = recurseType; } - /// - /// Initializes a new instance of the class. - /// - /// The wildcard. - public SwitchIncludeArchiveFilename(string wildcard) - : this(wildcard, null) - { - } - /// public void BuildArguments(ref ProcessArgumentBuilder builder) { @@ -52,4 +44,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-ai{recurse}!{wildcard}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchIncludeArchiveFilenameCollection.cs b/src/Cake.7zip/Switches/SwitchIncludeArchiveFilenameCollection.cs index d1121590..1306b4ec 100644 --- a/src/Cake.7zip/Switches/SwitchIncludeArchiveFilenameCollection.cs +++ b/src/Cake.7zip/Switches/SwitchIncludeArchiveFilenameCollection.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// A Collection of . @@ -14,7 +14,6 @@ public class SwitchIncludeArchiveFilenameCollection : BaseSwitchCollection /// /// -i (Include filenames) switch. @@ -30,21 +31,12 @@ public class SwitchIncludeFilename : ISwitch /// /// The wildcard. /// Type of the recurse. - public SwitchIncludeFilename(string wildcard, RecurseType recurseType) + public SwitchIncludeFilename(string wildcard, RecurseType recurseType = null) { this.wildcard = wildcard; this.recurseType = recurseType; } - /// - /// Initializes a new instance of the class. - /// - /// The wildcard. - public SwitchIncludeFilename(string wildcard) - : this(wildcard, null) - { - } - /// public void BuildArguments(ref ProcessArgumentBuilder builder) { @@ -52,4 +44,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-i{recurse}!{wildcard}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchIncludeFilenameCollection.cs b/src/Cake.7zip/Switches/SwitchIncludeFilenameCollection.cs index df44acbb..7a142336 100644 --- a/src/Cake.7zip/Switches/SwitchIncludeFilenameCollection.cs +++ b/src/Cake.7zip/Switches/SwitchIncludeFilenameCollection.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// A Collection of . @@ -12,7 +12,6 @@ public class SwitchIncludeFilenameCollection : BaseSwitchCollectionThe initial. /// The additional. public SwitchIncludeFilenameCollection(SwitchIncludeFilename initial, params SwitchIncludeFilename[] additional) - : base() { Switches.Add(initial); Switches.AddRange(additional); diff --git a/src/Cake.7zip/Switches/SwitchNtSecurityInformation.cs b/src/Cake.7zip/Switches/SwitchNtSecurityInformation.cs index 4684ccec..950f8a5b 100644 --- a/src/Cake.7zip/Switches/SwitchNtSecurityInformation.cs +++ b/src/Cake.7zip/Switches/SwitchNtSecurityInformation.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// @@ -28,4 +30,4 @@ public SwitchNtSecurityInformation(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchNtfsAlternateStreams.cs b/src/Cake.7zip/Switches/SwitchNtfsAlternateStreams.cs index 17956c5e..a958b69b 100644 --- a/src/Cake.7zip/Switches/SwitchNtfsAlternateStreams.cs +++ b/src/Cake.7zip/Switches/SwitchNtfsAlternateStreams.cs @@ -1,4 +1,6 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// @@ -28,4 +30,4 @@ public SwitchNtfsAlternateStreams(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchOutputDirectory.cs b/src/Cake.7zip/Switches/SwitchOutputDirectory.cs index 9139aef5..8043bac9 100644 --- a/src/Cake.7zip/Switches/SwitchOutputDirectory.cs +++ b/src/Cake.7zip/Switches/SwitchOutputDirectory.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -o (set Output directory) switch. @@ -38,4 +39,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.AppendSwitchQuoted("-o", string.Empty, directory.FullPath); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchOverwriteMode.cs b/src/Cake.7zip/Switches/SwitchOverwriteMode.cs index 224b9d67..275067d2 100644 --- a/src/Cake.7zip/Switches/SwitchOverwriteMode.cs +++ b/src/Cake.7zip/Switches/SwitchOverwriteMode.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -ao (Overwrite mode) switch. diff --git a/src/Cake.7zip/Switches/SwitchPassword.cs b/src/Cake.7zip/Switches/SwitchPassword.cs index 3357fbb3..61f4bcbc 100644 --- a/src/Cake.7zip/Switches/SwitchPassword.cs +++ b/src/Cake.7zip/Switches/SwitchPassword.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -p (set Password) switch. @@ -37,4 +38,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.AppendSwitchQuotedSecret("-p", string.Empty, password); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchRecurseSubdirectories.cs b/src/Cake.7zip/Switches/SwitchRecurseSubdirectories.cs index 75a67602..09e87d15 100644 --- a/src/Cake.7zip/Switches/SwitchRecurseSubdirectories.cs +++ b/src/Cake.7zip/Switches/SwitchRecurseSubdirectories.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -r (Recurse subdirectories) switch. @@ -37,4 +38,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append($"-r{recurse}"); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchSelfExtractingArchive.cs b/src/Cake.7zip/Switches/SwitchSelfExtractingArchive.cs index 9e4f8d7e..8b4a1ba6 100644 --- a/src/Cake.7zip/Switches/SwitchSelfExtractingArchive.cs +++ b/src/Cake.7zip/Switches/SwitchSelfExtractingArchive.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -sfx (Create SFX archive) switch. @@ -23,14 +24,14 @@ namespace Cake.SevenZip public class SwitchSelfExtractingArchive : ISwitch { /// - /// Gets or sets the SFX module that will be combined with the archive. + /// Sets the SFX module that will be combined with the archive. /// This module must be placed in the same directory as the 7z.exe. /// If no module is assigned, 7-Zip will use standard console SFX module 7zCon.sfx. /// /// /// The SFX module. /// - public FilePath SfxModule { get; set; } + public FilePath SfxModule { private get; set; } /// public void BuildArguments(ref ProcessArgumentBuilder builder) diff --git a/src/Cake.7zip/Switches/SwitchSetTimestampFromMostRecentFile.cs b/src/Cake.7zip/Switches/SwitchSetTimestampFromMostRecentFile.cs index e7f34a84..bc737ff2 100644 --- a/src/Cake.7zip/Switches/SwitchSetTimestampFromMostRecentFile.cs +++ b/src/Cake.7zip/Switches/SwitchSetTimestampFromMostRecentFile.cs @@ -1,12 +1,14 @@ -namespace Cake.SevenZip +using Cake.SevenZip.Builder; + +namespace Cake.SevenZip.Switches { /// /// - /// -stl (Set archive timestamp from the most recently modified file) switch. + /// -stl (Set archive time-stamp from the most recently modified file) switch. /// /// - /// If -stl switch is specified, 7-Zip sets timestamp for archive file as - /// timestamp from the most recently modified file in that archive. + /// If -stl switch is specified, 7-Zip sets time-stamp for archive file as + /// time-stamp from the most recently modified file in that archive. /// /// /// @@ -27,4 +29,4 @@ public SwitchSetTimestampFromMostRecentFile(bool value) { } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchUpdateOptions.cs b/src/Cake.7zip/Switches/SwitchUpdateOptions.cs index 73cee91a..21cafb18 100644 --- a/src/Cake.7zip/Switches/SwitchUpdateOptions.cs +++ b/src/Cake.7zip/Switches/SwitchUpdateOptions.cs @@ -1,11 +1,12 @@ -namespace Cake.SevenZip -{ - using System.Collections.Generic; - using System.Text; +using System.Collections.Generic; +using System.Text; - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -u (Update options) switch. @@ -24,75 +25,75 @@ namespace Cake.SevenZip public class SwitchUpdateOptions : ISwitch { /// - /// Gets or sets the for the p-state. + /// Sets the for the p-state. /// File exists in archive, but is not matched with wildcard. /// /// /// The . /// - public UpdateAction P { get; set; } + public UpdateAction P { private get; set; } /// - /// Gets or sets the for the q-state. + /// Sets the for the q-state. /// File exists in archive, but doesn't exist on disk. /// /// /// The . /// - public UpdateAction Q { get; set; } + public UpdateAction Q { private get; set; } /// - /// Gets or sets the for the r-state. + /// Sets the for the r-state. /// File doesn't exist in archive, but exists on disk. /// /// /// The . /// - public UpdateAction R { get; set; } + public UpdateAction R { private get; set; } /// - /// Gets or sets the for the x-state. + /// Sets the for the x-state. /// File in archive is newer than the file on disk. /// /// /// The . /// - public UpdateAction X { get; set; } + public UpdateAction X { private get; set; } /// - /// Gets or sets the for the y-state. + /// Sets the for the y-state. /// File in archive is older than the file on disk. /// /// /// The . /// - public UpdateAction Y { get; set; } + public UpdateAction Y { private get; set; } /// - /// Gets or sets the for the z-state. + /// Sets the for the z-state. /// File in archive is same as the file on disk. /// /// /// The . /// - public UpdateAction Z { get; set; } + public UpdateAction Z { private get; set; } /// - /// Gets or sets the for the w-state. + /// Sets the for the w-state. /// Can not be detected what file is newer (times are the same, sizes are different). /// /// /// The . /// - public UpdateAction W { get; set; } + public UpdateAction W { private get; set; } /// - /// Gets or sets the new archivename. + /// Sets the new archive-name. /// /// /// The new name of the archive. /// - public FilePath NewArchiveName { get; set; } + public FilePath NewArchiveName { private get; set; } /// public void BuildArguments(ref ProcessArgumentBuilder builder) @@ -126,4 +127,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append(sb.ToString()); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchVolume.cs b/src/Cake.7zip/Switches/SwitchVolume.cs index eafd3d2c..90ea4e8e 100644 --- a/src/Cake.7zip/Switches/SwitchVolume.cs +++ b/src/Cake.7zip/Switches/SwitchVolume.cs @@ -1,10 +1,11 @@ -namespace Cake.SevenZip -{ - using System; +using System; - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -v (Create Volumes) switch. @@ -24,20 +25,20 @@ namespace Cake.SevenZip public class SwitchVolume : ISwitch { /// - /// Gets or sets the size. + /// Sets the size. /// /// /// The size. Must be greater than 0. /// - public int Size { get; set; } + public int Size { private get; set; } /// - /// Gets or sets the unit. + /// Sets the unit. /// /// /// The unit. Default is bytes. /// - public VolumeUnit Unit { get; set; } + public VolumeUnit Unit { private get; set; } /// public void BuildArguments(ref ProcessArgumentBuilder builder) @@ -51,4 +52,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.Append("-v{0}{1}", Size, unit); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/SwitchVolumeCollection.cs b/src/Cake.7zip/Switches/SwitchVolumeCollection.cs index 0d6cec94..7e682596 100644 --- a/src/Cake.7zip/Switches/SwitchVolumeCollection.cs +++ b/src/Cake.7zip/Switches/SwitchVolumeCollection.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// A Collection of . @@ -12,7 +12,6 @@ public class SwitchVolumeCollection : BaseSwitchCollection /// The initial. /// The additional. public SwitchVolumeCollection(SwitchVolume initial, params SwitchVolume[] additional) - : base() { Switches.Add(initial); Switches.AddRange(additional); diff --git a/src/Cake.7zip/Switches/SwitchWorkingDirectory.cs b/src/Cake.7zip/Switches/SwitchWorkingDirectory.cs index 5637b2ab..8e58c871 100644 --- a/src/Cake.7zip/Switches/SwitchWorkingDirectory.cs +++ b/src/Cake.7zip/Switches/SwitchWorkingDirectory.cs @@ -1,8 +1,9 @@ -namespace Cake.SevenZip -{ - using Cake.Core; - using Cake.Core.IO; +using Cake.Core; +using Cake.Core.IO; +using Cake.SevenZip.Builder; +namespace Cake.SevenZip.Switches +{ /// /// /// -w (set Working directory) switch. @@ -42,4 +43,4 @@ public void BuildArguments(ref ProcessArgumentBuilder builder) builder.AppendSwitchQuoted("-w", string.Empty, path.FullPath); } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/UpdateAction.cs b/src/Cake.7zip/Switches/UpdateAction.cs index 94b04736..4e2812f1 100644 --- a/src/Cake.7zip/Switches/UpdateAction.cs +++ b/src/Cake.7zip/Switches/UpdateAction.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// Specifies the action for a given -State. @@ -40,7 +40,7 @@ private UpdateAction(string action) /// Compress (compress file from disk to new archive). /// /// - /// The copress-action. + /// The compress-action. /// public static UpdateAction Compress => new UpdateAction("2"); @@ -59,4 +59,4 @@ public override string ToString() return action; } } -} \ No newline at end of file +} diff --git a/src/Cake.7zip/Switches/VolumeUnit.cs b/src/Cake.7zip/Switches/VolumeUnit.cs index c114328d..fec3bee5 100644 --- a/src/Cake.7zip/Switches/VolumeUnit.cs +++ b/src/Cake.7zip/Switches/VolumeUnit.cs @@ -1,4 +1,4 @@ -namespace Cake.SevenZip +namespace Cake.SevenZip.Switches { /// /// Units for . @@ -33,7 +33,7 @@ private VolumeUnit(string unit) public static VolumeUnit Megabytes => new VolumeUnit("m"); /// - /// Gets Unit: Gigaytes (g). + /// Gets Unit: Gigabytes (g). /// public static VolumeUnit Gigabytes => new VolumeUnit("g"); @@ -48,4 +48,4 @@ public override string ToString() return unit; } } -} \ No newline at end of file +} diff --git a/src/vsspell.ignoredWords.txt b/src/vsspell.ignoredWords.txt new file mode 100644 index 00000000..feb99844 --- /dev/null +++ b/src/vsspell.ignoredWords.txt @@ -0,0 +1,21 @@ +sni +sns +codecs +hashers +ssw +sdel +spf +ai +ao +sfx +stl +wildcards +wildcard +nuget +locator +xz +lzma +gzip +Enum +usings +foreach