Exemple #1
0
        protected void Initialize(IArgumentProvider arguments)
        {
            string assembliesToResolve = arguments.GetOption <string>(StandardOptions.AssembliesToResolve);

            if (!string.IsNullOrEmpty(assembliesToResolve))
            {
                foreach (string assemblyToResolve in assembliesToResolve.Split(';'))
                {
                    AddAssemblyToResolve(assemblyToResolve);
                }
            }

            string resolutionPaths = arguments.GetOption <string>(StandardOptions.AssemblyResolutionPaths);

            if (!string.IsNullOrEmpty(resolutionPaths))
            {
                foreach (string resolutionPath in resolutionPaths.Split(';'))
                {
                    if (!string.IsNullOrWhiteSpace(resolutionPath))
                    {
                        string expandedResolutionPath = Environment.ExpandEnvironmentVariables(resolutionPath);
                        AddResolutionPath(expandedResolutionPath);
                    }
                }
            }
        }
        public void ParameterPassingTest()
        {
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>(StandardOptions.AssembliesToResolve).Returns("foo;bar");
            arguments.GetOption <string>(StandardOptions.AssemblyResolutionPaths).Returns(@"C:\TestLoad1;C:\TestLoad2");
            TestAssemblyResolver testResolver = TestAssemblyResolver.TestCreate(arguments, null);

            testResolver.AssembliesToResolve.Should().BeEquivalentTo("foo", "bar");
            testResolver.ResolutionPaths.Should().BeEquivalentTo(@"C:\TestLoad1", @"C:\TestLoad2");
        }
Exemple #3
0
        public void GetExtensionsFromArgument_NullReturnsEmpty()
        {
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>("Option").Returns((string)null);
            arguments.GetExtensionsFromArgument("Option").Should().BeEmpty();
        }
        public T GetOption <T>(params string[] optionNames)
        {
            if (optionNames == null || optionNames.Length == 0)
            {
                return(default(T));
            }

            // Return the explict setting, if found
            object argumentValue = _argumentProvider.GetOption <object>(optionNames);

            if (argumentValue != null)
            {
                return(Types.ConvertType <T>(argumentValue));
            }

            // Don't have an explicit, look for a default
            string defaultSetting = GetSetting(optionNames[0]);

            if (!string.IsNullOrWhiteSpace(defaultSetting))
            {
                defaultSetting = Environment.ExpandEnvironmentVariables(defaultSetting);
            }

            return(Types.ConvertType <T>(defaultSetting));
        }
Exemple #5
0
        public void GetExtensionsFromArgument_BasicTest()
        {
            // Should split extensions across semicolons and trim leading asterisks
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>("Option").Returns("*Bar;FooBar");
            arguments.GetExtensionsFromArgument("Option").Should().BeEquivalentTo("Bar", "FooBar");
        }
        public void NotFoundAssemblyDoesNotLoad()
        {
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>(StandardOptions.AssembliesToResolve).Returns("MyDependency");
            arguments.GetOption <string>(StandardOptions.AssemblyResolutionPaths).Returns(@"C:\TestLoad1");

            IFileService fileService = Substitute.For <IFileService>();

            fileService.GetAttributes(@"C:\TestLoad1\MyDependency.dll").Returns(x => { throw new FileNotFoundException(); });

            TestAssemblyResolver testResolver = Substitute.ForPartsOf <TestAssemblyResolver>(fileService);

            testResolver.TestInitialize(arguments);

            ((object)testResolver.Domain_AssemblyResolve(null, new ResolveEventArgs("MyDependency"))).Should().BeNull();
            testResolver.ReceivedWithAnyArgs(0).TestLoadAssemblyFrom("");
        }
        public void FoundAssemblyLoads()
        {
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>(StandardOptions.AssembliesToResolve).Returns("MyDependency");
            arguments.GetOption <string>(StandardOptions.AssemblyResolutionPaths).Returns(@"C:\TestLoad1");

            IFileService fileService = Substitute.For <IFileService>();

            fileService.GetAttributes(@"C:\TestLoad1\MyDependency.dll").Returns(FileAttributes.Normal);

            TestAssemblyResolver testResolver = Substitute.ForPartsOf <TestAssemblyResolver>(fileService);

            testResolver.TestInitialize(arguments);

            ((object)testResolver.Domain_AssemblyResolve(null, new ResolveEventArgs("MyDependency"))).Should().Be(Assembly.GetExecutingAssembly());
            testResolver.Received(1).TestLoadAssemblyFrom(@"C:\TestLoad1\MyDependency.dll");
        }
Exemple #8
0
        public void GetFilesFromArgument_NullReturnsEmpty()
        {
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>("Option").Returns((string)null);
            IFileService fileService = Substitute.For <IFileService>();

            arguments.GetFilesFromArgument(fileService, "Option").Should().BeEmpty();
        }
        public void GetArgumentGetsDefaultSetting()
        {
            IClientSettings settings = Substitute.For<IClientSettings>();
            IArgumentProvider arguments = Substitute.For<IArgumentProvider>();
            settings.GetSetting("Foo").Returns("Bar");

            TestArgumentSettingsProvider provider = new TestArgumentSettingsProvider("Section", arguments, settings);
            IArgumentProvider castArguments = (IArgumentProvider)provider;
            castArguments.GetOption<string>("Foo").Should().Be("Bar");
        }
