Exemplo n.º 1
0
        public void ExecForKey()
        {
            const string command_line = "file1.bin file2.bin -wps \"c:\\Program files 321\\123\" 123 "
                                        + "--in file3.txt file4.txt file5.txt --in file6.txt -o result.bin "
                                        + "-- file7.qwe file8.asd";

            var parser = new CommandLineArgs(command_line.Split(' '));

            var values_   = new List <string>();
            var values_w  = new List <string>();
            var values_p  = new List <string>();
            var values_s  = new List <string>();
            var values_in = new List <string>();
            var values_o  = new List <string>();
            var values__  = new List <string>();

            var values_tst = new List <string>();

            bool Check(string key, List <string> values) => parser.ExecForKey(key, values.Add);

            Assert.That.Value(Check("", values_)).IsTrue().And.Collection(values_).IsEqualTo(new[] { "file1.bin", "file2.bin" });

            Assert.That.Value(Check("w", values_w)).IsTrue().And.Collection(values_w).IsEqualTo(new[] { "c:\\Program files 321\\123", "123" });
            Assert.That.Value(Check("p", values_p)).IsTrue().And.Collection(values_p).IsEqualTo(new[] { "c:\\Program files 321\\123", "123" });
            Assert.That.Value(Check("s", values_s)).IsTrue().And.Collection(values_s).IsEqualTo(new[] { "c:\\Program files 321\\123", "123" });

            Assert.That.Value(Check("in", values_in)).IsTrue().And.Collection(values_in).IsEqualTo(new[] { "file3.txt", "file4.txt", "file5.txt", "file6.txt" });
            Assert.That.Value(Check("o", values_o)).IsTrue().And.Collection(values_o).IsEqualTo(new[] { "result.bin" });

            Assert.That.Value(Check("--", values__)).IsTrue().And.Collection(values__).IsEqualTo(new[] { "file7.qwe", "file8.asd" });

            Assert.That.Value(Check("tst", values_tst)).IsFalse().And.Collection(values_tst).IsEmpty();
        }