public void MapperBindingTest()
        {
            var config = new TestConfig {
                Name      = "Anne",
                BirthDate = new DateTime(1980, 12, 21)
            };

            config.DeliveryAddress.Street     = "Main Street";
            config.DeliveryAddress.PostalCode = "10180";
            config.DeliveryAddress.State      = "MyState";

            var cmd = new CmdOptions {
                Name          = "Richard",
                DeliveryState = "OtherState"
            };

            var sut = new CommandLineConfigurationProvider <CmdOptions, TestConfig>(cmd, mapper => {
                mapper
                .Map(x => x.DeliveryState, x => x.DeliveryAddress.State)
                .Map(x => x.Name, x => x.Name);
            });

            sut.Load();

            string value = null;

            Assert.True(sut.TryGet("TestConfig:DeliveryAddress:State", out value));
            Assert.Equal("OtherState", value);
            value = null;
            Assert.True(sut.TryGet("TestConfig:Name", out value));
            Assert.Equal("Richard", value);
        }
예제 #2
0
        public void LoadKeyValuePairsFromCommandLineArgumentsWithSwitchMappings()
        {
            var args = new string[]
            {
                "-K1=Value1",
                "--Key2=Value2",
                "/Key3=Value3",
                "--Key4", "Value4",
                "/Key5", "Value5",
                "/Key6=Value6"
            };
            var switchMappings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "-K1", "LongKey1" },
                { "--Key2", "SuperLongKey2" },
                { "--Key6", "SuchALongKey6" }
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args, switchMappings);

            cmdLineConfig.Load();

            Assert.Equal("Value1", cmdLineConfig.Get("LongKey1"));
            Assert.Equal("Value2", cmdLineConfig.Get("SuperLongKey2"));
            Assert.Equal("Value3", cmdLineConfig.Get("Key3"));
            Assert.Equal("Value4", cmdLineConfig.Get("Key4"));
            Assert.Equal("Value5", cmdLineConfig.Get("Key5"));
            Assert.Equal("Value6", cmdLineConfig.Get("SuchALongKey6"));
        }