Exemple #10
0
        public void GetFilesFromArgument_BasicTest()
        {
            // Should split extensions across semicolons and trim leading asterisks
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <string>("Option").Returns("Bar;FooBar");
            IFileService fileService = Substitute.For <IFileService>();

            fileService.GetFullPath("").ReturnsForAnyArgs(i => (string)i[0]);

            arguments.GetFilesFromArgument(fileService, "Option").Should().BeEquivalentTo("Bar", "FooBar");
        }
        public void ClipOptionShouldHaveClipLoggers()
        {
            ITask             task      = Substitute.For <ITask>();
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <bool?>(StandardOptions.Clipboard).Returns((bool?)true);


            using (ConsoleTaskInteraction interaction = (ConsoleTaskInteraction)ConsoleTaskInteraction.Create(task, arguments, null))
            {
                interaction.Loggers[LoggerType.Status].Should().BeSameAs(ConsoleLogger.Instance);
                interaction.Loggers[LoggerType.Result].Should().BeOfType <AggregatedLogger>();
            }
        }
Exemple #12
0
        protected void Initialize(IArgumentProvider arguments)
        {
            string assembliesToResolve = arguments.GetOption<string>(StandardOptions.AssembliesToResolve);
            if (!String.IsNullOrEmpty(assembliesToResolve))
            {
                foreach (string assemblyToResolve in assembliesToResolve.Split(';'))
                {
                    this.AddAssemblyToResolve(assemblyToResolve);
                }
            }

            string resolutionPaths = arguments.GetOption<string>(StandardOptions.AssemblyResolutionPaths);
            if (!String.IsNullOrEmpty(resolutionPaths))
            {
                foreach (string resolutionPath in resolutionPaths.Split(';'))
                {
                    if (!String.IsNullOrWhiteSpace(resolutionPath))
                    {
                        string expandedResolutionPath = Environment.ExpandEnvironmentVariables(resolutionPath);
                        this.AddResolutionPath(expandedResolutionPath);
                    }
                }
            }
        }
        public void ClipTaskWithClipOffShouldNotHaveClipLoggers()
        {
            ITask task = Substitute.For <ITask>();

            task.GetOptionDefault <bool>(StandardOptions.Clipboard[0]).Returns(true);
            IArgumentProvider arguments = Substitute.For <IArgumentProvider>();

            arguments.GetOption <bool?>(StandardOptions.Clipboard).Returns((bool?)false);

            using (ConsoleTaskInteraction interaction = (ConsoleTaskInteraction)ConsoleTaskInteraction.Create(task, arguments, null))
            {
                interaction.Loggers[LoggerType.Status].Should().BeSameAs(ConsoleLogger.Instance);
                interaction.Loggers[LoggerType.Result].Should().BeSameAs(ConsoleLogger.Instance);
            }
        }
Exemple #14
0
        public void ListSettings_CountIsCorrect()
        {
            // Ensure we output the location table and all settings when listing settings

            // Set up loggers
            List <ITable> outputTables = new List <ITable>();
            ILogger       logger       = Substitute.For <ILogger>();

            logger.Write(Arg.Do <ITable>(x => outputTables.Add(x)));
            ILoggers loggers = Substitute.For <ILoggers>();

            loggers[Arg.Any <LoggerType>()].Returns(logger);

            // Set up to list settings
            ITaskInteraction interaction = Substitute.For <ITaskInteraction>();

            interaction.Loggers.Returns(loggers);
            IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>();

            argumentProvider.GetOption <SettingsLocation?>(StandardOptions.List).Returns(new Nullable <SettingsLocation>(SettingsLocation.Local));
            interaction.Arguments.Returns(argumentProvider);

            // Prepare the configuration results
            ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.Local).Returns("LocalPath");
            ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.Roaming).Returns("RoamingPath");
            ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.RunningExecutable).Returns("ExePath");

            ClientSetting[] settings =
            {
                new ClientSetting("foo", "one", SettingsLocation.Local),
                new ClientSetting("bar", "two", SettingsLocation.Roaming)
            };
            ((IClientSettings)argumentProvider).GetAllSettings().Returns(settings);

            DefaultsTask task = new DefaultsTask("Foo");

            task.Execute(interaction).Should().Be(ExitCode.Success);

            outputTables.Count.Should().Be(2, "table for locations and table for settings");
            outputTables[0].Rows.Skip(1).ForEachDoOne(
                row => row.Should().Contain(SettingsLocation.Local.ToString(), "LocalPath"),
                row => row.Should().Contain(SettingsLocation.Roaming.ToString(), "RoamingPath"),
                row => row.Should().Contain(SettingsLocation.RunningExecutable.ToString(), "ExePath"));

            outputTables[1].Rows.Skip(1).ForEachDoOne(
                row => row.Should().Contain("foo", SettingsLocation.Local.ToString(), "one"),
                row => row.Should().Contain("bar", SettingsLocation.Roaming.ToString(), "two"));
        }
