public void RemoveExistingEncryptedValue() { HostEnvironment.HostInteraction.Settings.SetEncryptedValue("TestSetting", "oldValue"); var command = new ConfigCommand(HostEnvironment); command.Configure(null); _ = command.Execute("--setEncrypted TestSetting=".Split(" ")); Assert.IsFalse(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out _)); }
public void SetExistingValue() { HostEnvironment.HostInteraction.Settings.SetValue("TestSetting", "oldValue"); var command = new ConfigCommand(HostEnvironment); command.Configure(null); _ = command.Execute("--set TestSetting=testValue".Split(" ")); Assert.IsTrue(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out string value)); Assert.AreEqual("testValue", value); }
public void SetNewEncryptedValue() { Assert.IsFalse(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out _)); var command = new ConfigCommand(HostEnvironment); command.Configure(null); _ = command.Execute("--setEncrypted TestSetting=testValue".Split(" ")); Assert.IsTrue(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out string value)); Assert.AreNotEqual("testValue", value); }
public void ReadExistingSetting_ShouldPrintValueOnly() { HostEnvironment.HostInteraction.Settings.SetValue("TestSetting", "testValue"); var mockLogger = new Mock <ILogger>(); mockLogger.Setup(log => log.Log(It.Is <string>(s => s.Equals("testValue", StringComparison.Ordinal)), It.Is <LogLevel>(l => l == LogLevel.Task))); HostEnvironment.Logger = mockLogger.Object; var command = new ConfigCommand(HostEnvironment); command.Configure(null); _ = command.Execute("TestSetting"); mockLogger.Verify(); }
public void ReadNonExistingSetting_ShouldLogError() { var command = new ConfigCommand(HostEnvironment); command.Configure(null); try { _ = command.Execute("TestSetting"); Assert.Fail(); } catch (AggregateException ae) { var ioe = ae.InnerException as InvalidOperationException; Assert.IsNotNull(ioe); string expected = string.Format(Resources.Text.ConfigCommand_Error_KeyNotFound, "TestSetting"); Assert.AreEqual(expected, ioe.Message); } }
public void ReadAndWriteInSameInvocation_ShouldFailWithError() { var command = new ConfigCommand(HostEnvironment); command.Configure(null); try { _ = command.Execute("TestSetting --set TestSetting2=testValue".Split(" ")); Assert.Fail(); } catch (AggregateException ae) { var ioe = ae.InnerException as InvalidOperationException; Assert.IsNotNull(ioe); string expected = Resources.Text.ConfigCommand_Error_ConflictingParameters; Assert.AreEqual(expected, ioe.Message); } }
public void TestInitialize() { savedItems = null; loggerMock = new Mock <ILogger>(MockBehavior.Loose); loggerMock.Setup(l => l.ForContext <ConfigCommand>()) .Returns(loggerMock.Object); repositoryMock = new Mock <IRepository <Credentials> >(MockBehavior.Strict); repositoryMock.Setup(r => r.Update(It.IsAny <IEnumerable <Credentials> >())) .Callback <IEnumerable <Credentials> >(items => { savedItems = items.ToList(); }); command = new ConfigCommand(loggerMock.Object, repositoryMock.Object); servicesMock = new Mock <IServiceProvider>(MockBehavior.Loose); servicesMock.Setup(s => s.GetService(typeof(ConfigCommand))) .Returns(command); cliApp = new CommandLineApplication(); ConfigCommand.Configure(cliApp, servicesMock.Object); }