예제 #3
0
        public void LoadKeyValuePairsFromCommandLineArgumentsWithSwitchMappings()
        {
            var args = new string[]
                {
                    "-K1=Value1",
                    "--Key2=Value2",
                    "/Key3=Value3",
                    "--Key4", "Value4",
                    "/Key5", "Value5",
                    "/Key6=Value6"
                };
            var switchMappings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "-K1", "LongKey1" },
                    { "--Key2", "SuperLongKey2" },
                    { "--Key6", "SuchALongKey6"}
                };
            var cmdLineConfig = new CommandLineConfigurationProvider(args, switchMappings);

            cmdLineConfig.Load();

            Assert.Equal("Value1", cmdLineConfig.Get("LongKey1"));
            Assert.Equal("Value2", cmdLineConfig.Get("SuperLongKey2"));
            Assert.Equal("Value3", cmdLineConfig.Get("Key3"));
            Assert.Equal("Value4", cmdLineConfig.Get("Key4"));
            Assert.Equal("Value5", cmdLineConfig.Get("Key5"));
            Assert.Equal("Value6", cmdLineConfig.Get("SuchALongKey6"));
        }
 public IotHubExportImport(CommandLineConfigurationProvider cmdConfig)
 {
     this.m_FromIotHubConnStr = cmdConfig.GetArgument("migrateiothub");
     this.m_ToIotHubConnStr   = cmdConfig.GetArgument("to");
     this.m_AccountName       = cmdConfig.GetArgument("acc");
     this.m_Key = cmdConfig.GetArgument("key");
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdConfig"></param>
        private static void GetFeedback(CommandLineConfigurationProvider cmdConfig)
        {
            //--listen=Feedback --connStr="" action=""
            string     connStr          = cmdConfig.GetArgument("connStr");
            IHubModule feedbackReceiver = new FeedbackReceiver(connStr: connStr);

            feedbackReceiver.Execute().Wait();
        }
        public void 實例化CommandLineConfigurationProvider(string[] args)
        {
            var provider = new CommandLineConfigurationProvider(args);

            provider.Load();
            provider.TryGet("AppId", out var appId);
            Console.WriteLine($"{args.First()}\r\n" +
                              $"AppId:{appId}");
        }
예제 #7
0
        static void Main(string[] args)
        {
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();

            cmdLineConfig.TryGet("From", out string FromFile);
            cmdLineConfig.TryGet("To", out string ToFile);
            if (string.IsNullOrWhiteSpace(FromFile) || string.IsNullOrWhiteSpace(ToFile))
            {
                var path  = Environment.CurrentDirectory;
                var input = File.ReadAllText($@"{path}\text\TestClass.csts");
                RemoveAllCommentStr(input, out string noComments2, out List <string> list2);

                foreach (var comment in list2)
                {
                    Console.WriteLine(comment);
                }
                Console.WriteLine("--------------");
                Console.WriteLine(noComments2);
                Console.WriteLine("没有设置正确参数From(来源文件夹)和To(目标文件夹)");
                Console.ReadLine();

                return;
            }


            Console.WriteLine("等待扫描来源文件夹");
            //获得来源文件
            GetFiles(new DirectoryInfo(FromFile), "*.*");
            foreach (var item in sb)
            {
                var newFullFile = item.Replace(FromFile, ToFile);
                var newPath     = Path.GetDirectoryName(newFullFile);
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                //处理文件
                if (!File.Exists(newFullFile) && Path.GetExtension(newFullFile).Contains(".cs"))
                {
                    var file = File.ReadAllText(item);
                    RemoveAllCommentStr(file, out string noComments, out List <string> list);
                    File.WriteAllText(newFullFile, noComments);
                    Console.WriteLine($"处理文件:{newFullFile}");
                }
                else if (!File.Exists(newFullFile) && !Path.GetExtension(newFullFile).Contains(".cs"))
                {
                    File.Copy(item, newFullFile);
                    Console.WriteLine($"复制:{newFullFile}");
                }
            }
            Console.WriteLine("完成");
            Console.ReadLine();
        }
        /// <summary>
        /// Event Listener Cloud to Device
        /// </summary>
        /// <param name="cmdConfig">CommandLineConfigurationProvider</param>
        private static void C2DListen(CommandLineConfigurationProvider cmdConfig)
        {
            string        connStr = cmdConfig.GetArgument("connStr");
            string        action  = cmdConfig.GetArgument("action", false);
            CommandAction commandAction;
            bool          isPressed = Enum.TryParse <CommandAction>(action, true, out commandAction);

            IHubModule devListener = new Cloud2DeviceListener(connStr, commandAction);

            devListener.Execute().Wait();
        }
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="testParameters">The Test Parameter args.</param>
        public TestParameterConfigurationProvider(TestParameters testParameters)
        {
            List <string> args1 = new List <string>();

            foreach (string x in testParameters.Names)
            {
                args1.Add(string.Format("{0}={1}", x, testParameters[x]));
            }

            _instance = new CommandLineConfigurationProvider(args1, null);
        }
예제 #10
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Generating token...");

                CommandLineConfigurationProvider cmdLineConfig = new CommandLineConfigurationProvider(args);

                cmdLineConfig.Load();

                if (!cmdLineConfig.TryGet("clientId", out string clientId))
                {
                    throw new ArgumentException("'clientId' argument must be specified.");
                }

                if (!cmdLineConfig.TryGet("resource", out string resource))
                {
                    throw new ArgumentException("'resource' argument must be specified");
                }

                if (!cmdLineConfig.TryGet("redirectUri", out string redirectUri))
                {
                    throw new ArgumentException("'redirectUri' argument must be specified");
                }

                cmdLineConfig.TryGet("authority", out string authority);
                cmdLineConfig.TryGet("secret", out string secret);

                string token;
                if (string.IsNullOrEmpty(secret) == true)
                {
                    token = createTokenFromClientCredentials(clientId, resource, redirectUri, authority);
                }
                else
                {
                    token = createTokenFromClientSecret(secret, clientId, resource, redirectUri, authority);
                }
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(token);

                Console.WriteLine("Press Enter to exit the application.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                if (e != null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Acquiring token failed with the following error:" + Environment.NewLine + e);
                }
                Console.ResetColor();
                Console.ReadLine();
            }
        }
