예제 #1
0
        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 _));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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();
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
        }