From b93744ee771ea3b1828fc922196dd6a5bc679cf0 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Mar 2017 14:38:30 -0500 Subject: [PATCH 1/5] (GH-1209) (c) Chocolatey Software to specs --- .../MockEventSubscriptionManager.cs | 9 +- .../NUnitSetup.cs | 14 +- .../Properties/AssemblyInfo.cs | 5 +- src/chocolatey.tests.integration/Scenario.cs | 14 +- src/chocolatey.tests.integration/TODO.cs | 5 +- .../services/FilesServiceSpecs.cs | 7 +- .../commands/CommandExecutorSpecs.cs | 20 +- .../cryptography/CrytpoHashProviderSpecs.cs | 9 +- .../filesystem/DotNetFileSystemSpecs.cs | 51 +++-- .../scenarios/InstallScenarios.cs | 147 +++++++------- .../scenarios/ListScenarios.cs | 11 +- .../scenarios/PackScenarios.cs | 9 +- .../scenarios/PinScenarios.cs | 9 +- .../scenarios/UninstallScenarios.cs | 37 ++-- .../scenarios/UpgradeScenarios.cs | 110 +++++------ src/chocolatey.tests/GetChocolateySpecs.cs | 5 +- src/chocolatey.tests/MockLogger.cs | 12 +- .../Properties/AssemblyInfo.cs | 8 +- .../attributes/CommandForAttributeSpecs.cs | 10 +- .../commands/ChocolateyApiKeyCommandSpecs.cs | 16 +- .../commands/ChocolateyConfigCommandSpecs.cs | 7 +- .../commands/ChocolateyFeatureCommandSpecs.cs | 37 ++-- .../commands/ChocolateyInfoCommandSpecs.cs | 9 +- .../commands/ChocolateyInstallCommandSpecs.cs | 16 +- .../commands/ChocolateyListCommandSpecs.cs | 18 +- .../commands/ChocolateyNewCommandSpecs.cs | 15 +- .../ChocolateyOutdatedCommandSpecs.cs | 18 +- .../commands/ChocolateyPackCommandSpecs.cs | 12 +- .../commands/ChocolateyPinCommandSpecs.cs | 33 ++-- .../commands/ChocolateyPushCommandSpecs.cs | 16 +- .../commands/ChocolateySourceCommandSpecs.cs | 18 +- .../ChocolateyUninstallCommandSpecs.cs | 11 +- .../ChocolateyUnpackSelfCommandSpecs.cs | 12 +- .../commands/ChocolateyUpgradeCommandSpecs.cs | 12 +- .../configuration/ConfigurationOptionsSpec.cs | 94 ++++----- .../AutomaticUninstallerServiceSpecs.cs | 105 +++++++--- .../services/FilesServiceSpecs.cs | 86 ++++---- .../services/NugetServiceSpecs.cs | 133 +++++++++---- .../services/RegistryServiceSpecs.cs | 36 ++-- .../services/TemplateServiceSpecs.cs | 164 +++++++-------- .../commandline/InteractivePromptSpecs.cs | 42 ++-- .../commands/CommandExecutorSpecs.cs | 11 +- .../ExternalCommandArgsBuilderSpecs.cs | 187 +++++++++++++++--- .../commands/PowershellExecutorSpecs.cs | 9 +- .../configuration/ConfigSpecs.cs | 7 +- .../cryptography/CrytpoHashProviderSpecs.cs | 21 +- .../events/EventSubscriptionManagerSpecs.cs | 40 ++-- .../events/context/FakeEvent.cs | 5 +- .../events/context/FakeSubscriber.cs | 12 +- .../filesystem/DotNetFileSystemSpecs.cs | 57 +++--- .../infrastructure/guards/EnsureSpecs.cs | 35 ++-- .../information/VersionInformationSpecs.cs | 7 +- .../infrastructure/platforms/PlatformSpecs.cs | 9 +- .../tokens/TokenReplacerSpecs.cs | 15 +- .../tolerance/FaultToleranceSpecs.cs | 48 +++-- 55 files changed, 1107 insertions(+), 758 deletions(-) diff --git a/src/chocolatey.tests.integration/MockEventSubscriptionManager.cs b/src/chocolatey.tests.integration/MockEventSubscriptionManager.cs index 5bd4bb32f4..659810ee53 100644 --- a/src/chocolatey.tests.integration/MockEventSubscriptionManager.cs +++ b/src/chocolatey.tests.integration/MockEventSubscriptionManager.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,9 +20,9 @@ namespace chocolatey.tests.integration using System.Collections.Concurrent; using System.Collections.Generic; using System.Reactive.Subjects; - using Moq; using chocolatey.infrastructure.events; using chocolatey.infrastructure.services; + using Moq; public class MockEventSubscriptionManager : Mock, IEventSubscriptionManagerService { @@ -34,7 +35,7 @@ public ConcurrentDictionary> Messages public void publish(Event eventMessage) where Event : class, IMessage { - var list = _messages.Value.GetOrAdd(typeof (Event), new List()); + var list = _messages.Value.GetOrAdd(typeof(Event), new List()); list.Add(eventMessage); Object.publish(eventMessage); } @@ -44,4 +45,4 @@ public IDisposable subscribe(Action handleEvent, Action return new Subject(); } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/NUnitSetup.cs b/src/chocolatey.tests.integration/NUnitSetup.cs index 6bcddd5fd5..c7a0dced73 100644 --- a/src/chocolatey.tests.integration/NUnitSetup.cs +++ b/src/chocolatey.tests.integration/NUnitSetup.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,17 +22,16 @@ namespace chocolatey.tests.integration using System.Linq; using System.Reflection; using System.Threading; - using chocolatey.infrastructure.licensing; - using NUnit.Framework; - using SimpleInjector; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.builders; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.filesystem; + using chocolatey.infrastructure.licensing; using chocolatey.infrastructure.platforms; using chocolatey.infrastructure.registration; - using chocolatey.infrastructure.services; + using NUnit.Framework; + using SimpleInjector; // ReSharper disable InconsistentNaming @@ -51,13 +51,13 @@ public override void BeforeEverything() // don't have to worry about issues using it var config = Container.GetInstance().deep_copy(); config.Information.PlatformType = PlatformType.Windows; - config.Information.IsInteractive = false; + config.Information.IsInteractive = false; config.PromptForConfirmation = false; config.Force = true; unpack_self(Container, config); build_packages(Container, config); - ConfigurationBuilder.set_up_configuration(new List(), config, Container, new ChocolateyLicense(), null); + ConfigurationBuilder.set_up_configuration(new List(), config, Container, new ChocolateyLicense(), null); MockLogger.reset(); } diff --git a/src/chocolatey.tests.integration/Properties/AssemblyInfo.cs b/src/chocolatey.tests.integration/Properties/AssemblyInfo.cs index bb45f433c6..2560401790 100644 --- a/src/chocolatey.tests.integration/Properties/AssemblyInfo.cs +++ b/src/chocolatey.tests.integration/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -51,4 +52,4 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 5c351da576..2ecad30aef 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ namespace chocolatey.tests.integration { using System; + using System.Collections.Generic; using System.IO; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.configuration; @@ -24,7 +26,6 @@ namespace chocolatey.tests.integration using chocolatey.infrastructure.commands; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.platforms; - using System.Collections.Generic; public class Scenario { @@ -89,11 +90,11 @@ public static void install_package(ChocolateyConfiguration config, string packag _service = NUnitSetup.Container.GetInstance(); } var installConfig = config.deep_copy(); - + installConfig.PackageNames = packageId; installConfig.Version = version; _service.install_run(installConfig); - + NUnitSetup.MockLogger.Messages.Clear(); } @@ -108,11 +109,12 @@ public static void add_files(IEnumerable> files) _fileSystem.write_file(file.Item1, file.Item2); } } - + public static void create_directory(string directoryPath) { _fileSystem.create_directory(directoryPath); } + private static ChocolateyConfiguration baseline_configuration() { // note that this does not mean an empty configuration. It does get influenced by @@ -122,7 +124,7 @@ private static ChocolateyConfiguration baseline_configuration() config.Information.PlatformType = PlatformType.Windows; config.Information.IsInteractive = false; config.Information.ChocolateyVersion = "1.2.3"; - config.Information.PlatformVersion = new Version(6,1,0,0); + config.Information.PlatformVersion = new Version(6, 1, 0, 0); config.Information.PlatformName = "Windows 7 SP1"; config.Information.ChocolateyVersion = "1.2.3"; config.Information.ChocolateyProductVersion = "1.2.3"; diff --git a/src/chocolatey.tests.integration/TODO.cs b/src/chocolatey.tests.integration/TODO.cs index 9fc4e14810..b19b32afb8 100644 --- a/src/chocolatey.tests.integration/TODO.cs +++ b/src/chocolatey.tests.integration/TODO.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -43,4 +44,4 @@ public class TODO * */ } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs index 6a0d452eca..25964c6552 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,8 +19,6 @@ namespace chocolatey.tests.integration.infrastructure.app.services using System; using System.IO; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; @@ -28,6 +27,8 @@ namespace chocolatey.tests.integration.infrastructure.app.services using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.results; using chocolatey.infrastructure.services; + using Moq; + using Should; public class FilesServiceSpecs { diff --git a/src/chocolatey.tests.integration/infrastructure/commands/CommandExecutorSpecs.cs b/src/chocolatey.tests.integration/infrastructure/commands/CommandExecutorSpecs.cs index 0b40494b80..6d1d33d1b6 100644 --- a/src/chocolatey.tests.integration/infrastructure/commands/CommandExecutorSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/commands/CommandExecutorSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,10 +17,10 @@ namespace chocolatey.tests.integration.infrastructure.commands { using System; - using Should; using chocolatey.infrastructure.app; using chocolatey.infrastructure.commands; using chocolatey.infrastructure.filesystem; + using Should; public class CommandExecutorSpecs { @@ -31,7 +32,6 @@ public abstract class CommandExecutorSpecsBase : TinySpec public override void Context() { commandExecutor = new CommandExecutor(fileSystem); - } } @@ -46,8 +46,16 @@ public override void Context() } public override void Because() - { - result = commandExecutor.execute("cmd.exe", "/c bob123123", ApplicationParameters.DefaultWaitForExitInSeconds, fileSystem.get_current_directory(), null, (s, e) => { errorOutput += e.Data; }, updateProcessPath: false, allowUseWindow: false); + { + result = commandExecutor.execute( + "cmd.exe", + "/c bob123123", + ApplicationParameters.DefaultWaitForExitInSeconds, + fileSystem.get_current_directory(), + null, + (s, e) => { errorOutput += e.Data; }, + updateProcessPath: false, + allowUseWindow: false); } [Fact] @@ -93,4 +101,4 @@ public void should_have_an_error_message() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs b/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs index 6b3de12e1c..8940956c20 100644 --- a/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/cryptography/CrytpoHashProviderSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,12 +18,10 @@ namespace chocolatey.tests.integration.infrastructure.cryptography { using System; using System.IO; - using System.Reflection; using System.Security.Cryptography; - using chocolatey.infrastructure.app.configuration; - using Should; using chocolatey.infrastructure.cryptography; using chocolatey.infrastructure.filesystem; + using Should; public class CrytpoHashProviderSpecs { @@ -65,4 +64,4 @@ public void should_provide_the_correct_hash_based_on_a_checksum() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs index 20670c3f32..c7bf54a4b0 100644 --- a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,10 +19,10 @@ namespace chocolatey.tests.integration.infrastructure.filesystem using System; using System.IO; using System.Linq; - using NUnit.Framework; - using Should; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.platforms; + using NUnit.Framework; + using Should; public class DotNetFileSystemSpecs { @@ -60,22 +61,22 @@ public override void Because() public void GetExecutablePath_should_find_existing_executable() { FileSystem.get_executable_path("cmd").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\Windows\\system32\\cmd.exe" + Platform.get_platform() == PlatformType.Windows + ? "C:\\Windows\\system32\\cmd.exe" : "cmd", StringComparer.OrdinalIgnoreCase - ); + ); } [Fact] public void GetExecutablePath_should_find_existing_executable_with_extension() { FileSystem.get_executable_path("cmd.exe").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "c:\\windows\\system32\\cmd.exe" + Platform.get_platform() == PlatformType.Windows + ? "c:\\windows\\system32\\cmd.exe" : "cmd", StringComparer.OrdinalIgnoreCase - ); + ); } [Fact] @@ -95,7 +96,6 @@ public void GetExecutablePath_should_return_empty_string_when_value_is_empty_str { FileSystem.get_executable_path(string.Empty).ShouldEqual(string.Empty); } - } [Category("Integration")] @@ -105,14 +105,14 @@ public override void Context() { base.Context(); FileArray = new[] - { - Path.Combine(ContextPath, TheTestFile) - }; + { + Path.Combine(ContextPath, TheTestFile) + }; DirectoryArray = new[] - { - DestinationPath - }; + { + DestinationPath + }; } public override void Because() @@ -200,9 +200,9 @@ public override void Context() public override void Because() { - FileSystem.ensure_file_attribute_set(SourceFile,FileAttributes.Hidden); + FileSystem.ensure_file_attribute_set(SourceFile, FileAttributes.Hidden); } - + [Fact] public void visible_file_should_now_be_hidden() { @@ -214,9 +214,8 @@ public override void AfterObservations() base.AfterObservations(); File.SetAttributes(SourceFile, (FileSystem.get_file_info_for(SourceFile).Attributes & ~FileAttributes.Hidden)); } - } - - + } + [Category("Integration")] public class when_removing_readonly_attributes_with_dotNetFileSystem : DotNetFileSystemSpecsBase { @@ -229,16 +228,16 @@ public override void Context() public override void Because() { - FileSystem.ensure_file_attribute_removed(SourceFile,FileAttributes.ReadOnly); + FileSystem.ensure_file_attribute_removed(SourceFile, FileAttributes.ReadOnly); } - + [Fact] public void readonly_file_should_no_longer_be_readonly() { ((FileAttributes)FileSystem.get_file_info_for(SourceFile).Attributes & FileAttributes.ReadOnly).ShouldNotEqual(FileAttributes.ReadOnly); } - } - + } + [Category("Integration")] public class when_running_fileMove_with_dotNetFileSystem : DotNetFileSystemSpecsBase { @@ -363,4 +362,4 @@ public void should_have_correct_modified_date() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 58524551c3..339220bcc2 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,24 +16,21 @@ namespace chocolatey.tests.integration.scenarios { - using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; - using System.Xml; using System.Xml.XPath; - using Microsoft.Web.XmlTransform; - using NuGet; - using Should; using bdddoc.core; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commands; using chocolatey.infrastructure.results; + using NuGet; + using Should; using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; - + public class InstallScenarios { public abstract class ScenariosBase : TinySpec @@ -136,8 +134,8 @@ public void should_contain_a_message_that_it_would_have_used_Nuget_to_install_a_ } expectedMessage.ShouldBeTrue(); - } - + } + [Fact] public void should_contain_a_message_that_it_was_unable_to_find_package() { @@ -183,7 +181,7 @@ public void should_install_the_expected_version_of_the_package() var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] public void should_create_a_shim_for_console_in_the_bin_directory() { @@ -214,8 +212,8 @@ public void should_not_create_a_shim_for_mismatched_case_ignored_executable_in_t var shimfile = Path.Combine(Scenario.get_top_level(), "bin", "casemismatch.exe"); File.Exists(shimfile).ShouldBeFalse(); - } - + } + [Fact] public void should_not_create_an_extensions_folder_for_the_package() { @@ -236,7 +234,7 @@ public void should_have_a_console_shim_that_is_set_for_non_gui_access() 10, stdOutAction: (s, e) => messages.Add(e.Data), stdErrAction: (s, e) => messages.Add(e.Data) - ); + ); var messageFound = false; @@ -261,7 +259,7 @@ public void should_have_a_graphical_shim_that_is_set_for_gui_access() 10, stdOutAction: (s, e) => messages.Add(e.Data), stdErrAction: (s, e) => messages.Add(e.Data) - ); + ); var messageFound = false; @@ -330,7 +328,7 @@ public override void Context() { base.Context(); var packagesConfig = "{0}\\context\\testing.packages.config".format_with(Scenario.get_top_level()); - Configuration.PackageNames = Configuration.Input = packagesConfig; + Configuration.PackageNames = Configuration.Input = packagesConfig; Scenario.add_packages_to_source_location(Configuration, "hasdependency.1.0.0*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isdependency.1.0.0*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isexactversiondependency*" + Constants.PackageExtension); @@ -356,7 +354,13 @@ public void should_install_where_install_location_reports() [Fact] public void should_install_expected_packages_in_the_lib_directory() { - var packagesExpected = new List {"installpackage", "hasdependency", "isdependency", "upgradepackage"}; + var packagesExpected = new List + { + "installpackage", + "hasdependency", + "isdependency", + "upgradepackage" + }; foreach (var package in packagesExpected) { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", package); @@ -485,7 +489,7 @@ public void should_still_have_a_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeTrue(); } - + [Fact] public void should_still_have_the_expected_version_of_the_package_installed() { @@ -493,7 +497,7 @@ public void should_still_have_the_expected_version_of_the_package_installed() var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] public void should_contain_a_warning_message_that_it_was_unable_to_install_any_packages() { @@ -538,15 +542,15 @@ public void should_ave_warning_package_result() public class when_force_installing_an_already_installed_package : ScenariosBase { private PackageResult packageResult; - private string modifiedText = "bob"; + private readonly string modifiedText = "bob"; public override void Context() { base.Context(); Scenario.install_package(Configuration, "installpackage", "1.0.0"); var fileToModify = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "chocolateyInstall.ps1"); - File.WriteAllText(fileToModify,modifiedText); - + File.WriteAllText(fileToModify, modifiedText); + Configuration.Force = true; } @@ -577,7 +581,7 @@ public void should_install_the_same_version_of_the_package() var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] public void should_remove_and_re_add_the_package_files_in_the_lib_directory() { @@ -640,7 +644,7 @@ public void should_have_a_version_of_one_dot_zero_dot_zero() public class when_force_installing_an_already_installed_package_that_errors : ScenariosBase { private PackageResult packageResult; - private string modifiedText = "bob"; + private readonly string modifiedText = "bob"; public override void Context() { @@ -668,7 +672,7 @@ public void should_restore_the_backup_version_of_the_package() var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] public void should_restore_the_original_files_in_the_package_lib_folder() { @@ -713,7 +717,6 @@ public void should_not_have_warning_package_result() { packageResult.Warning.ShouldBeFalse(); } - } [Concern(typeof(ChocolateyInstallCommand))] @@ -736,7 +739,7 @@ public override void AfterObservations() base.AfterObservations(); fileStream.Close(); } - + public override void Because() { Results = Service.install_run(Configuration); @@ -836,13 +839,13 @@ public override void AfterObservations() base.AfterObservations(); fileStream.Close(); } - + public override void Because() { Results = Service.install_run(Configuration); packageResult = Results.FirstOrDefault().Value; } - + [Fact] public void should_have_a_package_installed_in_the_lib_directory() { @@ -850,7 +853,7 @@ public void should_have_a_package_installed_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeTrue(); } - + [Fact] public void should_still_have_the_package_installed_with_the_expected_version_of_the_package() { @@ -858,7 +861,7 @@ public void should_still_have_the_package_installed_with_the_expected_version_of var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] [Pending("Force install with file locked leaves inconsistent state - GH-114")] public void should_delete_the_rollback() @@ -1385,7 +1388,7 @@ public void should_install_a_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeTrue(); } - + [Fact] public void should_contain_a_warning_message_that_it_installed_successfully() { @@ -1461,7 +1464,7 @@ public void should_install_a_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeTrue(); } - + [Fact] public void should_contain_a_warning_message_that_it_installed_successfully() { @@ -1515,7 +1518,7 @@ public override void Context() base.Context(); Configuration.AllowMultipleVersions = true; Scenario.install_package(Configuration, "installpackage", "1.0.0"); - Configuration.AllowMultipleVersions =false; + Configuration.AllowMultipleVersions = false; Configuration.Force = true; } @@ -1538,7 +1541,7 @@ public void should_install_a_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeTrue(); } - + [Fact] public void should_contain_a_warning_message_that_it_installed_successfully() { @@ -1630,7 +1633,7 @@ public void should_install_the_expected_version_of_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } + } [Fact] public void should_contain_a_message_that_everything_installed_successfully() @@ -1687,7 +1690,7 @@ public class when_force_installing_an_already_installed_package_with_dependencie public override void Context() { base.Context(); - + Configuration.PackageNames = Configuration.Input = "hasdependency"; Scenario.add_packages_to_source_location(Configuration, "hasdependency.1*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isdependency.1.0.0*" + Constants.PackageExtension); @@ -1798,7 +1801,7 @@ public class when_force_installing_an_already_installed_package_forcing_dependen public override void Context() { base.Context(); - + Configuration.PackageNames = Configuration.Input = "hasdependency"; Scenario.add_packages_to_source_location(Configuration, "hasdependency.1*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isdependency.1.0.0*" + Constants.PackageExtension); @@ -1853,8 +1856,8 @@ public void should_reinstall_the_floating_dependency_with_the_latest_version_tha var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.1.0.0"); - } - + } + [Fact] public void should_reinstall_the_exact_same_version_of_the_exact_dependency() { @@ -1909,7 +1912,7 @@ public class when_force_installing_an_already_installed_package_ignoring_depende public override void Context() { base.Context(); - + Configuration.PackageNames = Configuration.Input = "hasdependency"; Scenario.add_packages_to_source_location(Configuration, "hasdependency.1*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isdependency.1.0.0*" + Constants.PackageExtension); @@ -1965,7 +1968,7 @@ public void should_not_touch_the_floating_dependency() var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); } - + [Fact] public void should_not_touch_the_exact_dependency() { @@ -2020,7 +2023,7 @@ public class when_force_installing_an_already_installed_package_forcing_and_igno public override void Context() { base.Context(); - + Configuration.PackageNames = Configuration.Input = "hasdependency"; Scenario.add_packages_to_source_location(Configuration, "hasdependency.1*" + Constants.PackageExtension); Scenario.add_packages_to_source_location(Configuration, "isdependency.1.0.0*" + Constants.PackageExtension); @@ -2067,8 +2070,8 @@ public void should_remove_the_floating_dependency() { var dependency = Path.Combine(Scenario.get_top_level(), "lib", "isdependency"); Directory.Exists(dependency).ShouldBeFalse(); - } - + } + [Fact] public void should_remove_the_exact_dependency() { @@ -2366,7 +2369,7 @@ public void should_install_the_dependency_in_the_lib_directory() [Fact] public void should_upgrade_the_dependency() { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency","isdependency.nupkg"); + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.1.0.0"); } @@ -2436,7 +2439,7 @@ public void should_not_install_the_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeFalse(); } - + [Fact] public void should_contain_a_message_that_is_was_unable_to_install_any_packages() { @@ -2475,9 +2478,8 @@ public void should_not_have_warning_package_result() packageResult.Value.Warning.ShouldBeFalse(); } } + } - } - [Concern(typeof(ChocolateyInstallCommand))] public class when_installing_a_package_that_depends_on_an_unavailable_newer_version_of_an_installed_dependency_ignoring_dependencies : ScenariosBase { @@ -2596,8 +2598,8 @@ public void should_not_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] public void should_contain_a_warning_message_that_it_was_unable_to_install_any_packages() { @@ -2719,8 +2721,8 @@ public void should_upgrade_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.1.0"); - } - + } + [Fact] public void should_contain_a_message_that_it_installed_successfully() { @@ -2759,8 +2761,8 @@ public void should_not_have_warning_package_result() packageResult.Value.Warning.ShouldBeFalse(); } } - } - + } + [Concern(typeof(ChocolateyInstallCommand))] public class when_installing_a_package_with_dependencies_on_a_newer_version_of_a_package_than_are_allowed_by_an_existing_package_with_that_dependency : ScenariosBase { @@ -2807,8 +2809,8 @@ public void should_not_upgrade_the_minimum_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] [Pending("NuGet does not deal with version conflicts - GH-116")] public void should_not_upgrade_the_exact_version_dependency() @@ -2816,8 +2818,8 @@ public void should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] [Pending("NuGet does not deal with version conflicts - GH-116")] public void should_contain_a_message_that_it_was_unable_to_install_any_packages() @@ -2880,8 +2882,8 @@ public void should_have_an_error_package_result() errorFound.ShouldBeTrue(); } - } - + } + [Concern(typeof(ChocolateyInstallCommand))] public class when_installing_a_package_with_dependencies_on_an_older_version_of_a_package_than_is_already_installed : ScenariosBase { @@ -2924,8 +2926,8 @@ public void should_not_upgrade_the_exact_version_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] [Pending("NuGet does not deal with version conflicts - GH-116")] public void should_contain_a_message_that_it_was_unable_to_install_any_packages() @@ -2988,8 +2990,8 @@ public void should_have_an_error_package_result() errorFound.ShouldBeTrue(); } - } - + } + [Concern(typeof(ChocolateyInstallCommand))] public class when_installing_a_package_with_a_dependent_package_that_also_depends_on_a_less_constrained_but_still_valid_dependency_of_the_same_package : ScenariosBase { @@ -3049,8 +3051,8 @@ public void should_install_the_expected_version_of_the_dependency() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "childdependencywithlooserversiondependency", "childdependencywithlooserversiondependency.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] [Pending("NuGet does not handle version conflicts with highestversion dependency resolution - GH-507")] public void should_install_the_expected_version_of_the_constrained_dependency() @@ -3101,7 +3103,7 @@ public void should_not_have_warning_package_result() { packageResult.Value.Warning.ShouldBeFalse(); } - } + } } [Concern(typeof(ChocolateyInstallCommand))] @@ -3195,7 +3197,7 @@ public void should_have_a_console_shim_that_is_set_for_non_gui_access() 10, stdOutAction: (s, e) => messages.Add(e.Data), stdErrAction: (s, e) => messages.Add(e.Data) - ); + ); var messageFound = false; @@ -3220,7 +3222,7 @@ public void should_have_a_graphical_shim_that_is_set_for_gui_access() 10, stdOutAction: (s, e) => messages.Add(e.Data), stdErrAction: (s, e) => messages.Add(e.Data) - ); + ); var messageFound = false; @@ -3286,7 +3288,7 @@ public class when_installing_a_package_with_config_transforms : ScenariosBase public override void Context() { base.Context(); - Configuration.PackageNames = Configuration.Input = "upgradepackage"; + Configuration.PackageNames = Configuration.Input = "upgradepackage"; Scenario.add_packages_to_source_location(Configuration, "upgradepackage.1.0.0*" + Constants.PackageExtension); _xmlFilePath = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe.config"); @@ -3366,7 +3368,6 @@ public void should_add_the_insert_value_in_the_config_due_to_XDT_InsertIfMissing [Concern(typeof(ChocolateyInstallCommand))] public class when_installing_a_package_with_no_sources_enabled : ScenariosBase { - public override void Context() { base.Context(); @@ -3388,7 +3389,7 @@ public void should_have_no_sources_enabled_result() public void should_not_install_any_packages() { Results.Count().ShouldEqual(0); - } + } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index 4920694b5b..596730bcdc 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,14 +18,14 @@ namespace chocolatey.tests.integration.scenarios { using System.Collections.Generic; using System.Linq; - using NuGet; - using Should; using bdddoc.core; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.results; + using NuGet; + using Should; public class ListScenarios { @@ -344,7 +345,6 @@ public void should_not_contain_debugging_messages() [Concern(typeof(ChocolateyListCommand))] public class when_listing_packages_with_no_sources_enabled : ScenariosBase { - public override void Context() { base.Context(); @@ -367,8 +367,7 @@ public void should_have_no_sources_enabled_result() public void should_not_list_any_packages() { Results.Count().ShouldEqual(0); - } - + } } [Concern(typeof(ChocolateyListCommand))] diff --git a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs index fc0490a6cc..046c6b73e2 100644 --- a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,13 +16,13 @@ namespace chocolatey.tests.integration.scenarios { - using Should; using System; using System.IO; using bdddoc.core; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; + using Should; public class PackScenarios { @@ -74,7 +75,7 @@ public void generated_package_should_be_in_current_directory() [Fact] public void sources_should_be_set_to_current_directory() { - Configuration.Sources.ShouldEqual(Scenario.get_top_level()); + Configuration.Sources.ShouldEqual(Scenario.get_top_level()); } } @@ -132,4 +133,4 @@ public void sources_should_be_set_to_specified_output_directory() "; } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/scenarios/PinScenarios.cs b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs index cd1e5b6f93..ba2660fb02 100644 --- a/src/chocolatey.tests.integration/scenarios/PinScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/PinScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,8 +19,6 @@ namespace chocolatey.tests.integration.scenarios using System; using System.Collections.Generic; using System.Linq; - using NuGet; - using Should; using bdddoc.core; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.attributes; @@ -28,6 +27,8 @@ namespace chocolatey.tests.integration.scenarios using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.commands; using chocolatey.infrastructure.results; + using NuGet; + using Should; public class PinScenarios { @@ -124,7 +125,7 @@ public void should_contain_existing_pin_messages() MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeTrue(); } } - + [Concern(typeof(ChocolateyPinCommand))] public class when_listing_pins_with_existing_pins : ScenariosBase { diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index 59fb2094c2..4dc04ffc3c 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,9 +20,6 @@ namespace chocolatey.tests.integration.scenarios using System.Collections.Concurrent; using System.IO; using System.Linq; - using NUnit.Framework; - using NuGet; - using Should; using bdddoc.core; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; @@ -29,6 +27,9 @@ namespace chocolatey.tests.integration.scenarios using chocolatey.infrastructure.commands; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.results; + using NuGet; + using NUnit.Framework; + using Should; using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; public class UninstallScenarios @@ -58,7 +59,7 @@ public override void Context() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_noop_uninstalling_a_package : ScenariosBase { public override void Context() @@ -105,7 +106,7 @@ public void should_contain_a_message_that_it_would_have_run_powershell_modificat } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_noop_uninstalling_a_package_that_does_not_exist : ScenariosBase { public override void Context() @@ -133,7 +134,7 @@ public void should_contain_a_message_that_it_was_unable_to_find_package() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_happy_path : ScenariosBase { private PackageResult packageResult; @@ -233,7 +234,7 @@ public void should_have_executed_chocolateyUninstall_script() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_force_uninstalling_a_package : ScenariosBase { private PackageResult packageResult; @@ -319,7 +320,7 @@ public void config_should_match_package_result_name() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_packages_with_packages_config : ScenariosBase { public override void Context() @@ -334,7 +335,7 @@ public override void Because() } [Fact] - [ExpectedException(typeof (ApplicationException))] + [ExpectedException(typeof(ApplicationException))] public void should_throw_an_error_that_it_is_not_allowed() { Results = Service.uninstall_run(Configuration); @@ -407,7 +408,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_with_a_read_and_delete_share_locked_file : ScenariosBase { private PackageResult _packageResult; @@ -480,7 +481,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_with_an_exclusively_locked_file : ScenariosBase { private PackageResult _packageResult; @@ -561,7 +562,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_with_added_files : ScenariosBase { private PackageResult packageResult; @@ -659,7 +660,7 @@ public void config_should_match_package_result_name() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_with_changed_files : ScenariosBase { private PackageResult packageResult; @@ -757,7 +758,7 @@ public void config_should_match_package_result_name() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_force_uninstalling_a_package_with_added_and_changed_files : ScenariosBase { private PackageResult packageResult; @@ -863,7 +864,7 @@ public void config_should_match_package_result_name() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_that_does_not_exist : ScenariosBase { private PackageResult packageResult; @@ -938,7 +939,7 @@ public void should_have_an_error_package_result() } } - [Concern(typeof (ChocolateyUninstallCommand))] + [Concern(typeof(ChocolateyUninstallCommand))] public class when_uninstalling_a_package_that_errors : ScenariosBase { private PackageResult packageResult; @@ -1047,4 +1048,4 @@ public void should_have_expected_error_in_package_result() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 1b55cb2dd9..0b68f1bb62 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,15 +22,15 @@ namespace chocolatey.tests.integration.scenarios using System.Linq; using System.Threading; using System.Xml.XPath; - using NUnit.Framework; - using NuGet; - using Should; using bdddoc.core; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.results; + using NuGet; + using NUnit.Framework; + using Should; public class UpgradeScenarios { @@ -57,7 +58,7 @@ public override void Context() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_noop_upgrading_a_package_that_has_available_upgrades : ScenariosBase { public override void Context() @@ -112,7 +113,7 @@ public void should_not_create_a_rollback() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_noop_upgrading_a_package_that_does_not_have_available_upgrades : ScenariosBase { public override void Context() @@ -160,7 +161,7 @@ public void should_not_create_a_rollback() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_noop_upgrading_a_package_that_does_not_exist : ScenariosBase { public override void Context() @@ -200,7 +201,7 @@ public void should_contain_a_message_that_no_packages_can_be_upgraded() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_an_existing_package_happy_path : ScenariosBase { private PackageResult _packageResult; @@ -337,7 +338,7 @@ public void should_have_executed_chocolateyInstall_script_for_new_package() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_an_existing_package_with_prerelease_available_without_prerelease_specified : ScenariosBase { private PackageResult _packageResult; @@ -427,7 +428,7 @@ public void should_match_the_original_package_version() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_an_existing_package_with_prerelease_available_and_prerelease_specified : ScenariosBase { private PackageResult _packageResult; @@ -570,8 +571,8 @@ public void should_have_executed_chocolateyInstall_script_for_new_package() MockLogger.contains_message("upgradepackage 1.1.1-beta2 Installed", LogLevel.Info).ShouldBeTrue(); } } - - [Concern(typeof (ChocolateyUpgradeCommand))] + + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_an_existing_prerelease_package_without_prerelease_specified : ScenariosBase { private PackageResult _packageResult; @@ -730,7 +731,7 @@ public override void Context() Configuration.Prerelease = false; Configuration.UpgradeCommand.ExcludePrerelease = true; } - + public override void Because() { Results = Service.upgrade_run(Configuration); @@ -810,7 +811,7 @@ public void should_only_find_the_last_stable_version() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_force_upgrading_a_package : ScenariosBase { private PackageResult _packageResult; @@ -920,7 +921,7 @@ public void should_match_the_upgrade_version_of_one_dot_one_dot_zero() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_that_does_not_have_available_upgrades : ScenariosBase { private PackageResult _packageResult; @@ -1010,7 +1011,7 @@ public void should_match_the_existing_version_of_one_dot_zero_dot_zero() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_force_upgrading_a_package_that_does_not_have_available_upgrades : ScenariosBase { private PackageResult _packageResult; @@ -1101,7 +1102,7 @@ public void should_match_the_existing_version_of_one_dot_zero_dot_zero() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_packages_with_packages_config : ScenariosBase { public override void Context() @@ -1116,7 +1117,7 @@ public override void Because() } [Fact] - [ExpectedException(typeof (ApplicationException))] + [ExpectedException(typeof(ApplicationException))] public void should_throw_an_error_that_it_is_not_allowed() { Results = Service.upgrade_run(Configuration); @@ -1128,7 +1129,6 @@ public class when_upgrading_a_package_with_readonly_files : ScenariosBase { private PackageResult _packageResult; - public override void Context() { base.Context(); @@ -1224,7 +1224,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_a_read_and_delete_share_locked_file : ScenariosBase { private PackageResult _packageResult; @@ -1331,7 +1331,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_an_exclusively_locked_file : ScenariosBase { private PackageResult _packageResult; @@ -1432,7 +1432,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_added_files : ScenariosBase { private PackageResult _packageResult; @@ -1511,7 +1511,7 @@ public void should_match_the_upgrade_version_of_one_dot_one_dot_zero() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_changed_files : ScenariosBase { private PackageResult _packageResult; @@ -1590,7 +1590,7 @@ public void should_match_the_upgrade_version_of_one_dot_one_dot_zero() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_that_does_not_exist : ScenariosBase { private PackageResult packageResult; @@ -1671,7 +1671,7 @@ public void should_have_an_error_package_result() errorFound.ShouldBeTrue(); } - + [Fact] public void should_have_expected_error_in_package_result() { @@ -1686,7 +1686,6 @@ public void should_have_expected_error_in_package_result() errorFound.ShouldBeTrue(); } - } [Concern(typeof(ChocolateyUpgradeCommand))] @@ -1758,8 +1757,8 @@ public void should_not_have_warning_package_result() { _packageResult.Warning.ShouldBeFalse(); } - } - + } + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_that_is_not_installed_and_failing_on_not_installed : ScenariosBase { @@ -1786,7 +1785,7 @@ public void should_not_install_a_package_in_the_lib_directory() Directory.Exists(packageDir).ShouldBeFalse(); } - + [Fact] public void should_contain_a_warning_message_that_it_was_unable_to_upgrade_a_package() { @@ -1848,7 +1847,7 @@ public void should_have_expected_error_in_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_that_errors : ScenariosBase { private PackageResult packageResult; @@ -1966,7 +1965,7 @@ public void should_have_expected_error_in_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_dependencies_happy : ScenariosBase { public override void Context() @@ -2049,7 +2048,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_unavailable_dependencies : ScenariosBase { public override void Context() @@ -2170,7 +2169,7 @@ public void should_have_expected_error_in_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_unavailable_dependencies_ignoring_dependencies : ScenariosBase { public override void Context() @@ -2254,7 +2253,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_dependency_happy : ScenariosBase { public override void Context() @@ -2337,7 +2336,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_dependency_legacy_folder_version : ScenariosBase { public override void Context() @@ -2478,7 +2477,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_dependency_with_parent_that_depends_on_a_range_less_than_upgrade_version : ScenariosBase { public override void Context() @@ -2561,7 +2560,7 @@ public void should_not_have_warning_package_result() } } - [Concern(typeof (ChocolateyUpgradeCommand))] + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_legacy_folder_dependency_with_parent_that_depends_on_a_range_less_than_upgrade_version : ScenariosBase { public override void Context() @@ -2706,7 +2705,7 @@ public class when_upgrading_a_package_with_config_transforms : ScenariosBase public override void Context() { base.Context(); - + _xmlFilePath = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe.config"); } @@ -2718,7 +2717,7 @@ public override void Because() var xmlDocument = new XPathDocument(_xmlFilePath); _xPathNavigator = xmlDocument.CreateNavigator(); } - + [Fact] public void should_upgrade_the_package() { @@ -2790,8 +2789,8 @@ public void should_add_the_insertNew_value_in_the_config_due_to_XDT_InsertIfMiss { _xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='insertNew']/@value").TypedValue.to_string().ShouldEqual("1.1.0"); } - } - + } + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_config_transforms_when_config_was_edited : ScenariosBase { @@ -2803,9 +2802,9 @@ public class when_upgrading_a_package_with_config_transforms_when_config_was_edi public override void Context() { base.Context(); - + _xmlFilePath = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, "tools", "console.exe.config"); - + File.WriteAllText(_xmlFilePath, File.ReadAllText(_xmlFilePath) + COMMENT_ADDED); } @@ -2817,7 +2816,7 @@ public override void Because() var xmlDocument = new XPathDocument(_xmlFilePath); _xPathNavigator = xmlDocument.CreateNavigator(); } - + [Fact] public void should_upgrade_the_package() { @@ -2882,8 +2881,8 @@ public void should_change_the_testReplace_value_in_the_config_due_to_XDT_Replace public void should_not_change_the_insert_value_in_the_config_due_to_upgrade_and_XDT_InsertIfMissing() { _xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='insert']/@value").TypedValue.to_string().ShouldEqual("1.0.0"); - } - + } + [Fact] public void should_add_the_insertNew_value_in_the_config_due_to_XDT_InsertIfMissing() { @@ -2900,7 +2899,6 @@ public void should_have_a_config_with_the_comment_from_the_original() [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_a_package_with_no_sources_enabled : ScenariosBase { - public override void Context() { base.Context(); @@ -2916,13 +2914,13 @@ public override void Because() public void should_have_no_sources_enabled_result() { MockLogger.contains_message("Upgrading was NOT successful. There are no sources enabled for", LogLevel.Error).ShouldBeTrue(); - } + } [Fact] public void should_not_have_any_packages_upgraded() { Results.Count().ShouldEqual(0); - } + } } [Concern(typeof(ChocolateyUpgradeCommand))] @@ -2960,8 +2958,8 @@ public void should_skip_packages_without_upgrades() installPackageResult.Count.ShouldEqual(1, "installpackage must be there once"); installPackageResult.First().Value.Version.ShouldEqual("1.0.0"); } - } - + } + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_all_packages_with_prereleases_installed : ScenariosBase { @@ -2992,7 +2990,7 @@ public void should_upgrade_packages_with_upgrades() upgradePackageResult.Count.ShouldEqual(1, "upgradepackage must be there once"); upgradePackageResult.First().Value.Version.ShouldEqual("1.1.1-beta2"); } - + [Fact] public void should_upgrade_upgradepackage() { @@ -3008,8 +3006,8 @@ public void should_skip_packages_without_upgrades() installPackageResult.Count.ShouldEqual(1, "installpackage must be there once"); installPackageResult.First().Value.Version.ShouldEqual("1.0.0"); } - } - + } + [Concern(typeof(ChocolateyUpgradeCommand))] public class when_upgrading_all_packages_with_prereleases_installed_with_excludeprerelease_specified : ScenariosBase { @@ -3019,7 +3017,7 @@ public override void Context() Configuration.Prerelease = true; Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); Configuration.Prerelease = false; - + Configuration.PackageNames = Configuration.Input = "all"; Configuration.UpgradeCommand.ExcludePrerelease = true; } @@ -3091,4 +3089,4 @@ public void should_skip_packages_in_except_list() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/GetChocolateySpecs.cs b/src/chocolatey.tests/GetChocolateySpecs.cs index 20fd5d6ec9..333e060fd1 100644 --- a/src/chocolatey.tests/GetChocolateySpecs.cs +++ b/src/chocolatey.tests/GetChocolateySpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -73,4 +74,4 @@ public void should_get_instantiated_chocolatey2() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/MockLogger.cs b/src/chocolatey.tests/MockLogger.cs index 20c53a2afe..dc236ac3c4 100644 --- a/src/chocolatey.tests/MockLogger.cs +++ b/src/chocolatey.tests/MockLogger.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,8 +19,8 @@ namespace chocolatey.tests using System; using System.Collections.Concurrent; using System.Collections.Generic; - using Moq; using chocolatey.infrastructure.logging; + using Moq; public enum LogLevel { @@ -52,7 +53,7 @@ public bool contains_message(string expectedMessage, LogLevel level) { return contains_message_count(expectedMessage, level) != 0; } - + public int contains_message_count(string expectedMessage) { int messageCount = 0; @@ -102,7 +103,7 @@ public void LogMessage(LogLevel logLevel, string message) list.Add(message); if (LogMessagesToConsole) { - System.Console.WriteLine("[{0}] {1}".format_with(logLevel.to_string(),message)); + Console.WriteLine("[{0}] {1}".format_with(logLevel.to_string(), message)); } } @@ -122,7 +123,6 @@ public void Info(string message, params object[] formatting) { Object.Info(message.format_with(formatting)); LogMessage(LogLevel.Info, message.format_with(formatting)); - } public void Info(Func message) @@ -167,4 +167,4 @@ public void Fatal(Func message) LogMessage(LogLevel.Fatal, message()); } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/Properties/AssemblyInfo.cs b/src/chocolatey.tests/Properties/AssemblyInfo.cs index 5235581c2d..e0dab35491 100644 --- a/src/chocolatey.tests/Properties/AssemblyInfo.cs +++ b/src/chocolatey.tests/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Reflection; +using System.Reflection; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -30,6 +31,7 @@ [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible + [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM @@ -48,4 +50,4 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/chocolatey.tests/infrastructure.app/attributes/CommandForAttributeSpecs.cs b/src/chocolatey.tests/infrastructure.app/attributes/CommandForAttributeSpecs.cs index 27f8d5fc38..03fd4065da 100644 --- a/src/chocolatey.tests/infrastructure.app/attributes/CommandForAttributeSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/attributes/CommandForAttributeSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,9 +16,8 @@ namespace chocolatey.tests.infrastructure.app.attributes { - using Should; using chocolatey.infrastructure.app.attributes; - using chocolatey.infrastructure.app.domain; + using Should; public class CommandForAttributeSpecs { @@ -32,7 +32,7 @@ public class when_CommandForAttribute_is_set_with_string : CommandForAttributeSp public override void Context() { - attribute = new CommandForAttribute("bob",""); + attribute = new CommandForAttribute("bob", ""); } public override void Because() @@ -47,4 +47,4 @@ public void should_be_set_to_the_string() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyApiKeyCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyApiKeyCommandSpecs.cs index df67389c0f..f27b805c09 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyApiKeyCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyApiKeyCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,13 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyApiKeyCommandSpecs { @@ -48,15 +48,15 @@ public class when_implementing_command_for : ChocolateyApiKeyCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] public void should_implement_apikey() { results.ShouldContain("apikey"); - } - + } + [Fact] public void should_implement_setapikey() { @@ -212,4 +212,4 @@ public void should_call_service_set_api_key() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs index 8ba1b0df08..b79cc159f7 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyConfigCommandSpecs { diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyFeatureCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyFeatureCommandSpecs.cs index 4d404b18cd..e62b83debc 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyFeatureCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyFeatureCommandSpecs.cs @@ -1,16 +1,32 @@ -namespace chocolatey.tests.infrastructure.app.commands +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.tests.infrastructure.app.commands { using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyFeatureCommandSpecs { @@ -33,20 +49,20 @@ public class when_implementing_command_for : ChocolateyFeatureCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] public void should_implement_feature() { results.ShouldContain("feature"); - } - + } + [Fact] public void should_implement_features() { results.ShouldContain("features"); - } + } } public class when_configurating_the_argument_parser : ChocolateyFeatureCommandSpecsBase @@ -128,7 +144,7 @@ public void should_throw_when_more_than_one_unparsed_arg_is_passed() error.ShouldBeType(); error.Message.ShouldContain("A single features command must be listed"); } - + [Fact] public void should_accept_enable_as_the_subcommand() { @@ -212,7 +228,6 @@ public void should_throw_when_command_is_not_list_and_name_is_not_set() error.Message.ShouldEqual("When specifying the subcommand '{0}', you must also specify --name.".format_with(configuration.FeatureCommand.Command.to_string())); } - [Fact] public void should_continue_when_command_is_list_and_name_is_not_set() { @@ -260,7 +275,7 @@ public void should_call_service_source_list_when_command_is_list() because(); configSettingsService.Verify(c => c.feature_list(configuration), Times.Once); } - + [Fact] public void should_call_service_source_disable_when_command_is_disable() { @@ -278,4 +293,4 @@ public void should_call_service_source_enable_when_command_is_enable() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs index dc2a8118df..6858428668 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInfoCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -136,7 +137,7 @@ public void should_add_short_version_of_password_to_the_option_set() public class when_handling_additional_argument_parsing : ChocolateyInfoCommandSpecsBase { private readonly IList unparsedArgs = new List(); - private string source = "https://somewhereoutthere"; + private readonly string source = "https://somewhereoutthere"; private Action because; public override void Context() @@ -173,8 +174,8 @@ public void should_set_exact_to_true() configuration.ListCommand.Exact = false; because(); configuration.ListCommand.Exact.ShouldBeTrue(); - } - + } + [Fact] public void should_set_verbose_to_true() { diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs index f43a002320..9212b426b3 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyInstallCommandSpecs { @@ -48,7 +49,7 @@ public class when_implementing_command_for : ChocolateyInstallCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -89,8 +90,8 @@ public void should_add_short_version_of_source_to_the_option_set() public void should_add_version_to_the_option_set() { optionSet.Contains("version").ShouldBeTrue(); - } - + } + [Fact] public void should_allow_insensitive_case_Version_to_the_option_set() { @@ -234,7 +235,6 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } - } public class when_handling_additional_argument_parsing : ChocolateyInstallCommandSpecsBase @@ -324,4 +324,4 @@ public void should_call_service_install_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs index 130663b863..3eb703b571 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,15 +19,13 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; - using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyListCommandSpecs { @@ -49,7 +48,7 @@ public class when_implementing_command_for : ChocolateyListCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -139,7 +138,7 @@ public void should_add_short_version_of_allversions_to_the_option_set() { optionSet.Contains("a").ShouldBeTrue(); } - + [Fact] public void should_add_user_to_the_option_set() { @@ -163,13 +162,12 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } - } public class when_handling_additional_argument_parsing : ChocolateyListCommandSpecsBase { private readonly IList unparsedArgs = new List(); - private string source = "https://somewhereoutthere"; + private readonly string source = "https://somewhereoutthere"; private Action because; public override void Context() @@ -229,4 +227,4 @@ public void should_call_service_list_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs index 32c83712a7..758f26217a 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyNewCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.app.templates; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyNewCommandSpecs { @@ -47,7 +48,7 @@ public class when_implementing_command_for : ChocolateyNewCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -359,7 +360,7 @@ public void should_call_service_generate() templateService.Verify(c => c.generate(configuration), Times.Once); } } - + public class when_handling_arguments_parsing : ChocolateyNewCommandSpecsBase { private OptionSet optionSet; @@ -373,7 +374,7 @@ public override void Context() public override void Because() { - optionSet.Parse(new[] { "--name", "Bob", "--automaticpackage", "--template-name", "custom", "--version", "0.42.0", "--maintainer" , "Loyd", "--outputdirectory", "c:\\packages" }); + optionSet.Parse(new[] { "--name", "Bob", "--automaticpackage", "--template-name", "custom", "--version", "0.42.0", "--maintainer", "Loyd", "--outputdirectory", "c:\\packages" }); } [Fact] @@ -414,4 +415,4 @@ public void should_outputdirectory_equal_packages() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs index 59dd99d5f4..1fbe292456 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,17 +16,15 @@ namespace chocolatey.tests.infrastructure.app.commands { - using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyOutdatedCommandSpecs { @@ -48,7 +47,7 @@ public class when_implementing_command_for : ChocolateyOutdatedCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -84,7 +83,7 @@ public void should_add_short_version_of_source_to_the_option_set() { optionSet.Contains("s").ShouldBeTrue(); } - + [Fact] public void should_add_user_to_the_option_set() { @@ -108,9 +107,8 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } - } - + public class when_noop_is_called : ChocolateyOutdatedCommandSpecsBase { public override void Because() @@ -139,4 +137,4 @@ public void should_call_service_oudated_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs index 259cc0d4b0..8d188b943c 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPackCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,14 +18,13 @@ namespace chocolatey.tests.infrastructure.app.commands { using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyPackCommandSpecs { @@ -46,7 +46,7 @@ public class when_implementing_command_for : ChocolateyPackCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -164,4 +164,4 @@ public void should_outputdirectory_equal_packages() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs index 1e40c0e4a1..79e6a95c33 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPinCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,12 +17,8 @@ namespace chocolatey.tests.infrastructure.app.commands { using System; - using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; - using Moq; - using NuGet; - using Should; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; @@ -29,8 +26,10 @@ namespace chocolatey.tests.infrastructure.app.commands using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; - using chocolatey.infrastructure.logging; using chocolatey.infrastructure.results; + using Moq; + using NuGet; + using Should; public class ChocolateyPinCommandSpecs { @@ -46,19 +45,27 @@ public abstract class ChocolateyPinCommandSpecsBase : TinySpec public override void Context() { - // MockLogger = new MockLogger(); - // Log.InitializeWith(MockLogger); + // MockLogger = new MockLogger(); + // Log.InitializeWith(MockLogger); configuration.Sources = "https://localhost/somewhere/out/there"; command = new ChocolateyPinCommand(packageInfoService.Object, nugetLogger.Object, nugetService.Object); package = new Mock(); package.Setup(p => p.Id).Returns("regular"); package.Setup(p => p.Version).Returns(new SemanticVersion("1.2.0")); - packageInfoService.Setup(s => s.get_package_information(package.Object)).Returns(new ChocolateyPackageInformation(package.Object) { IsPinned = false }); + packageInfoService.Setup(s => s.get_package_information(package.Object)).Returns( + new ChocolateyPackageInformation(package.Object) + { + IsPinned = false + }); pinnedPackage = new Mock(); pinnedPackage.Setup(p => p.Id).Returns("pinned"); pinnedPackage.Setup(p => p.Version).Returns(new SemanticVersion("1.1.0")); - packageInfoService.Setup(s => s.get_package_information(pinnedPackage.Object)).Returns(new ChocolateyPackageInformation(pinnedPackage.Object) { IsPinned = true }); + packageInfoService.Setup(s => s.get_package_information(pinnedPackage.Object)).Returns( + new ChocolateyPackageInformation(pinnedPackage.Object) + { + IsPinned = true + }); } public void reset() @@ -337,7 +344,7 @@ public override void Context() configuration.Sources = ApplicationParameters.PackagesLocation; configuration.ListCommand.LocalOnly = true; configuration.AllVersions = true; - var packageResults = new [] + var packageResults = new[] { new PackageResult(package.Object, null), new PackageResult(pinnedPackage.Object, null) @@ -416,7 +423,7 @@ public void should_call_nuget_service_list_run_when_command_is_list() nugetService.Verify(n => n.list_run(It.IsAny()), Times.Once); } - + [Pending("NuGet is killing me with extension methods. Need to find proper item to mock out to return the package object.")] [Fact] public void should_set_pin_when_command_is_add() @@ -450,4 +457,4 @@ public void should_remove_pin_when_command_is_remove() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs index 5b11ae953d..ffe5bafb08 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,15 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyPushCommandSpecs { @@ -50,7 +50,7 @@ public class when_implementing_command_for : ChocolateyPushCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -105,7 +105,7 @@ public void should_add_short_version_of_apikey_to_the_option_set() { optionSet.Contains("k").ShouldBeTrue(); } - + [Fact] public void should_add_short_version_of_timeout_to_the_option_set() { @@ -148,7 +148,7 @@ public void should_set_the_source_to_default_feed_if_not_set_explicitly() because(); configuration.Sources.ShouldEqual(ApplicationParameters.ChocolateyCommunityFeedPushSource); - } + } [Fact] public void should_not_set_the_apiKey_if_source_is_not_found() @@ -342,4 +342,4 @@ public void should_call_service_push_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs index 7879183bad..4953444e69 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateySourceCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateySourceCommandSpecs { @@ -48,15 +49,15 @@ public class when_implementing_command_for : ChocolateySourceCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] public void should_implement_source() { results.ShouldContain("source"); - } - + } + [Fact] public void should_implement_sources() { @@ -299,7 +300,6 @@ public void should_throw_when_command_is_not_list_and_name_is_not_set() error.Message.ShouldEqual("When specifying the subcommand '{0}', you must also specify --name.".format_with(configuration.SourceCommand.Command.to_string())); } - [Fact] public void should_continue_when_command_is_list_and_name_is_not_set() { @@ -355,7 +355,7 @@ public void should_call_service_source_add_when_command_is_add() because(); configSettingsService.Verify(c => c.source_add(configuration), Times.Once); } - + [Fact] public void should_call_service_source_remove_when_command_is_remove() { @@ -399,4 +399,4 @@ public void should_call_service_source_list_when_command_is_list() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs index 3ebd5cce59..f260f54f4d 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUninstallCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyUninstallCommandSpecs { @@ -48,7 +49,7 @@ public class when_implementing_command_for : ChocolateyUninstallCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -257,4 +258,4 @@ public void should_call_service_uninstall_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs index ab49cdaf5a..2871a6b9ae 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUnpackSelfCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,13 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; - using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.filesystem; + using Moq; + using Should; public class ChocolateyUnpackSelfCommandSpecs { @@ -49,7 +49,7 @@ public class when_implementing_command_for : ChocolateyUnpackSelfCommandSpecsBas public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -99,4 +99,4 @@ public void should_call_assembly_file_extractor() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs index fad894dd9f..ab64f6b0b4 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,14 +19,14 @@ namespace chocolatey.tests.infrastructure.app.commands using System; using System.Collections.Generic; using System.Linq; - using Moq; - using Should; using chocolatey.infrastructure.app.attributes; using chocolatey.infrastructure.app.commands; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ChocolateyUpgradeCommandSpecs { @@ -48,7 +49,7 @@ public class when_implementing_command_for : ChocolateyUpgradeCommandSpecsBase public override void Because() { - results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); + results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList(); } [Fact] @@ -216,7 +217,6 @@ public void should_add_short_version_of_password_to_the_option_set() { optionSet.Contains("p").ShouldBeTrue(); } - } public class when_handling_additional_argument_parsing : ChocolateyUpgradeCommandSpecsBase @@ -306,4 +306,4 @@ public void should_call_service_upgrade_run() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs index 336ba562a7..431ca6a09d 100644 --- a/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs +++ b/src/chocolatey.tests/infrastructure.app/configuration/ConfigurationOptionsSpec.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,11 +21,11 @@ namespace chocolatey.tests.infrastructure.app.configuration using System.IO; using System.Linq; using System.Text; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class ConfigurationOptionsSpec { @@ -75,11 +76,11 @@ public class when_ConfigurationOptions_parses_arguments_and_updates_configuratio public void should_set_help_options_by_default() { setOptions = set => - { - set.Contains("h").ShouldBeTrue(); - set.Contains("help").ShouldBeTrue(); - set.Contains("?").ShouldBeTrue(); - }; + { + set.Contains("h").ShouldBeTrue(); + set.Contains("help").ShouldBeTrue(); + set.Contains("?").ShouldBeTrue(); + }; because(); } @@ -114,10 +115,7 @@ public void should_have_a_helpMessage_with_contents_when_help_is_requested() public void should_not_run_validate_configuration_when_help_is_requested() { args.Add("-h"); - validateConfiguration = () => - { - "should".ShouldEqual("not be reached"); - }; + validateConfiguration = () => { "should".ShouldEqual("not be reached"); }; because(); } @@ -126,10 +124,7 @@ public void should_not_run_validate_configuration_when_help_is_requested() public void should_run_validate_configuration_unless_help_is_requested() { var wasCalled = false; - validateConfiguration = () => - { - wasCalled = true; - }; + validateConfiguration = () => { wasCalled = true; }; because(); @@ -141,10 +136,10 @@ public void should_give_an_empty_unparsed_args_to_after_parse() { var wasCalled = false; afterParse = list => - { - wasCalled = true; - list.ShouldBeEmpty(); - }; + { + wasCalled = true; + list.ShouldBeEmpty(); + }; because(); @@ -157,10 +152,10 @@ public void should_give_an_empty_unparsed_args_to_after_parse_when_all_specified args.Add("-h"); var wasCalled = false; afterParse = list => - { - wasCalled = true; - list.ShouldBeEmpty(); - }; + { + wasCalled = true; + list.ShouldBeEmpty(); + }; because(); @@ -173,10 +168,10 @@ public void should_give_unparsed_args_to_after_parse_when_not_picked_up_by_an_op args.Add("--what-is=this"); var wasCalled = false; afterParse = list => - { - wasCalled = true; - list.ShouldContain(args.First()); - }; + { + wasCalled = true; + list.ShouldContain(args.First()); + }; because(); @@ -189,10 +184,10 @@ public void should_find_command_name_in_unparsed_args_if_not_set_otherwise() args.Add("dude"); var wasCalled = false; afterParse = list => - { - wasCalled = true; - list.ShouldContain(args.First()); - }; + { + wasCalled = true; + list.ShouldContain(args.First()); + }; because(); @@ -206,10 +201,10 @@ public void should_set_help_requested_if_command_name_is_starts_with_a_prefix() args.Add("/dude"); var wasCalled = false; afterParse = list => - { - wasCalled = true; - list.ShouldContain(args.First()); - }; + { + wasCalled = true; + list.ShouldContain(args.First()); + }; because(); @@ -263,11 +258,11 @@ public void should_set_option_for_gena_to_true_when_specified_with_forward_slash public void should_set_option_when_specified_as_single_dash_for_timmy_and_other_option_short_values_are_passed_the_same_way() { setOptions = set => - { - set.Add("timmy", "sets the timmy switch", option => config.Verbose = option != null); - set.Add("s|skip", "sets the skip switch", option => config.SkipPackageInstallProvider = option != null); - set.Add("d|debug", "sets the debug switch", option => config.Debug = option != null); - }; + { + set.Add("timmy", "sets the timmy switch", option => config.Verbose = option != null); + set.Add("s|skip", "sets the skip switch", option => config.SkipPackageInstallProvider = option != null); + set.Add("d|debug", "sets the debug switch", option => config.Debug = option != null); + }; args.Add("-timmy"); args.Add("-sd"); @@ -282,11 +277,11 @@ public void should_set_option_when_specified_as_single_dash_for_timmy_and_other_ public void should_set_option_when_specified_as_single_dash_for_lo_and_other_option_short_values_are_passed_the_same_way() { setOptions = set => - { - set.Add("lo|local-only", "sets the lo switch", option => config.ListCommand.LocalOnly = option != null); - set.Add("l|lskip", "sets the skip switch", option => config.SkipPackageInstallProvider = option != null); - set.Add("m|mdebug", "sets the debug switch", option => config.Debug = option != null); - }; + { + set.Add("lo|local-only", "sets the lo switch", option => config.ListCommand.LocalOnly = option != null); + set.Add("l|lskip", "sets the skip switch", option => config.SkipPackageInstallProvider = option != null); + set.Add("m|mdebug", "sets the debug switch", option => config.Debug = option != null); + }; args.Add("-lo"); args.Add("-ml"); @@ -301,10 +296,7 @@ public void should_set_option_when_specified_as_single_dash_for_lo_and_other_opt [Fact] public void should_show_help_menu_when_passing_bundled_options_that_do_not_exist() { - setOptions = set => - { - set.Add("w|wdebug", "sets the debug switch", option => config.Debug = option != null); - }; + setOptions = set => { set.Add("w|wdebug", "sets the debug switch", option => config.Debug = option != null); }; args.Add("-wz"); because(); @@ -334,4 +326,4 @@ public void should_not_parse_unknown_option() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs index 35fd0810a1..3efb1ec0a3 100644 --- a/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/AutomaticUninstallerServiceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,16 +21,16 @@ namespace chocolatey.tests.infrastructure.app.services using System.Collections.Generic; using System.Diagnostics; using System.Linq; - using chocolatey.infrastructure.app.domain.installers; - using Moq; - using NuGet; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; + using chocolatey.infrastructure.app.domain.installers; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.commands; using chocolatey.infrastructure.results; + using Moq; + using NuGet; using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; public class AutomaticUninstallerServiceSpecs @@ -65,7 +66,8 @@ public override void Context() package.Setup(p => p.Version).Returns(new SemanticVersion("1.2.0")); packageResult = new PackageResult(package.Object, null); packageInformation = new ChocolateyPackageInformation(package.Object); - registryKeys.Add(new RegistryApplicationKey + registryKeys.Add( + new RegistryApplicationKey { InstallLocation = @"C:\Program Files (x86)\WinDirStat", UninstallString = originalUninstallString, @@ -115,7 +117,9 @@ public void should_not_get_package_information() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -141,7 +145,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -167,7 +173,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -195,7 +203,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -206,7 +216,8 @@ public override void Context() base.Context(); fileSystem.ResetCalls(); registryKeys.Clear(); - registryKeys.Add(new RegistryApplicationKey + registryKeys.Add( + new RegistryApplicationKey { InstallLocation = string.Empty, UninstallString = originalUninstallString, @@ -232,7 +243,9 @@ public void should_call_get_package_information() public void should_call_command_executor() { var args = installerType.build_uninstall_command_arguments().trim_safe(); - commandExecutor.Verify(c => c.execute(expectedUninstallString, args, It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Once); + commandExecutor.Verify( + c => c.execute(expectedUninstallString, args, It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Once); } } @@ -259,7 +272,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -289,7 +304,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -312,16 +329,18 @@ public override void Because() [Fact] public void should_log_why_it_skips_auto_uninstaller() { - MockLogger.Verify(l => l.Info(" Skipping auto uninstaller - The uninstaller file no longer exists. \"" + expectedUninstallString +"\""), Times.Once); + MockLogger.Verify(l => l.Info(" Skipping auto uninstaller - The uninstaller file no longer exists. \"" + expectedUninstallString + "\""), Times.Once); } [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } - } - + } + public class when_AutomaticUninstallerService_is_run_normally : AutomaticUninstallerServiceSpecsBase { public override void Because() @@ -338,19 +357,29 @@ public void should_call_get_package_information() [Fact] public void should_call_command_executor() { - commandExecutor.Verify(c => c.execute(expectedUninstallString, installerType.build_uninstall_command_arguments().trim_safe(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Once); + commandExecutor.Verify( + c => + c.execute( + expectedUninstallString, + installerType.build_uninstall_command_arguments().trim_safe(), + It.IsAny(), + It.IsAny>(), + It.IsAny>(), + It.IsAny()), + Times.Once); } } public class when_uninstall_string_is_split_by_quotes : AutomaticUninstallerServiceSpecsBase { - private string uninstallStringWithQuoteSeparation = @"""C:\Program Files (x86)\WinDirStat\Uninstall.exe"" ""WinDir Stat"""; - + private readonly string uninstallStringWithQuoteSeparation = @"""C:\Program Files (x86)\WinDirStat\Uninstall.exe"" ""WinDir Stat"""; + public override void Context() { base.Context(); registryKeys.Clear(); - registryKeys.Add(new RegistryApplicationKey + registryKeys.Add( + new RegistryApplicationKey { InstallLocation = @"C:\Program Files (x86)\WinDirStat", UninstallString = uninstallStringWithQuoteSeparation, @@ -375,7 +404,16 @@ public void should_call_get_package_information() [Fact] public void should_call_command_executor() { - commandExecutor.Verify(c => c.execute(expectedUninstallString, "\"WinDir Stat\"".trim_safe(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Once); + commandExecutor.Verify( + c => + c.execute( + expectedUninstallString, + "\"WinDir Stat\"".trim_safe(), + It.IsAny(), + It.IsAny>(), + It.IsAny>(), + It.IsAny()), + Times.Once); } } @@ -386,7 +424,8 @@ public override void Context() base.Context(); registryKeys.Clear(); commandExecutor.ResetCalls(); - registryKeys.Add(new RegistryApplicationKey + registryKeys.Add( + new RegistryApplicationKey { InstallLocation = @"C:\Program Files (x86)\WinDirStat", UninstallString = "{0} {1}".format_with(originalUninstallString, "/bob"), @@ -414,7 +453,9 @@ public void should_log_why_it_skips_auto_uninstaller() [Fact] public void should_not_call_command_executor() { - commandExecutor.Verify(c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Never); + commandExecutor.Verify( + c => c.execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), + Times.Never); } } @@ -439,7 +480,8 @@ public void reset() private void test_installertype(IInstaller installer, bool hasQuietUninstallString) { reset(); - registryKeys.Add(new RegistryApplicationKey + registryKeys.Add( + new RegistryApplicationKey { InstallLocation = @"C:\Program Files (x86)\WinDirStat", UninstallString = "{0} {1}".format_with(originalUninstallString, registryUninstallArgs), @@ -456,7 +498,16 @@ private void test_installertype(IInstaller installer, bool hasQuietUninstallStri var uninstallArgs = !hasQuietUninstallString ? registryUninstallArgs.trim_safe() + " " + installerTypeArgs : registryUninstallArgs.trim_safe(); - commandExecutor.Verify(c => c.execute(expectedUninstallString, uninstallArgs.trim_safe(), It.IsAny(), It.IsAny>(), It.IsAny>(), It.IsAny()), Times.Once); + commandExecutor.Verify( + c => + c.execute( + expectedUninstallString, + uninstallArgs.trim_safe(), + It.IsAny(), + It.IsAny>(), + It.IsAny>(), + It.IsAny()), + Times.Once); } //[Fact] @@ -520,4 +571,4 @@ public void should_use_registry_uninstall_args_when_installtype_is_nsis_and_has_ } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs index 5f4b471d9b..024e25375b 100644 --- a/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/FilesServiceSpecs.cs @@ -1,10 +1,24 @@ -namespace chocolatey.tests.infrastructure.app.services +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.tests.infrastructure.app.services { using System; using System.Collections.Generic; using System.IO; - using Moq; - using Should; using chocolatey.infrastructure.app; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; @@ -13,6 +27,8 @@ using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.results; using chocolatey.infrastructure.services; + using Moq; + using Should; public class FilesServiceSpecs { @@ -22,13 +38,13 @@ public abstract class FilesServiceSpecsBase : TinySpec protected Mock XmlService = new Mock(); protected Mock FileSystem = new Mock(); protected Mock HashProvider = new Mock(); - + public override void Context() { XmlService.ResetCalls(); FileSystem.ResetCalls(); HashProvider.ResetCalls(); - Service = new FilesService(XmlService.Object,FileSystem.Object,HashProvider.Object); + Service = new FilesService(XmlService.Object, FileSystem.Object, HashProvider.Object); } } @@ -59,18 +75,18 @@ public void should_not_deserialize_if_file_does_not_exist() because(); - XmlService.Verify(x => x.deserialize(It.IsAny()),Times.Never); + XmlService.Verify(x => x.deserialize(It.IsAny()), Times.Never); } - } - + } + public class when_FilesService_saves_files : FilesServiceSpecsBase { private Action because; private PackageFiles files; - + public override void Because() { - because = () => Service.save_to_file(files , "fake path"); + because = () => Service.save_to_file(files, "fake path"); } [Fact] @@ -78,7 +94,7 @@ public void should_save_if_the_snapshot_is_not_null() { Context(); files = new PackageFiles(); - + because(); XmlService.Verify(x => x.serialize(files, It.IsAny()), Times.Once()); @@ -112,13 +128,13 @@ public override void Because() { result = Service.capture_package_files(packageResult, config); } - + [Fact] public void should_not_call_get_files() { FileSystem.Verify(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories), Times.Never); } - + [Fact] public void should_return_a_warning_if_the_install_directory_matches_choco_install_location() { @@ -130,7 +146,7 @@ public void should_return_null() { result.ShouldBeNull(); } - } + } public class when_FilesService_captures_files_and_install_directory_reports_packages_location : FilesServiceSpecsBase { @@ -148,13 +164,13 @@ public override void Because() { result = Service.capture_package_files(packageResult, config); } - + [Fact] public void should_not_call_get_files() { FileSystem.Verify(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories), Times.Never); } - + [Fact] public void should_return_a_warning_if_the_install_directory_matches_choco_install_location() { @@ -166,8 +182,8 @@ public void should_return_null() { result.ShouldBeNull(); } - } - + } + public class when_FilesService_captures_files_and_package_result_is_null : FilesServiceSpecsBase { private PackageFiles result; @@ -184,7 +200,7 @@ public override void Because() { result = Service.capture_package_files(packageResult, config); } - + [Fact] public void should_not_call_get_files() { @@ -195,28 +211,32 @@ public void should_not_call_get_files() public void should_return_a_non_null_object() { result.ShouldNotBeNull(); - } - + } + [Fact] public void should_return_empty_package_files() { result.Files.ShouldBeEmpty(); } - } - + } + public class when_FilesService_captures_files_happy_path : FilesServiceSpecsBase { private PackageFiles result; private PackageResult packageResult; private readonly ChocolateyConfiguration config = new ChocolateyConfiguration(); private readonly string installDirectory = ApplicationParameters.PackagesLocation + "\\bob"; - private readonly IList files = new List { "file1", "file2" }; + private readonly IList files = new List + { + "file1", + "file2" + }; public override void Context() { base.Context(); packageResult = new PackageResult("bob", "1.2.3", installDirectory); - + FileSystem.Setup(x => x.get_files(ApplicationParameters.PackagesLocation + "\\bob", It.IsAny(), SearchOption.AllDirectories)).Returns(files); HashProvider.Setup(x => x.hash_file(It.IsAny())).Returns("yes"); } @@ -225,19 +245,19 @@ public override void Because() { result = Service.capture_package_files(packageResult, config); } - + [Fact] public void should_return_a_PackageFiles_object() { result.ShouldNotBeNull(); - } - + } + [Fact] public void should_contain_package_files() { result.Files.ShouldNotBeEmpty(); - } - + } + [Fact] public void should_contain_the_correct_number_of_package_files() { @@ -247,8 +267,8 @@ public void should_contain_the_correct_number_of_package_files() [Fact] public void should_call_hash_provider_for_each_file() { - HashProvider.Verify(x => x.hash_file(It.IsAny()),Times.Exactly(files.Count)); + HashProvider.Verify(x => x.hash_file(It.IsAny()), Times.Exactly(files.Count)); } - } + } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs index 41a783c51b..4d8e20b933 100644 --- a/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/NugetServiceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,13 +20,13 @@ namespace chocolatey.tests.infrastructure.app.services using System.Collections.Generic; using System.IO; using System.Linq; - using Moq; - using NuGet; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; - using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; + using Moq; + using NuGet; using Should; + using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; public class NugetServiceSpecs { @@ -79,42 +80,63 @@ public void should_ignore_an_unchanged_file() { Context(); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; packageFiles.Files.Add(packageFile); packageInfo.FilesSnapshot = packageFiles; - var fileSystemFiles = new List() { filePath }; + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); - filesService.Setup(x => x.capture_package_files(It.IsAny(),config)).Returns(packageFiles); + filesService.Setup(x => x.capture_package_files(It.IsAny(), config)).Returns(packageFiles); because(); - fileSystem.Verify(x => x.copy_file(It.IsAny(),It.IsAny(),It.IsAny()),Times.Never); - } - + fileSystem.Verify(x => x.copy_file(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + [Fact] public void should_backup_a_changed_file() { Context(); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; packageFiles.Files.Add(packageFile); packageInfo.FilesSnapshot = packageFiles; - var packageFileWithUpdatedChecksum = new PackageFile { Path = filePath, Checksum = "4321" }; + var packageFileWithUpdatedChecksum = new PackageFile + { + Path = filePath, + Checksum = "4321" + }; - var fileSystemFiles = new List() { filePath }; + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); var updatedPackageFiles = new PackageFiles(); - updatedPackageFiles.Files = new List{packageFileWithUpdatedChecksum}; + updatedPackageFiles.Files = new List + { + packageFileWithUpdatedChecksum + }; filesService.Setup(x => x.capture_package_files(It.IsAny(), config)).Returns(updatedPackageFiles); because(); fileSystem.Verify(x => x.copy_file(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); - } - } - + } + } + public class when_NugetService_removes_installation_files_on_uninstall : NugetServiceSpecsBase { private Action because; @@ -144,70 +166,105 @@ public void should_do_nothing_if_the_directory_no_longer_exists() fileSystem.ResetCalls(); fileSystem.Setup(x => x.directory_exists(It.IsAny())).Returns(false); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); - var fileSystemFiles = new List() { filePath }; + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny())).Returns(packageFile); because(); filesService.Verify(x => x.get_package_file(It.IsAny()), Times.Never); - fileSystem.Verify(x => x.delete_file(filePath),Times.Never); - } - + fileSystem.Verify(x => x.delete_file(filePath), Times.Never); + } + [Fact] public void should_remove_an_unchanged_file() { Context(); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); - var fileSystemFiles = new List() { filePath }; + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny())).Returns(packageFile); because(); fileSystem.Verify(x => x.delete_file(filePath)); - } - + } + [Fact] public void should_not_delete_a_changed_file() { Context(); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; - var packageFileWithUpdatedChecksum = new PackageFile { Path = filePath, Checksum = "4321" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; + var packageFileWithUpdatedChecksum = new PackageFile + { + Path = filePath, + Checksum = "4321" + }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); - var fileSystemFiles = new List() { filePath }; + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); filesService.Setup(x => x.get_package_file(It.IsAny())).Returns(packageFileWithUpdatedChecksum); because(); - fileSystem.Verify(x => x.delete_file(filePath),Times.Never); - } - + fileSystem.Verify(x => x.delete_file(filePath), Times.Never); + } + [Fact] public void should_not_delete_an_unfound_file() { Context(); - var packageFile = new PackageFile { Path = filePath, Checksum = "1234" }; - var packageFileNotInOriginal = new PackageFile { Path ="c:\\files", Checksum = "4321" }; + var packageFile = new PackageFile + { + Path = filePath, + Checksum = "1234" + }; + var packageFileNotInOriginal = new PackageFile + { + Path = "c:\\files", + Checksum = "4321" + }; packageFiles.Add(packageFile); packageInfo.FilesSnapshot.Files = packageFiles.ToList(); - var fileSystemFiles = new List() { filePath }; - + var fileSystemFiles = new List() + { + filePath + }; fileSystem.Setup(x => x.get_files(It.IsAny(), It.IsAny(), SearchOption.AllDirectories)).Returns(fileSystemFiles); @@ -215,7 +272,7 @@ public void should_not_delete_an_unfound_file() because(); - fileSystem.Verify(x => x.delete_file(filePath),Times.Never); + fileSystem.Verify(x => x.delete_file(filePath), Times.Never); } } @@ -267,4 +324,4 @@ public void generated_package_should_be_in_specified_directory() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/services/RegistryServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/RegistryServiceSpecs.cs index 66c0e7b36f..eca3667459 100644 --- a/src/chocolatey.tests/infrastructure.app/services/RegistryServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/RegistryServiceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,13 +16,12 @@ namespace chocolatey.tests.infrastructure.app.services { - using System; - using Microsoft.Win32; - using Moq; - using Should; using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.services; + using Microsoft.Win32; + using Moq; + using Should; using Registry = chocolatey.infrastructure.app.domain.Registry; public class RegistryServiceSpecs @@ -61,21 +61,19 @@ public override void Because() _result = Service.get_installer_keys(); } - [Fact] public void should_not_be_null() { _result.ShouldNotBeNull(); } - } [WindowsOnly] public class when_RegistryService_get_key_is_called_for_a_value_that_exists : RegistryServiceSpecsBase { private RegistryKey _result; - private RegistryHive _hive = RegistryHive.CurrentUser; - private string _subkeyPath = "Software"; + private readonly RegistryHive _hive = RegistryHive.CurrentUser; + private readonly string _subkeyPath = "Software"; public override void Context() { @@ -90,13 +88,13 @@ public override void Because() [Fact] public void should_return_a_non_null_value() { - _result.ShouldNotBeNull(); - } - + _result.ShouldNotBeNull(); + } + [Fact] public void should_return_a_value_of_type_RegistryKey() { - _result.ShouldBeType(); + _result.ShouldBeType(); } [Fact] @@ -104,20 +102,20 @@ public void should_contain_keys() { _result.GetSubKeyNames().ShouldNotBeEmpty(); } - + [Fact] public void should_contain_values() { Service.get_key(_hive, "Environment").GetValueNames().ShouldNotBeEmpty(); } - } - + } + [WindowsOnly] public class when_RegistryService_get_key_is_called_for_a_value_that_does_not_exist : RegistryServiceSpecsBase { private RegistryKey _result; - private RegistryHive _hive = RegistryHive.CurrentUser; - private string _subkeyPath = "Software\\alsdjfalskjfaasdfasdf"; + private readonly RegistryHive _hive = RegistryHive.CurrentUser; + private readonly string _subkeyPath = "Software\\alsdjfalskjfaasdfasdf"; public override void Context() { @@ -144,4 +142,4 @@ public void should_return_null_key() //todo a subkey that exists only in 32 bit mode (must create it to test it though) } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs b/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs index 936f754a9c..3163654aba 100644 --- a/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/services/TemplateServiceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,21 +14,19 @@ // See the License for the specific language governing permissions and // limitations under the License. - namespace chocolatey.tests.infrastructure.app.services { - using System; - using System.Collections; + using System; using System.Collections.Generic; using System.IO; using System.Linq; - using Moq; + using System.Text; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.services; - using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; - using Should; using chocolatey.infrastructure.app.templates; - using System.Text; + using chocolatey.infrastructure.filesystem; + using Moq; + using Should; public class TemplateServiceSpecs { @@ -96,7 +95,7 @@ public class when_generate_file_from_template_is_called : TemplateServiceSpecsBa private Action because; private readonly ChocolateyConfiguration config = new ChocolateyConfiguration(); private readonly TemplateValues templateValues = new TemplateValues(); - private string template = "[[PackageName]]"; + private readonly string template = "[[PackageName]]"; private const string fileLocation = "c:\\packages\\bob.nuspec"; private string fileContent; @@ -107,7 +106,6 @@ public override void Context() fileSystem.Setup(x => x.write_file(It.Is((string fl) => fl == fileLocation), It.IsAny(), Encoding.UTF8)) .Callback((string filePath, string fileContent, Encoding encoding) => this.fileContent = fileContent); - templateValues.PackageName = "Bob"; } @@ -160,8 +158,13 @@ public override void Context() fileSystem.Setup(x => x.get_current_directory()).Returns("c:\\chocolatey"); fileSystem.Setup(x => x.combine_paths(It.IsAny(), It.IsAny())) - .Returns((string a, string[] b) => { return a + "\\" + b[0]; }); - fileSystem.Setup(x => x.directory_exists(It.IsAny())).Returns(x => { verifiedDirectoryPath = x; return true; }); + .Returns((string a, string[] b) => { return a + "\\" + b[0]; }); + fileSystem.Setup(x => x.directory_exists(It.IsAny())).Returns( + x => + { + verifiedDirectoryPath = x; + return true; + }); config.NewCommand.Name = "Bob"; } @@ -225,8 +228,8 @@ public class when_generate_is_called : TemplateServiceSpecsBase { private Action because; private readonly ChocolateyConfiguration config = new ChocolateyConfiguration(); - private List files = new List(); - private HashSet directoryCreated = new HashSet(StringComparer.InvariantCultureIgnoreCase); + private readonly List files = new List(); + private readonly HashSet directoryCreated = new HashSet(StringComparer.InvariantCultureIgnoreCase); public override void Context() { @@ -234,26 +237,28 @@ public override void Context() fileSystem.Setup(x => x.get_current_directory()).Returns("c:\\chocolatey"); fileSystem.Setup(x => x.combine_paths(It.IsAny(), It.IsAny())) - .Returns((string a, string[] b) => - { - if(a.EndsWith("templates") && b[0] == "default") - { - return "templates\\default"; - } - return a + "\\" + b[0]; - }); + .Returns( + (string a, string[] b) => + { + if (a.EndsWith("templates") && b[0] == "default") + { + return "templates\\default"; + } + return a + "\\" + b[0]; + }); fileSystem.Setup(x => x.directory_exists(It.IsAny())).Returns(dirPath => dirPath.EndsWith("templates\\default")); fileSystem.Setup(x => x.write_file(It.IsAny(), It.IsAny(), Encoding.UTF8)) .Callback((string filePath, string fileContent, Encoding encoding) => files.Add(filePath)); fileSystem.Setup(x => x.delete_directory_if_exists(It.IsAny(), true)); - fileSystem.Setup(x => x.create_directory_if_not_exists(It.IsAny())).Callback((string directory) => - { - if (!string.IsNullOrWhiteSpace(directory)) - { - directoryCreated.Add(directory); - } - }); - fileSystem.Setup(x => x.get_files(It.IsAny(), "*.*", SearchOption.AllDirectories)).Returns(new[] { "templates\\default\\template.nuspec", "templates\\default\\random.txt" }); + fileSystem.Setup(x => x.create_directory_if_not_exists(It.IsAny())).Callback( + (string directory) => + { + if (!string.IsNullOrWhiteSpace(directory)) + { + directoryCreated.Add(directory); + } + }); + fileSystem.Setup(x => x.get_files(It.IsAny(), "*.*", SearchOption.AllDirectories)).Returns(new[] { "templates\\default\\template.nuspec", "templates\\default\\random.txt" }); fileSystem.Setup(x => x.get_directory_name(It.IsAny())).Returns(file => Path.GetDirectoryName(file)); fileSystem.Setup(x => x.get_file_extension(It.IsAny())).Returns(file => Path.GetExtension(file)); fileSystem.Setup(x => x.read_file(It.IsAny())).Returns(string.Empty); @@ -276,11 +281,11 @@ public override void BeforeEachSpec() [Fact] public void should_generate_all_files_and_directories() { - because(); - - var directories = directoryCreated.ToList(); - directories.Count.ShouldEqual(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); - directories[0].ShouldEqual("c:\\chocolatey\\Bob"); + because(); + + var directories = directoryCreated.ToList(); + directories.Count.ShouldEqual(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); + directories[0].ShouldEqual("c:\\chocolatey\\Bob"); directories[1].ShouldEqual("c:\\chocolatey\\Bob\\tools"); files.Count.ShouldEqual(2, "There should be 2 files, but there was: " + string.Join(", ", files)); @@ -295,11 +300,11 @@ public void should_generate_all_files_and_directories_even_with_outputdirectory( { config.OutputDirectory = "c:\\packages"; - because(); - - var directories = directoryCreated.ToList(); - directories.Count.ShouldEqual(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); - directories[0].ShouldEqual("c:\\packages\\Bob"); + because(); + + var directories = directoryCreated.ToList(); + directories.Count.ShouldEqual(2, "There should be 2 directories, but there was: " + string.Join(", ", directories)); + directories[0].ShouldEqual("c:\\packages\\Bob"); directories[1].ShouldEqual("c:\\packages\\Bob\\tools"); files.Count.ShouldEqual(2, "There should be 2 files, but there was: " + string.Join(", ", files)); @@ -308,14 +313,14 @@ public void should_generate_all_files_and_directories_even_with_outputdirectory( MockLogger.MessagesFor(LogLevel.Info).Last().ShouldEqual(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine)); } - } - + } + public class when_generate_is_called_with_nested_folders : TemplateServiceSpecsBase { private Action because; private readonly ChocolateyConfiguration config = new ChocolateyConfiguration(); - private List files = new List(); - private HashSet directoryCreated = new HashSet(StringComparer.InvariantCultureIgnoreCase); + private readonly List files = new List(); + private readonly HashSet directoryCreated = new HashSet(StringComparer.InvariantCultureIgnoreCase); public override void Context() { @@ -323,32 +328,35 @@ public override void Context() fileSystem.Setup(x => x.get_current_directory()).Returns("c:\\chocolatey"); fileSystem.Setup(x => x.combine_paths(It.IsAny(), It.IsAny())) - .Returns((string a, string[] b) => - { - if (a.EndsWith("templates") && b[0] == "test") - { - return "templates\\test"; - } - return a + "\\" + b[0]; - }); + .Returns( + (string a, string[] b) => + { + if (a.EndsWith("templates") && b[0] == "test") + { + return "templates\\test"; + } + return a + "\\" + b[0]; + }); fileSystem.Setup(x => x.directory_exists(It.IsAny())).Returns(dirPath => dirPath.EndsWith("templates\\test")); fileSystem.Setup(x => x.write_file(It.IsAny(), It.IsAny(), Encoding.UTF8)) .Callback((string filePath, string fileContent, Encoding encoding) => files.Add(filePath)); - fileSystem.Setup(x => x.delete_directory_if_exists(It.IsAny(), true)); - fileSystem.Setup(x => x.get_files(It.IsAny(), "*.*", SearchOption.AllDirectories)).Returns(new[] { "templates\\test\\template.nuspec", "templates\\test\\random.txt", "templates\\test\\tools\\chocolateyInstall.ps1", "templates\\test\\tools\\lower\\another.ps1" }); - fileSystem.Setup(x => x.create_directory_if_not_exists(It.IsAny())).Callback((string directory) => - { - if (!string.IsNullOrWhiteSpace(directory)) - { - directoryCreated.Add(directory); - } - }); + fileSystem.Setup(x => x.delete_directory_if_exists(It.IsAny(), true)); + fileSystem.Setup(x => x.get_files(It.IsAny(), "*.*", SearchOption.AllDirectories)) + .Returns(new[] { "templates\\test\\template.nuspec", "templates\\test\\random.txt", "templates\\test\\tools\\chocolateyInstall.ps1", "templates\\test\\tools\\lower\\another.ps1" }); + fileSystem.Setup(x => x.create_directory_if_not_exists(It.IsAny())).Callback( + (string directory) => + { + if (!string.IsNullOrWhiteSpace(directory)) + { + directoryCreated.Add(directory); + } + }); fileSystem.Setup(x => x.get_directory_name(It.IsAny())).Returns(file => Path.GetDirectoryName(file)); fileSystem.Setup(x => x.get_file_extension(It.IsAny())).Returns(file => Path.GetExtension(file)); fileSystem.Setup(x => x.read_file(It.IsAny())).Returns(string.Empty); - config.NewCommand.Name = "Bob"; - config.NewCommand.TemplateName = "test"; + config.NewCommand.Name = "Bob"; + config.NewCommand.TemplateName = "test"; } public override void Because() @@ -367,11 +375,11 @@ public override void BeforeEachSpec() [WindowsOnly] public void should_generate_all_files_and_directories() { - because(); - - var directories = directoryCreated.ToList(); - directories.Count.ShouldEqual(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); - directories[0].ShouldEqual("c:\\chocolatey\\Bob"); + because(); + + var directories = directoryCreated.ToList(); + directories.Count.ShouldEqual(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); + directories[0].ShouldEqual("c:\\chocolatey\\Bob"); directories[1].ShouldEqual("c:\\chocolatey\\Bob\\tools"); directories[2].ShouldEqual("c:\\chocolatey\\Bob\\tools\\lower"); @@ -384,24 +392,24 @@ public void should_generate_all_files_and_directories() MockLogger.MessagesFor(LogLevel.Info).Last().ShouldEqual(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\chocolatey\Bob'", Environment.NewLine)); } - [Fact] + [Fact] [WindowsOnly] public void should_generate_all_files_and_directories_even_with_outputdirectory() { config.OutputDirectory = "c:\\packages"; - because(); - - var directories = directoryCreated.ToList(); - directories.Count.ShouldEqual(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); - directories[0].ShouldEqual("c:\\packages\\Bob"); - directories[1].ShouldEqual("c:\\packages\\Bob\\tools"); + because(); + + var directories = directoryCreated.ToList(); + directories.Count.ShouldEqual(3, "There should be 3 directories, but there was: " + string.Join(", ", directories)); + directories[0].ShouldEqual("c:\\packages\\Bob"); + directories[1].ShouldEqual("c:\\packages\\Bob\\tools"); directories[2].ShouldEqual("c:\\packages\\Bob\\tools\\lower"); files.Count.ShouldEqual(4, "There should be 4 files, but there was: " + string.Join(", ", files)); - files[0].ShouldEqual("c:\\packages\\Bob\\__name_replace__.nuspec"); - files[1].ShouldEqual("c:\\packages\\Bob\\random.txt"); - files[2].ShouldEqual("c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); + files[0].ShouldEqual("c:\\packages\\Bob\\__name_replace__.nuspec"); + files[1].ShouldEqual("c:\\packages\\Bob\\random.txt"); + files[2].ShouldEqual("c:\\packages\\Bob\\tools\\chocolateyInstall.ps1"); files[3].ShouldEqual("c:\\packages\\Bob\\tools\\lower\\another.ps1"); MockLogger.MessagesFor(LogLevel.Info).Last().ShouldEqual(string.Format(@"Successfully generated Bob package specification files{0} at 'c:\packages\Bob'", Environment.NewLine)); diff --git a/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs b/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs index 792c22b8c4..131f8aa937 100644 --- a/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs +++ b/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,10 +18,10 @@ namespace chocolatey.tests.infrastructure.commandline { using System; using System.Collections.Generic; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.commandline; + using Moq; + using Should; public class InteractivePromptSpecs { @@ -101,7 +102,10 @@ public void should_error_when_the_choicelist_is_empty() [Fact] public void should_error_when_the_prompt_input_is_null() { - choices = new List {"bob"}; + choices = new List + { + "bob" + }; prompt_value = null; bool errored = false; console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed @@ -121,7 +125,10 @@ public void should_error_when_the_prompt_input_is_null() [Fact] public void should_error_when_the_default_choice_is_not_in_list() { - choices = new List {"bob"}; + choices = new List + { + "bob" + }; default_choice = "maybe"; bool errored = false; string errorMessage = string.Empty; @@ -173,8 +180,8 @@ public void should_return_first_choice_when_1_is_given() console.Setup(c => c.ReadLine()).Returns("1"); var result = prompt(); result.ShouldEqual(choices[0]); - } - + } + [Fact] public void should_return_first_choice_when_value_of_choice_is_given() { @@ -445,7 +452,7 @@ public class when_prompting_short_with_interactivePrompt_guard_errors : Interact public override void Because() { console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed - prompt = () => InteractivePrompt.prompt_for_confirmation(prompt_value, choices, defaultChoice: null, requireAnswer:true, shortPrompt: true); + prompt = () => InteractivePrompt.prompt_for_confirmation(prompt_value, choices, defaultChoice: null, requireAnswer: true, shortPrompt: true); } [Fact] @@ -492,7 +499,10 @@ public void should_error_when_the_choicelist_is_empty() [Fact] public void should_error_when_the_prompt_input_is_null() { - choices = new List { "bob" }; + choices = new List + { + "bob" + }; prompt_value = null; bool errored = false; string errorMessage = string.Empty; @@ -515,7 +525,11 @@ public void should_error_when_the_prompt_input_is_null() [Fact] public void should_error_when_the_choicelist_contains_empty_values() { - choices = new List { "bob", "" }; + choices = new List + { + "bob", + "" + }; bool errored = false; string errorMessage = string.Empty; console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed @@ -537,7 +551,11 @@ public void should_error_when_the_choicelist_contains_empty_values() [Fact] public void should_error_when_the_choicelist_has_multiple_items_with_same_first_letter() { - choices = new List {"sally", "suzy"}; + choices = new List + { + "sally", + "suzy" + }; bool errored = false; string errorMessage = string.Empty; console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed @@ -641,4 +659,4 @@ public void should_error_when_any_choice_not_available_is_given() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/commands/CommandExecutorSpecs.cs b/src/chocolatey.tests/infrastructure/commands/CommandExecutorSpecs.cs index 38d5730a61..24c2dc812d 100644 --- a/src/chocolatey.tests/infrastructure/commands/CommandExecutorSpecs.cs +++ b/src/chocolatey.tests/infrastructure/commands/CommandExecutorSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,12 +17,12 @@ namespace chocolatey.tests.infrastructure.commands { using System; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app; using chocolatey.infrastructure.commands; using chocolatey.infrastructure.filesystem; + using Moq; + using Should; public class CommandExecutorSpecs { @@ -138,7 +139,7 @@ public class when_CommandExecutor_does_not_wait_for_exit : CommandExecutorSpecsB public override void Because() { - result = commandExecutor.execute("bob", "args", waitForExitInSeconds: 0, workingDirectory:null, stdOutAction: null, stdErrAction: null, updateProcessPath:false, allowUseWindow: true, waitForExit: false); + result = commandExecutor.execute("bob", "args", waitForExitInSeconds: 0, workingDirectory: null, stdOutAction: null, stdErrAction: null, updateProcessPath: false, allowUseWindow: true, waitForExit: false); } [Fact] @@ -154,4 +155,4 @@ public void should_not_call_WaitForExit() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/commands/ExternalCommandArgsBuilderSpecs.cs b/src/chocolatey.tests/infrastructure/commands/ExternalCommandArgsBuilderSpecs.cs index 1d5d7ec85f..f1c1329a12 100644 --- a/src/chocolatey.tests/infrastructure/commands/ExternalCommandArgsBuilderSpecs.cs +++ b/src/chocolatey.tests/infrastructure/commands/ExternalCommandArgsBuilderSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,9 +18,9 @@ namespace chocolatey.tests.infrastructure.commands { using System; using System.Collections.Generic; - using Should; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.commands; + using Should; public class ExternalCommandArgsBuilderSpecs { @@ -46,7 +47,12 @@ public override void Because() public void should_add_a_parameter_if_property_value_is_set() { argsDictionary.Clear(); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source "}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source " + }); buildConfigs().ShouldEqual("-source " + configuration.Sources); } @@ -54,7 +60,12 @@ public void should_add_a_parameter_if_property_value_is_set() public void should_add_a_parameter_if_property_value_is_sub_property() { argsDictionary.Clear(); - argsDictionary.Add("ApiKeyCommand.Key", new ExternalCommandArgument {ArgumentOption = "-apikey "}); + argsDictionary.Add( + "ApiKeyCommand.Key", + new ExternalCommandArgument + { + ArgumentOption = "-apikey " + }); buildConfigs().ShouldEqual("-apikey " + configuration.ApiKeyCommand.Key); } @@ -62,7 +73,12 @@ public void should_add_a_parameter_if_property_value_is_sub_property() public void should_skip_a_parameter_that_does_not_match_the_case_of_the_property_name_exactly() { argsDictionary.Clear(); - argsDictionary.Add("sources", new ExternalCommandArgument {ArgumentOption = "-source "}); + argsDictionary.Add( + "sources", + new ExternalCommandArgument + { + ArgumentOption = "-source " + }); buildConfigs().ShouldEqual(""); } @@ -70,7 +86,12 @@ public void should_skip_a_parameter_that_does_not_match_the_case_of_the_property public void should_add_a_parameter_that_does_not_match_the_case_of_the_property_name_when_dictionary_ignores_case() { IDictionary ignoreCaseDictionary = new Dictionary(StringComparer.InvariantCultureIgnoreCase); - ignoreCaseDictionary.Add("sources", new ExternalCommandArgument {ArgumentOption = "-source "}); + ignoreCaseDictionary.Add( + "sources", + new ExternalCommandArgument + { + ArgumentOption = "-source " + }); ExternalCommandArgsBuilder.build_arguments(configuration, ignoreCaseDictionary).ShouldEqual("-source yo"); } @@ -78,7 +99,13 @@ public void should_add_a_parameter_that_does_not_match_the_case_of_the_property_ public void should_not_override_ArgumentValue_with_the_property_value_for_a_parameter() { argsDictionary.Clear(); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source ", ArgumentValue = "bob"}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source ", + ArgumentValue = "bob" + }); buildConfigs().ShouldEqual("-source bob"); } @@ -86,7 +113,12 @@ public void should_not_override_ArgumentValue_with_the_property_value_for_a_para public void should_skip_a_parameter_if_property_value_has_no_value() { argsDictionary.Clear(); - argsDictionary.Add("Version", new ExternalCommandArgument {ArgumentOption = "-version "}); + argsDictionary.Add( + "Version", + new ExternalCommandArgument + { + ArgumentOption = "-version " + }); buildConfigs().ShouldEqual(""); } @@ -94,7 +126,13 @@ public void should_skip_a_parameter_if_property_value_has_no_value() public void should_add_a_parameter_when_Required_set_true_even_if_property_has_no_value() { argsDictionary.Clear(); - argsDictionary.Add("Version", new ExternalCommandArgument {ArgumentOption = "install", Required = true}); + argsDictionary.Add( + "Version", + new ExternalCommandArgument + { + ArgumentOption = "install", + Required = true + }); buildConfigs().ShouldEqual("install"); } @@ -102,7 +140,12 @@ public void should_add_a_parameter_when_Required_set_true_even_if_property_has_n public void should_skip_a_parameter_not_found_in_the_properties_object() { argsDictionary.Clear(); - argsDictionary.Add("_install_", new ExternalCommandArgument {ArgumentOption = "install"}); + argsDictionary.Add( + "_install_", + new ExternalCommandArgument + { + ArgumentOption = "install" + }); buildConfigs().ShouldEqual(""); } @@ -110,7 +153,13 @@ public void should_skip_a_parameter_not_found_in_the_properties_object() public void should_add_a_parameter_not_found_in_the_properties_object_when_Required_set_to_true() { argsDictionary.Clear(); - argsDictionary.Add("_install_", new ExternalCommandArgument {ArgumentOption = "install", Required = true}); + argsDictionary.Add( + "_install_", + new ExternalCommandArgument + { + ArgumentOption = "install", + Required = true + }); buildConfigs().ShouldEqual("install"); } @@ -118,7 +167,12 @@ public void should_add_a_parameter_not_found_in_the_properties_object_when_Requi public void should_add_a_boolean_as_a_switch_when_true() { argsDictionary.Clear(); - argsDictionary.Add("Verbose", new ExternalCommandArgument {ArgumentOption = "-verbose"}); + argsDictionary.Add( + "Verbose", + new ExternalCommandArgument + { + ArgumentOption = "-verbose" + }); buildConfigs().ShouldEqual("-verbose"); } @@ -126,7 +180,12 @@ public void should_add_a_boolean_as_a_switch_when_true() public void should_skip_a_boolean_as_a_switch_when_false() { argsDictionary.Clear(); - argsDictionary.Add("Prerelease", new ExternalCommandArgument {ArgumentOption = "-pre"}); + argsDictionary.Add( + "Prerelease", + new ExternalCommandArgument + { + ArgumentOption = "-pre" + }); buildConfigs().ShouldEqual(""); } @@ -134,7 +193,13 @@ public void should_skip_a_boolean_as_a_switch_when_false() public void should_quote_a_value_when_QuoteValue_is_set_to_true() { argsDictionary.Clear(); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source ", QuoteValue = true}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source ", + QuoteValue = true + }); buildConfigs().ShouldEqual("-source \"yo\""); } @@ -142,7 +207,12 @@ public void should_quote_a_value_when_QuoteValue_is_set_to_true() public void should_auto_quote_an_argument_value_with_spaces() { argsDictionary.Clear(); - argsDictionary.Add("CommandName", new ExternalCommandArgument {ArgumentOption = "-command "}); + argsDictionary.Add( + "CommandName", + new ExternalCommandArgument + { + ArgumentOption = "-command " + }); buildConfigs().ShouldEqual("-command \"{0}\"".format_with(configuration.CommandName)); } @@ -150,7 +220,13 @@ public void should_auto_quote_an_argument_value_with_spaces() public void should_not_quote_an_argument_option_with_spaces() { argsDictionary.Clear(); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source you know = ", QuoteValue = true}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source you know = ", + QuoteValue = true + }); buildConfigs().ShouldEqual("-source you know = \"yo\""); } @@ -158,7 +234,13 @@ public void should_not_quote_an_argument_option_with_spaces() public void should_use_only_the_value_when_UseValueOnly_is_set_to_true() { argsDictionary.Clear(); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source ", UseValueOnly = true}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source ", + UseValueOnly = true + }); buildConfigs().ShouldEqual("yo"); } @@ -166,7 +248,15 @@ public void should_use_only_the_value_when_UseValueOnly_is_set_to_true() public void should_use_only_the_value_when_UseValueOnly_and_Required_is_set_to_true() { argsDictionary.Clear(); - argsDictionary.Add("_source_", new ExternalCommandArgument {ArgumentOption = "-source ", ArgumentValue = "bob", UseValueOnly = true, Required = true}); + argsDictionary.Add( + "_source_", + new ExternalCommandArgument + { + ArgumentOption = "-source ", + ArgumentValue = "bob", + UseValueOnly = true, + Required = true + }); buildConfigs().ShouldEqual("bob"); } @@ -174,7 +264,13 @@ public void should_use_only_the_value_when_UseValueOnly_and_Required_is_set_to_t public void should_not_add_a_value_when_UseValueOnly_is_set_to_true_and_no_value_is_set() { argsDictionary.Clear(); - argsDictionary.Add("Version", new ExternalCommandArgument {ArgumentOption = "-version ", UseValueOnly = true}); + argsDictionary.Add( + "Version", + new ExternalCommandArgument + { + ArgumentOption = "-version ", + UseValueOnly = true + }); buildConfigs().ShouldEqual(""); } @@ -182,8 +278,19 @@ public void should_not_add_a_value_when_UseValueOnly_is_set_to_true_and_no_value public void should_separate_arguments_by_one_space() { argsDictionary.Clear(); - argsDictionary.Add("_install_", new ExternalCommandArgument {ArgumentOption = "install", Required = true}); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source "}); + argsDictionary.Add( + "_install_", + new ExternalCommandArgument + { + ArgumentOption = "install", + Required = true + }); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source " + }); buildConfigs().ShouldEqual("install -source yo"); } @@ -191,20 +298,46 @@ public void should_separate_arguments_by_one_space() public void should_add_items_in_order_based_on_the_dictionary() { argsDictionary.Clear(); - argsDictionary.Add("_install_", new ExternalCommandArgument {ArgumentOption = "install", Required = true}); - argsDictionary.Add("_output_directory_", new ExternalCommandArgument + argsDictionary.Add( + "_install_", + new ExternalCommandArgument + { + ArgumentOption = "install", + Required = true + }); + argsDictionary.Add( + "_output_directory_", + new ExternalCommandArgument { ArgumentOption = "-outputdirectory ", ArgumentValue = "bob", QuoteValue = true, Required = true }); - argsDictionary.Add("Sources", new ExternalCommandArgument {ArgumentOption = "-source ", QuoteValue = true}); - argsDictionary.Add("_non_interactive_", new ExternalCommandArgument {ArgumentOption = "-noninteractive", Required = true}); - argsDictionary.Add("_no_cache_", new ExternalCommandArgument {ArgumentOption = "-nocache", Required = true}); + argsDictionary.Add( + "Sources", + new ExternalCommandArgument + { + ArgumentOption = "-source ", + QuoteValue = true + }); + argsDictionary.Add( + "_non_interactive_", + new ExternalCommandArgument + { + ArgumentOption = "-noninteractive", + Required = true + }); + argsDictionary.Add( + "_no_cache_", + new ExternalCommandArgument + { + ArgumentOption = "-nocache", + Required = true + }); buildConfigs().ShouldEqual("install -outputdirectory \"bob\" -source \"{0}\" -noninteractive -nocache".format_with(configuration.Sources)); } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/commands/PowershellExecutorSpecs.cs b/src/chocolatey.tests/infrastructure/commands/PowershellExecutorSpecs.cs index 2bc8bf46b9..35778811e0 100644 --- a/src/chocolatey.tests/infrastructure/commands/PowershellExecutorSpecs.cs +++ b/src/chocolatey.tests/infrastructure/commands/PowershellExecutorSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,11 +18,11 @@ namespace chocolatey.tests.infrastructure.commands { using System; using System.IO; + using chocolatey.infrastructure.commands; + using chocolatey.infrastructure.filesystem; using Moq; using NUnit.Framework; using Should; - using chocolatey.infrastructure.commands; - using chocolatey.infrastructure.filesystem; public class PowershellExecutorSpecs { @@ -115,4 +116,4 @@ public void should_throw_an_error() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/configuration/ConfigSpecs.cs b/src/chocolatey.tests/infrastructure/configuration/ConfigSpecs.cs index 07a11b524a..11d378555c 100644 --- a/src/chocolatey.tests/infrastructure/configuration/ConfigSpecs.cs +++ b/src/chocolatey.tests/infrastructure/configuration/ConfigSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,9 +16,9 @@ namespace chocolatey.tests.infrastructure.configuration { - using Should; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.configuration; + using Should; public class ConfigSpecs { @@ -60,4 +61,4 @@ public void should_use_the_overridden_type() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/cryptography/CrytpoHashProviderSpecs.cs b/src/chocolatey.tests/infrastructure/cryptography/CrytpoHashProviderSpecs.cs index cd90d491a9..9988bd5db1 100644 --- a/src/chocolatey.tests/infrastructure/cryptography/CrytpoHashProviderSpecs.cs +++ b/src/chocolatey.tests/infrastructure/cryptography/CrytpoHashProviderSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,12 +19,12 @@ namespace chocolatey.tests.infrastructure.cryptography using System; using System.IO; using System.Security.Cryptography; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app; using chocolatey.infrastructure.cryptography; using chocolatey.infrastructure.filesystem; + using Moq; + using Should; public class CrytpoHashProviderSpecs { @@ -41,8 +42,8 @@ public override void Context() public class when_HashProvider_provides_a_hash : CrytpoHashProviderSpecsBase { private string result; - private string filePath = "c:\\path\\does\\not\\matter.txt"; - private readonly byte[] byteArray = new byte[] {23, 25, 27}; + private readonly string filePath = "c:\\path\\does\\not\\matter.txt"; + private readonly byte[] byteArray = new byte[] { 23, 25, 27 }; public override void Context() { @@ -63,15 +64,15 @@ public void should_provide_the_correct_hash_based_on_a_checksum() result.ShouldEqual(expected); } - } - + } + public class when_HashProvider_attempts_to_provide_a_hash_for_a_file_over_2GB : CrytpoHashProviderSpecsBase { private string result; - private string filePath = "c:\\path\\does\\not\\matter.txt"; + private readonly string filePath = "c:\\path\\does\\not\\matter.txt"; private readonly byte[] byteArray = new byte[] { 23, 25, 27 }; private readonly Mock _hashAlgorithm = new Mock(); - + public override void Context() { base.Context(); @@ -106,4 +107,4 @@ public void should_provide_an_unchanging_hash_for_a_file_too_big_to_hash() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/events/EventSubscriptionManagerSpecs.cs b/src/chocolatey.tests/infrastructure/events/EventSubscriptionManagerSpecs.cs index 81148b3f9e..485c5b86da 100644 --- a/src/chocolatey.tests/infrastructure/events/EventSubscriptionManagerSpecs.cs +++ b/src/chocolatey.tests/infrastructure/events/EventSubscriptionManagerSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,10 +19,10 @@ namespace chocolatey.tests.infrastructure.events using System; using System.Collections.Generic; using System.Threading; - using NUnit.Framework; - using Should; using chocolatey.infrastructure.services; using context; + using NUnit.Framework; + using Should; public class EventSubscriptionManagerSpecs { @@ -46,11 +47,14 @@ public class when_using_eventSubscriptionManager_to_subscribe_to_an_event : Even public override void Context() { base.Context(); - SubscriptionManager.subscribe(x => + SubscriptionManager.subscribe( + x => { _wasCalled = true; _localFakeEvent = x; - }, null, null); + }, + null, + null); } public override void Because() @@ -91,14 +95,17 @@ public class when_using_eventSubscriptionManager_with_long_running_event_subscri public override void Context() { base.Context(); - SubscriptionManager.subscribe(m => + SubscriptionManager.subscribe( + m => { //stuff is happening Thread.Sleep(2000); _wasCalled = true; _localFakeEvent = m; Console.WriteLine("event complete"); - }, null, null); + }, + null, + null); } public override void Because() @@ -128,11 +135,14 @@ public class when_using_eventSubscriptionManager_to_subscribe_to_an_event_with_a public override void Context() { base.Context(); - SubscriptionManager.subscribe(x => + SubscriptionManager.subscribe( + x => { _wasCalled = true; _localFakeEvent = x; - }, null, (message) => message.Digits > 3); + }, + null, + (message) => message.Digits > 3); } public override void Because() @@ -173,11 +183,14 @@ public class when_using_eventSubscriptionManager_to_subscribe_to_an_event_with_a public override void Context() { base.Context(); - SubscriptionManager.subscribe(x => + SubscriptionManager.subscribe( + x => { _wasCalled = true; _localFakeEvent = x; - }, null, (message) => message.Digits < 3); + }, + null, + (message) => message.Digits < 3); } public override void Because() @@ -210,7 +223,8 @@ public override void Context() do { _list.Add(new FakeSubscriber(SubscriptionManager)); - } while (_list.Count < 5); + } + while (_list.Count < 5); } public override void Because() @@ -243,4 +257,4 @@ public void should_throw_an_error() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/events/context/FakeEvent.cs b/src/chocolatey.tests/infrastructure/events/context/FakeEvent.cs index a143d636a3..835846a922 100644 --- a/src/chocolatey.tests/infrastructure/events/context/FakeEvent.cs +++ b/src/chocolatey.tests/infrastructure/events/context/FakeEvent.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,4 +29,4 @@ public FakeEvent(string name, double digits) public string Name { get; private set; } public double Digits { get; private set; } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/events/context/FakeSubscriber.cs b/src/chocolatey.tests/infrastructure/events/context/FakeSubscriber.cs index 8db2634218..937c7ac982 100644 --- a/src/chocolatey.tests/infrastructure/events/context/FakeSubscriber.cs +++ b/src/chocolatey.tests/infrastructure/events/context/FakeSubscriber.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,16 +23,19 @@ public class FakeSubscriber { public FakeSubscriber(IEventSubscriptionManagerService subscriptionManager) { - subscriptionManager.subscribe(x => + subscriptionManager.subscribe( + x => { WasCalled = true; ReceivedEvent = x; CalledAt = DateTime.Now; - }, null, null); + }, + null, + null); } public FakeEvent ReceivedEvent { get; private set; } public bool WasCalled { get; private set; } public DateTime CalledAt { get; private set; } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs index cf58a4a3d0..5d5b58d678 100644 --- a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,13 +18,13 @@ namespace chocolatey.tests.infrastructure.filesystem { using System; using System.IO; - using NUnit.Framework; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.platforms; + using Moq; + using NUnit.Framework; + using Should; public class DotNetFileSystemSpecs { @@ -77,8 +78,8 @@ public void GetExtension_should_return_the_extension_of_the_filename_even_with_a public void GetDirectoryName_should_return_the_directory_of_the_path_to_the_file() { FileSystem.get_directory_name("C:\\temp\\test.txt").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\temp" + Platform.get_platform() == PlatformType.Windows + ? "C:\\temp" : "C:/temp"); } @@ -86,8 +87,8 @@ public void GetDirectoryName_should_return_the_directory_of_the_path_to_the_file public void Combine_should_combine_the_file_paths_of_all_the_included_items_together() { FileSystem.combine_paths("C:\\temp", "yo", "filename.txt").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\temp\\yo\\filename.txt" + Platform.get_platform() == PlatformType.Windows + ? "C:\\temp\\yo\\filename.txt" : "C:/temp/yo/filename.txt"); } @@ -95,8 +96,8 @@ public void Combine_should_combine_the_file_paths_of_all_the_included_items_toge public void Combine_should_combine_when_paths_have_backslashes_in_subpaths() { FileSystem.combine_paths("C:\\temp", "yo\\timmy", "filename.txt").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\temp\\yo\\timmy\\filename.txt" + Platform.get_platform() == PlatformType.Windows + ? "C:\\temp\\yo\\timmy\\filename.txt" : "C:/temp/yo/timmy/filename.txt"); } @@ -104,8 +105,8 @@ public void Combine_should_combine_when_paths_have_backslashes_in_subpaths() public void Combine_should_combine_when_paths_start_with_backslashes_in_subpaths() { FileSystem.combine_paths("C:\\temp", "\\yo", "filename.txt").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\temp\\yo\\filename.txt" + Platform.get_platform() == PlatformType.Windows + ? "C:\\temp\\yo\\filename.txt" : "C:/temp/yo/filename.txt"); } @@ -113,8 +114,8 @@ public void Combine_should_combine_when_paths_start_with_backslashes_in_subpaths public void Combine_should_combine_when_paths_start_with_forwardslashes_in_subpaths() { FileSystem.combine_paths("C:\\temp", "/yo", "filename.txt").ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "C:\\temp\\yo\\filename.txt" + Platform.get_platform() == PlatformType.Windows + ? "C:\\temp\\yo\\filename.txt" : "C:/temp/yo/filename.txt"); } @@ -136,8 +137,8 @@ public override void Context() _environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL"); _environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns( @"C:\ProgramData\Chocolatey\bin{0}C:\Program Files\Microsoft\Web Platform Installer\{0}C:\Users\yes\AppData\Roaming\Boxstarter{0}C:\tools\ChocolateyPackageUpdater{0}C:\Windows\system32{0}C:\Windows{0}C:\Windows\System32\Wbem{0}C:\Windows\System32\WindowsPowerShell\v1.0\{0}" - .format_with(Path.PathSeparator) - ); + .format_with(Path.PathSeparator) + ); FileSystem.initialize_with(new Lazy(() => _environment.Object)); } @@ -154,22 +155,22 @@ private void reset() public void GetExecutablePath_should_find_existing_executable() { FileSystem.get_executable_path("cmd").to_lower().ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "c:\\windows\\system32\\cmd.exe" + Platform.get_platform() == PlatformType.Windows + ? "c:\\windows\\system32\\cmd.exe" : "cmd", StringComparer.OrdinalIgnoreCase - ); + ); } [Fact] public void GetExecutablePath_should_find_existing_executable_with_extension() { FileSystem.get_executable_path("cmd.exe").to_lower().ShouldEqual( - Platform.get_platform() == PlatformType.Windows ? - "c:\\windows\\system32\\cmd.exe" + Platform.get_platform() == PlatformType.Windows + ? "c:\\windows\\system32\\cmd.exe" : "cmd.exe", StringComparer.OrdinalIgnoreCase - ); + ); } [Fact] @@ -201,8 +202,8 @@ public override void Context() _environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(string.Empty); _environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns( "/usr/local/bin{0}/usr/bin/{0}/bin{0}/usr/sbin{0}/sbin" - .format_with(Path.PathSeparator) - ); + .format_with(Path.PathSeparator) + ); FileSystem.initialize_with(new Lazy(() => _environment.Object)); } @@ -214,11 +215,11 @@ public override void Because() public void GetExecutablePath_should_find_existing_executable() { FileSystem.get_executable_path("ls").ShouldEqual( - Platform.get_platform() != PlatformType.Windows ? - "/bin/ls" + Platform.get_platform() != PlatformType.Windows + ? "/bin/ls" : "ls"); } - + [Fact] public void GetExecutablePath_should_return_same_value_when_executable_is_not_found() { @@ -238,4 +239,4 @@ public void GetExecutablePath_should_return_empty_string_when_value_is_empty_str } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs b/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs index 280d377ecb..be6cb2c845 100644 --- a/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs +++ b/src/chocolatey.tests/infrastructure/guards/EnsureSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,10 +17,10 @@ namespace chocolatey.tests.infrastructure.guards { using System; - using Moq; - using Should; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.guards; + using Moq; + using Should; public class EnsureSpecs { @@ -33,7 +34,7 @@ public override void Context() public class when_Ensure_is_being_set_to_a_type : EnsureSpecsBase { private object result; - private string bob = "something"; + private readonly string bob = "something"; public override void Because() { @@ -294,10 +295,10 @@ public override void Because() Ensure.that(() => test).meets( s => s == s.ToLower(), (name, value) => - { - exceptionActionInvoked = true; - throw new ApplicationException("this is what we throw."); - }); + { + exceptionActionInvoked = true; + throw new ApplicationException("this is what we throw."); + }); } catch (Exception ex) { @@ -346,10 +347,10 @@ public override void Because() Ensure.that(() => test).meets( s => s == s.ToLower(), (name, value) => - { - exceptionActionInvoked = true; - throw new ApplicationException("this is what we throw."); - }); + { + exceptionActionInvoked = true; + throw new ApplicationException("this is what we throw."); + }); } catch (Exception ex) { @@ -398,10 +399,10 @@ public override void Because() Ensure.that(() => test).meets( s => s == s.ToLower(), (name, value) => - { - exceptionActionInvoked = true; - throw new ApplicationException("this is what we throw."); - }); + { + exceptionActionInvoked = true; + throw new ApplicationException("this is what we throw."); + }); } catch (Exception ex) { @@ -450,4 +451,4 @@ public void should_not_return_the_specified_error_message() // } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/information/VersionInformationSpecs.cs b/src/chocolatey.tests/infrastructure/information/VersionInformationSpecs.cs index 9dfb905fc0..60c629f6ec 100644 --- a/src/chocolatey.tests/infrastructure/information/VersionInformationSpecs.cs +++ b/src/chocolatey.tests/infrastructure/information/VersionInformationSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,8 +17,8 @@ namespace chocolatey.tests.infrastructure.information { using System; - using Should; using chocolatey.infrastructure.information; + using Should; public class VersionInformationSpecs { @@ -62,4 +63,4 @@ public void should_not_equal_zero_dot_zero_dot_zero_dot_zero() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/platforms/PlatformSpecs.cs b/src/chocolatey.tests/infrastructure/platforms/PlatformSpecs.cs index 30bc1f9fdf..b03fcaf8a7 100644 --- a/src/chocolatey.tests/infrastructure/platforms/PlatformSpecs.cs +++ b/src/chocolatey.tests/infrastructure/platforms/PlatformSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,11 +17,11 @@ namespace chocolatey.tests.infrastructure.platforms { using System; - using Moq; - using Should; using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.platforms; + using Moq; + using Should; using Environment = System.Environment; public class PlatformSpecs @@ -143,4 +144,4 @@ public void should_return_Mac() } } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/tokens/TokenReplacerSpecs.cs b/src/chocolatey.tests/infrastructure/tokens/TokenReplacerSpecs.cs index 09bd739e74..de2241e84a 100644 --- a/src/chocolatey.tests/infrastructure/tokens/TokenReplacerSpecs.cs +++ b/src/chocolatey.tests/infrastructure/tokens/TokenReplacerSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,9 +17,9 @@ namespace chocolatey.tests.infrastructure.tokens { using System.Collections.Generic; - using Should; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.tokens; + using Should; public class TokenReplacerSpecs { @@ -67,8 +68,8 @@ public void when_given_brace_brace_commandname_brace_brace_should_replace_with_t public void when_given_brace_brace_COMMANDNAME_brace_brace_should_replace_with_the_Name_from_the_configuration() { TokenReplacer.replace_tokens(configuration, "Hi! My name is [[COMMANDNAME]]").ShouldEqual("Hi! My name is " + name); - } - + } + [Fact] public void when_given_brace_brace_cOMmAnDnAMe_brace_brace_should_replace_with_the_Name_from_the_configuration() { @@ -109,8 +110,7 @@ public void if_given_an_null_value_should_return_the_ll_value() public class when_using_TokenReplacer_with_a_Dictionary : TokenReplacerSpecsBase { public Dictionary tokens = new Dictionary(); - private string value = "sweet"; - + private readonly string value = "sweet"; public override void Because() { @@ -122,7 +122,6 @@ public void when_given_a_proper_token_it_should_replace_with_the_dictionary_valu { TokenReplacer.replace_tokens(tokens, "Hi! My name is [[dude]]").ShouldEqual("Hi! My name is " + value); } - } } -} \ No newline at end of file +} diff --git a/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs b/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs index 12feba3100..f110e78d3f 100644 --- a/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs +++ b/src/chocolatey.tests/infrastructure/tolerance/FaultToleranceSpecs.cs @@ -1,4 +1,5 @@ -// Copyright © 2011 - Present RealDimensions Software, LLC +// Copyright © 2017 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,9 +17,9 @@ namespace chocolatey.tests.infrastructure.tolerance { using System; + using chocolatey.infrastructure.tolerance; using NUnit.Framework; using Should; - using chocolatey.infrastructure.tolerance; public class FaultToleranceSpecs { @@ -41,16 +42,21 @@ public override void Because() } [Fact] - [ExpectedException(typeof (ApplicationException))] + [ExpectedException(typeof(ApplicationException))] public void should_not_allow_the_number_of_retries_to_be_zero() { reset(); - FaultTolerance.retry(0, () => { var dude = 1; }); + FaultTolerance.retry( + 0, + () => + { + var dude = 1; + }); } [Fact] - [ExpectedException(typeof (Exception))] + [ExpectedException(typeof(Exception))] public void should_throw_an_error_if_retries_are_reached() { reset(); @@ -83,12 +89,14 @@ public void should_retry_the_number_of_times_specified() var i = 0; try { - FaultTolerance.retry(10, () => + FaultTolerance.retry( + 10, + () => { i += 1; throw new Exception("YIKES"); }, - waitDurationMilliseconds: 0); + waitDurationMilliseconds: 0); } catch { @@ -124,7 +132,7 @@ public void should_log_an_error_message() reset(); FaultTolerance.try_catch_with_logging_exception( - () => { throw new Exception("This is the message");}, + () => { throw new Exception("This is the message"); }, "You have an error" ); @@ -150,10 +158,10 @@ public void should_log_a_warning_message_when_set_to_warn() reset(); FaultTolerance.try_catch_with_logging_exception( - () => { throw new Exception("This is the message");}, + () => { throw new Exception("This is the message"); }, "You have an error", logWarningInsteadOfError: true - ); + ); MockLogger.MessagesFor(LogLevel.Warn).Count.ShouldEqual(1); } @@ -165,10 +173,10 @@ public void should_throw_an_error_if_throwError_set_to_true() reset(); FaultTolerance.try_catch_with_logging_exception( - () => { throw new Exception("This is the message"); }, - "You have an error", - throwError: true - ); + () => { throw new Exception("This is the message"); }, + "You have an error", + throwError: true + ); } [Fact] @@ -178,12 +186,12 @@ public void should_still_throw_an_error_when_warn_is_set_if_throwError_set_to_tr reset(); FaultTolerance.try_catch_with_logging_exception( - () => { throw new Exception("This is the message"); }, - "You have an error", - logWarningInsteadOfError: true, - throwError: true - ); + () => { throw new Exception("This is the message"); }, + "You have an error", + logWarningInsteadOfError: true, + throwError: true + ); } } } -} \ No newline at end of file +} From 71738fb612958b61fbe1e6f3104372a919fe0402 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Mar 2017 17:48:07 -0500 Subject: [PATCH 2/5] (GH-1213) Fix: list local should reset config When running `NuGetService.list_run` it makes changes to configuration items for a local only type of source. However it is not a good steward and doesn't set that configuration back. That can lead to undesirable results. Ensure that it puts the config back the way it received it. --- .../infrastructure.app/services/NugetService.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 4517220930..be22b48d21 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -113,6 +113,10 @@ public IEnumerable list_run(ChocolateyConfiguration config) { int count = 0; + var sources = config.Sources; + var prerelease = config.Prerelease; + var includeVersionOverrides = config.ListCommand.IncludeVersionOverrides; + if (config.ListCommand.LocalOnly) { config.Sources = ApplicationParameters.PackagesLocation; @@ -214,6 +218,10 @@ Package url { this.Log().Warn(() => @"{0} packages {1}.".format_with(count, config.ListCommand.LocalOnly ? "installed" : "found")); } + + config.Sources = sources; + config.Prerelease = prerelease; + config.ListCommand.IncludeVersionOverrides = includeVersionOverrides; } public void pack_noop(ChocolateyConfiguration config) From ccf06abee10d9028239064d104fa5e9d40062fc7 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Mar 2017 17:48:27 -0500 Subject: [PATCH 3/5] (maint) fix typo in method name --- src/chocolatey/infrastructure.app/services/NugetService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index be22b48d21..e9ecd49c33 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1142,7 +1142,7 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi if (!config.ForceDependencies) { // if you find an install of an .install / .portable / .commandline, allow adding it to the list - var installedPackages = get_all_intalled_packages(config).Select(p => p.Name).ToList().@join(ApplicationParameters.PackageNamesSeparator); + var installedPackages = get_all_installed_packages(config).Select(p => p.Name).ToList().@join(ApplicationParameters.PackageNamesSeparator); foreach (var packageName in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null()) { var installerExists = installedPackages.contains("{0}.install".format_with(packageName)); @@ -1381,7 +1381,7 @@ public void remove_installation_files(IPackage removedPackage, ChocolateyPackage } } - private IEnumerable get_all_intalled_packages(ChocolateyConfiguration config) + private IEnumerable get_all_installed_packages(ChocolateyConfiguration config) { //todo : move to deep copy for get all installed //var listConfig = config.deep_copy(); @@ -1428,7 +1428,7 @@ private void set_package_names_if_all_is_specified(ChocolateyConfiguration confi { if (config.PackageNames.is_equal_to(ApplicationParameters.AllPackages)) { - var packagesToUpdate = get_all_intalled_packages(config).Select(p => p.Name).ToList(); + var packagesToUpdate = get_all_installed_packages(config).Select(p => p.Name).ToList(); if (!string.IsNullOrWhiteSpace(config.UpgradeCommand.PackageNamesToSkip)) { From 9743e9369c3339cbde63fc8b4ada4416e718bc04 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Mar 2017 17:48:47 -0500 Subject: [PATCH 4/5] (spec) ensure config is reset between calls --- src/chocolatey.tests.integration/Scenario.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 2ecad30aef..84e971aab3 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -168,6 +168,13 @@ private static ChocolateyConfiguration baseline_configuration() config.Features.ChecksumFiles = true; config.OutputDirectory = null; config.Features.StopOnFirstPackageFailure = false; + config.UpgradeCommand.PackageNamesToSkip = string.Empty; + config.AllowDowngrade = false; + config.Features.FailOnStandardError = false; + config.ListCommand.IncludeVersionOverrides = false; + config.UpgradeCommand.FailOnNotInstalled = false; + config.PinCommand.Name = string.Empty; + config.PinCommand.Command = PinCommandType.unknown; return config; } From 55db9279fcc6fd4a63a690e9bdab3655c4aeb009 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 28 Mar 2017 17:56:13 -0500 Subject: [PATCH 5/5] (GH-1212) Fix: downgrade should not run w/out version When adding in `--allow-downgrade` to your upgrade options and you have a prerelease installed, it should not attempt to downgrade to the last stable version, unless you explicitly pass the version you want it to upgrade (or downgrade in this case) to. When version is null, it means that it should function as if it is on the latest release and do nothing. --- .../scenarios/UpgradeScenarios.cs | 94 +++++++++++++++++++ .../services/NugetService.cs | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 0b68f1bb62..dd1352fdf7 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -804,6 +804,100 @@ public void should_not_have_warning_package_result() _packageResult.Warning.ShouldBeFalse(); } + [Fact] + public void should_only_find_the_last_stable_version() + { + _packageResult.Version.ShouldEqual("1.1.0"); + } + } + + [Concern(typeof(ChocolateyUpgradeCommand))] + public class when_upgrading_an_existing_prerelease_package_with_allow_downgrade_with_excludeprelease_and_without_prerelease_specified : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Configuration.Prerelease = true; + Scenario.install_package(Configuration, "upgradepackage", "1.1.1-beta"); + Configuration.Prerelease = false; + Configuration.UpgradeCommand.ExcludePrerelease = true; + Configuration.AllowDowngrade = true; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_contain_a_message_that_you_have_the_latest_version_available() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) + { + if (message.Contains("upgradepackage v1.1.1-beta is newer")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_message_that_no_packages_were_upgraded() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 0/1 ")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_not_create_a_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeFalse(); + } + + [Fact] + public void should_not_remove_the_package_from_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + Directory.Exists(packageDir).ShouldBeTrue(); + } + + [Fact] + public void should_be_the_same_version_of_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension); + var package = new OptimizedZipPackage(packageFile); + package.Version.Version.to_string().ShouldEqual("1.1.1.0"); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + [Fact] public void should_only_find_the_last_stable_version() { diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index e9ecd49c33..6f53fb5694 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -676,7 +676,7 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu var packageResult = packageInstalls.GetOrAdd(packageName, new PackageResult(availablePackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, availablePackage.Id))); - if (installedPackage.Version > availablePackage.Version && !config.AllowDowngrade) + if (installedPackage.Version > availablePackage.Version && (!config.AllowDowngrade || (config.AllowDowngrade && version == null))) { string logMessage = "{0} v{1} is newer than the most recent.{2} You must be smarter than the average bear...".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine); packageResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));