예제 #11
0
        protected override (IConfigurationProvider Provider, Action Initializer) LoadThroughProvider(
            TestSection testConfig)
        {
            var args = new List <string>();

            SectionToArgs(args, "", testConfig);

            var provider = new CommandLineConfigurationProvider(args);

            return(provider, () => { });
        }
예제 #12
0
        public void IgnoreWhenAnArgumentCannotBeRecognized()
        {
            var args = new string[]
            {
                "ArgWithoutPrefixAndEqualSign"
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();
            Assert.Empty(cmdLineConfig.GetChildKeys(new string[0], null));
        }
        /// <summary>
        /// Send event Device to Cloud
        /// </summary>
        /// <param name="cmdConfig">CommandLineConfigurationProvider</param>
        private static void D2CSend(CommandLineConfigurationProvider cmdConfig)
        {
            //-send =event -connStr=connection_string -cmdDelay 5 -eventFile c:\temp\eventdata.csv -tempFile c:\jsontemplate.txt
            string     connStr           = cmdConfig.GetArgument("connStr");
            string     cmdDelay          = cmdConfig.GetArgument("cmdDelay");
            string     eventFile         = cmdConfig.GetArgument("eventFile");
            string     templateFile      = cmdConfig.GetArgument("tempFile");
            int        commandDelayInSec = int.Parse(cmdDelay);
            IHubModule devEmu            = new Device2CloudSender(connStr, commandDelayInSec, eventFile, templateFile);

            devEmu.Execute().Wait();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdConfig"></param>
        private static void C2DSend(CommandLineConfigurationProvider cmdConfig)
        {
            //--send=cloud --connstr="" enentfile="" --tempFile=""
            string connStr      = cmdConfig.GetArgument("connStr");
            string eventFile    = cmdConfig.GetArgument("eventFile");
            string templateFile = cmdConfig.GetArgument("tempFile");
            string deviceId     = cmdConfig.GetArgument("deviceId");

            IHubModule devEmu = new Cloud2DeviceSender(connStr, deviceId, eventFile, templateFile);

            devEmu.Execute().Wait();
        }
예제 #15
0
        public void IgnoresOnlyUnknownArgs()
        {
            var args = new string[]
            {
                "foo",
                "/bar=baz"
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();
            Assert.Single(cmdLineConfig.GetChildKeys(new string[0], null));
            Assert.Equal("baz", cmdLineConfig.Get("bar"));
        }
예제 #16
0
        public void OverrideValueWhenKeyIsDuplicated()
        {
            var args = new string[]
            {
                "/Key1=Value1",
                "--Key1=Value2"
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();

            Assert.Equal("Value2", cmdLineConfig.Get("Key1"));
        }
예제 #17
0
        public void ThrowExceptionWhenValueForAKeyIsMissing()
        {
            var args = new string[]
            {
                "--Key1", "Value1",
                "/Key2"     /* The value for Key2 is missing here */
            };
            var expectedMsg   = new FormatException(Resources.FormatError_ValueIsMissing("/Key2")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            var exception = Assert.Throws <FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #18
0
        public void ThrowExceptionWhenAnArgumentCannotBeRecognized()
        {
            var args = new string[]
            {
                "ArgWithoutPrefixAndEqualSign"
            };
            var expectedMsg = new FormatException(
                Resources.FormatError_UnrecognizedArgumentFormat("ArgWithoutPrefixAndEqualSign")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            var exception = Assert.Throws <FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #19
0
        public void IgnoreWhenValueForAKeyIsMissing()
        {
            var args = new string[]
            {
                "--Key1", "Value1",
                "/Key2" /* The value for Key2 is missing here */
            };

            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();
            Assert.Single(cmdLineConfig.GetChildKeys(new string[0], null));
            Assert.Equal("Value1", cmdLineConfig.Get("Key1"));
        }
예제 #20
0
        public void IgnoreWhenShortSwitchNotDefined()
        {
            var args = new string[]
            {
                "-Key1", "Value1",
            };
            var switchMappings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "-Key2", "LongKey2" }
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args, switchMappings);

            cmdLineConfig.Load();
            Assert.Empty(cmdLineConfig.GetChildKeys(new string[0], ""));
        }
예제 #21
0
        /// <summary>
        /// NOT WORKING RIGHT NOW!!!!
        /// </summary>
        /// <param name="args"></param>
        // WARNING: Input Arguments are currentlly not validated!
        // Enter arguments exactly in expected order.
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Genereting token...");
                CommandLineConfigurationProvider cmdLineConfig = new CommandLineConfigurationProvider(args);
                cmdLineConfig.Load();

                string userName;
                if (!cmdLineConfig.TryGet("userName", out userName))
                {
                    throw new Exception("'userName' argument must be specified.");
                }

                string clientId;
                if (!cmdLineConfig.TryGet("clientId", out clientId))
                {
                    throw new Exception("'clientId' argument must be specified.");
                }

                string resource;
                if (!cmdLineConfig.TryGet("resource", out resource))
                {
                    throw new Exception("'resource' argument must be specified");
                }

                string redirectUri;
                if (!cmdLineConfig.TryGet("redirectUri", out redirectUri))
                {
                    throw new Exception("'redirectUri' argument must be specified");
                }

                string authority;
                cmdLineConfig.TryGet("authority", out authority);

                var token = createToken(userName, clientId, resource, redirectUri, authority);


                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(token);
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }
예제 #22
0
        public static IWebHost BuildWebHost(string[] args)
        {
            var cliProvider = new CommandLineConfigurationProvider(args);

            cliProvider.Load();
            cliProvider.TryGet("startup", out var startUpArg);

            return(WebHost.CreateDefaultBuilder(args)
                   .UseStartup(getStartupType())
                   .Build());

            System.Type getStartupType() =>
            startUpArg == "withPublicPath" ? typeof(StartupWithPublicPath) :
            startUpArg == "withStaticFileOpts" ? typeof(StartupWithStaticFileOptions) :
            typeof(Startup);
        }
        /// <summary>
        /// Adds command line arguments as secrets to the secret store.
        /// </summary>
        /// <param name="builder">The secret store to add the command line arguments to.</param>
        /// <param name="arguments">The command line arguments that will be considered secrets.</param>
        /// <param name="name">The unique name to register this provider in the secret store.</param>
        /// <param name="mutateSecretName">The function to mutate the secret name before looking it up.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="builder"/> or <paramref name="arguments"/> is <c>null</c>.</exception>
        public static SecretStoreBuilder AddCommandLine(this SecretStoreBuilder builder, string[] arguments, string name, Func <string, string> mutateSecretName)
        {
            Guard.NotNull(builder, nameof(builder), "Requires a secret store builder to add the command line arguments as secrets to the secret store");
            Guard.NotNull(arguments, nameof(arguments), "Requires a set of command line arguments to be set as secret in the secret store");

            var configProvider = new CommandLineConfigurationProvider(arguments);

            configProvider.Load();

            var secretProvider = new CommandLineSecretProvider(configProvider);

            return(builder.AddProvider(secretProvider, options =>
            {
                options.Name = name;
                options.MutateSecretName = mutateSecretName;
            }));
        }
예제 #24
0
        public void ThrowExceptionWhenShortSwitchNotDefined()
        {
            var args = new string[]
            {
                "-Key1", "Value1",
            };
            var switchMappings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "-Key2", "LongKey2" }
            };
            var expectedMsg   = new FormatException(Resources.FormatError_ShortSwitchNotDefined("-Key1")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args, switchMappings);

            var exception = Assert.Throws <FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
        public static string GetArgument(this CommandLineConfigurationProvider provider, string name, bool isMandatory = true)
        {
            string returnValue;

            if (provider.TryGet(name, out returnValue))
            {
                return(returnValue);
            }
            else if (isMandatory)
            {
                throw new ArgumentException($"'--{name}' command not found. In order to see more details '--help'.");
            }
            else
            {
                return(default(String));
            }
        }
        public void 命令對應()
        {
            string[] args = { "-i=1234567890", "-c=app.json" };

            var map = new Dictionary <string, string>
            {
                { "-i", "AppId" },
                { "-c", "Config" }
            };

            var provider = new CommandLineConfigurationProvider(args, map);

            provider.Load();

            provider.TryGet("AppId", out var appId);
            provider.TryGet("Config", out var configPath);
            Console.WriteLine($"{args.First()}\r\n" +
                              $"AppId:{appId}\r\n" +
                              $"ConfigPath:{configPath}");
        }
예제 #27
0
        public void LoadKeyValuePairsFromCommandLineArgumentsWithoutSwitchMappings()
        {
            var args = new string[]
                {
                    "Key1=Value1",
                    "--Key2=Value2",
                    "/Key3=Value3",
                    "--Key4", "Value4",
                    "/Key5", "Value5"
                };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();

            Assert.Equal("Value1", cmdLineConfig.Get("Key1"));
            Assert.Equal("Value2", cmdLineConfig.Get("Key2"));
            Assert.Equal("Value3", cmdLineConfig.Get("Key3"));
            Assert.Equal("Value4", cmdLineConfig.Get("Key4"));
            Assert.Equal("Value5", cmdLineConfig.Get("Key5"));
        }
예제 #28
0
        public void LoadKeyValuePairsFromCommandLineArgumentsWithoutSwitchMappings()
        {
            var args = new string[]
            {
                "Key1=Value1",
                "--Key2=Value2",
                "/Key3=Value3",
                "--Key4", "Value4",
                "/Key5", "Value5"
            };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();

            Assert.Equal("Value1", cmdLineConfig.Get("Key1"));
            Assert.Equal("Value2", cmdLineConfig.Get("Key2"));
            Assert.Equal("Value3", cmdLineConfig.Get("Key3"));
            Assert.Equal("Value4", cmdLineConfig.Get("Key4"));
            Assert.Equal("Value5", cmdLineConfig.Get("Key5"));
        }
예제 #29
0
        public void IConfigurationProvider_CommandLine()
        {
            var args = new[] { "--name", "SinxHe" };
            var map  = new Dictionary <string, string>
            {
                ["--name"] = "Name"
            };
            var source = new CommandLineConfigurationSource
            {
                Args           = args,
                SwitchMappings = map
            };
            var provider = new CommandLineConfigurationProvider(args, map);

            provider.TryGet("Name", out var name);
            Assert.Null(name);
            provider.Load();
            provider.TryGet("Name", out name);
            Assert.Equal(name, "SinxHe");
        }
        private static void NonChained(string[] args)
        {
            IConfigurationProvider cmdConfig = new CommandLineConfigurationProvider(args);

            cmdConfig.Load();

            IConfigurationProvider jsonConfig = GetJsonConfiguration("appsettings.json");
            string defaultGreeting            = "How are you?";

            jsonConfig.TryGet("greeting", out defaultGreeting);

            string greeting;

            if (!cmdConfig.TryGet("greeting", out greeting))
            {
                greeting = defaultGreeting;
            }

            Console.WriteLine($"{greeting}");
        }
        /// <summary>
        /// Event Listener for IotHub or EventHub
        /// </summary>
        /// <param name="cmdConfig">CommandLineConfigurationProvider</param>
        /// <param name="path">Path for Event Hub</param>
        private static void EventListener(CommandLineConfigurationProvider cmdConfig, string path = null)
        {
            string   connStr       = cmdConfig.GetArgument("connStr");
            string   startTime     = cmdConfig.GetArgument("startTime");
            string   consumerGroup = cmdConfig.GetArgument("consumerGroup", false);
            DateTime time          = Helper.getTime(startTime);

            if (consumerGroup != null)
            {
                IHubModule module = new TeleMetryListener(connStr, path, time, consumerGroup);
                var        t      = module.Execute();

                t.Wait(Timeout.Infinite);
            }
            else
            {
                IHubModule module = new TeleMetryListener(connStr, path, time);
                var        t      = module.Execute();

                t.Wait();
            }
        }
        public void MapperWithDefaultOptionValues()
        {
            var config = new TestConfig {
                Name           = "Anne",
                BirthDate      = new DateTime(1980, 12, 21),
                DeliveryMethod = DeliveryMethod.Standard
            };

            config.DeliveryAddress.Street     = "Main Street";
            config.DeliveryAddress.PostalCode = "10180";
            config.DeliveryAddress.State      = "MyState";

            var cmd = new CmdOptions {
                DeliveryState = "OtherState"
            };

            var sut = new CommandLineConfigurationProvider <CmdOptions, TestConfig>(cmd, mapper => {
                mapper
                .Map(x => x.DeliveryState, x => x.DeliveryAddress.State)
                .Map(x => x.DeliveryPostalCode, x => x.DeliveryAddress.PostalCode)
                .Map(x => x.DeliveryMethod, x => x.DeliveryMethod)
                .Map(x => x.Name, x => x.Name);
            });

            sut.Load();

            string value = null;

            Assert.True(sut.TryGet("TestConfig:DeliveryAddress:State", out value));
            Assert.Equal("OtherState", value);

            //Values not set in CmdOptions are missing in the provider collection. If they exist
            //in a configuration file they will be added by the configuration provider
            Assert.False(sut.TryGet("TestConfig:DeliveryAddress:PostalCode", out value));
            Assert.False(sut.TryGet("TestConfig:DeliveryMethod", out value));
            Assert.False(sut.TryGet("TestConfig:Name", out value));
        }
예제 #33
0
        public void ThrowExceptionWhenValueForAKeyIsMissing()
        {
            var args = new string[]
                {
                    "--Key1", "Value1",
                    "/Key2" /* The value for Key2 is missing here */
                };
            var expectedMsg = new FormatException(Resources.FormatError_ValueIsMissing("/Key2")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            var exception = Assert.Throws<FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #34
0
        public void ThrowExceptionWhenAnArgumentCannotBeRecognized()
        {
            var args = new string[]
                {
                    "ArgWithoutPrefixAndEqualSign"
                };
            var expectedMsg = new FormatException(
                Resources.FormatError_UnrecognizedArgumentFormat("ArgWithoutPrefixAndEqualSign")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            var exception = Assert.Throws<FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #35
0
        public void ThrowExceptionWhenShortSwitchNotDefined()
        {
            var args = new string[]
                {
                    "-Key1", "Value1",
                };
            var switchMappings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "-Key2", "LongKey2" }
                };
            var expectedMsg = new FormatException(Resources.FormatError_ShortSwitchNotDefined("-Key1")).Message;
            var cmdLineConfig = new CommandLineConfigurationProvider(args, switchMappings);

            var exception = Assert.Throws<FormatException>(() => cmdLineConfig.Load());

            Assert.Equal(expectedMsg, exception.Message);
        }
예제 #36
0
        public void OverrideValueWhenKeyIsDuplicated()
        {
            var args = new string[]
                {
                    "/Key1=Value1",
                    "--Key1=Value2"
                };
            var cmdLineConfig = new CommandLineConfigurationProvider(args);

            cmdLineConfig.Load();

            Assert.Equal("Value2", cmdLineConfig.Get("Key1"));
        }