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")); }
public void AddSetting_Adds() { // 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.Add).Returns(new Nullable<SettingsLocation>(SettingsLocation.Local)); 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).SaveSetting(SettingsLocation.Local, "Boy", "Howdy"); }
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, "", ""); }