Exemple #15
0
        public void RemoveSetting_Removes()
        {
            // Ensure actually add a setting when adding

            // Set up to add settings
            ITaskInteraction  interaction      = Substitute.For <ITaskInteraction>();
            IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>();

            argumentProvider.GetOption <SettingsLocation?>(StandardOptions.Remove).Returns(new Nullable <SettingsLocation>(SettingsLocation.Roaming));
            interaction.Arguments.Returns(argumentProvider);

            argumentProvider.Options.Returns(new Dictionary <string, string>
            {
                { "Boy", "Howdy" }
            });

            DefaultsTask task = new DefaultsTask("Foo");

            task.Execute(interaction).Should().Be(ExitCode.Success);

            ((IClientSettings)argumentProvider).Received(1).RemoveSetting(SettingsLocation.Roaming, "Boy");
        }
Exemple #16
0
            public ConsoleTaskLoggers(ITask task, IArgumentProvider arguments)
            {
                if (arguments.GetOption <bool?>(StandardOptions.Clipboard) ?? task.GetOptionDefault <bool>(StandardOptions.Clipboard[0]))
                {
                    _richTextLogger    = new RichTextLogger();
                    _csvLogger         = new CsvLogger();
                    _textLogger        = new TextLogger();
                    _spreadsheetLogger = new XmlSpreadsheetLogger();
                    _aggregatedLogger  = new AggregatedLogger(
                        ConsoleLogger.Instance,
                        _richTextLogger,
                        _spreadsheetLogger,
                        _csvLogger,
                        _textLogger);

                    RegisterLogger(LoggerType.Result, _aggregatedLogger);
                }
                else
                {
                    RegisterLogger(LoggerType.Result, ConsoleLogger.Instance);
                }

                RegisterLogger(LoggerType.Status, ConsoleLogger.Instance);
            }
            public ConsoleTaskLoggers(ITask task, IArgumentProvider arguments)
            {
                if (arguments.GetOption<bool?>(StandardOptions.Clipboard) ?? task.GetOptionDefault<bool>(StandardOptions.Clipboard[0]))
                {
                    this.richTextLogger = new RichTextLogger();
                    this.csvLogger = new CsvLogger();
                    this.textLogger = new TextLogger();
                    this.spreadsheetLogger = new XmlSpreadsheetLogger();
                    this.aggregatedLogger = new AggregatedLogger(
                        ConsoleLogger.Instance,
                        this.richTextLogger,
                        this.spreadsheetLogger,
                        this.csvLogger,
                        this.textLogger);

                    this.RegisterLogger(LoggerType.Result, this.aggregatedLogger);
                }
                else
                {
                    this.RegisterLogger(LoggerType.Result, ConsoleLogger.Instance);
                }

                this.RegisterLogger(LoggerType.Status, ConsoleLogger.Instance);
            }
Exemple #18
0
        public void AddSetting_SkipOptions()
        {
            // Ensure we skip saving options that directly apply to the defaults task

            // Set up to add settings
            ITaskInteraction  interaction      = Substitute.For <ITaskInteraction>();
            IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>();

            argumentProvider.GetOption <SettingsLocation?>(StandardOptions.Add).Returns(new Nullable <SettingsLocation>(SettingsLocation.Local));
            interaction.Arguments.Returns(argumentProvider);

            argumentProvider.Options.Returns(new Dictionary <string, string>
            {
                { StandardOptions.List[0], "one" },
                { StandardOptions.Add[0], "two" },
                { StandardOptions.Remove[0], "three" },
            });

            DefaultsTask task = new DefaultsTask("Foo");

            task.Execute(interaction).Should().Be(ExitCode.Success);

            ((IClientSettings)argumentProvider).DidNotReceiveWithAnyArgs().SaveSetting(SettingsLocation.Local, "", "");
        }
 /// <summary>
 /// Returns files from the specified argument or empty array if none specified
 /// </summary>
 public static string[] GetFilesFromArgument(this IArgumentProvider arguments, IFileService fileService, params string[] optionAliases)
 {
     return(SplitFiles(fileService, arguments.GetOption <string>(optionAliases)));
 }
Exemple #20
0
 /// <summary>
 /// Returns directories from the specified argument or empty array if none specified
 /// </summary>
 public static string[] GetDirectoriesFromArgument(this IArgumentProvider arguments, IFileService fileService, params string[] optionAliases)
 {
     return(ArgumentProviderExtensions.SplitAndValidateDirectories(fileService, arguments.GetOption <string>(optionAliases)));
 }
 /// <summary>
 /// Returns files from the specified argument or empty array if none specified
 /// </summary>
 public static string[] GetExtensionsFromArgument(this IArgumentProvider arguments, params string[] optionAliases)
 {
     return(SplitExtensions(arguments.GetOption <string>(optionAliases)));
 }