Ejemplo n.º 1
0
        public void NotValidExport_CollectionMissing()
        {
            var c = new ExportCommand();

            c.Parse("--uri mongocon --query {}".Split(' '));
            Assert.Equal("mongocon", c.Connection);
            Assert.Equal("{}", c.SearchQueryForExport);
            Assert.Throws <ArgumentException>(() => c.Validate());
        }
Ejemplo n.º 2
0
        public void ValidExport()
        {
            var c = new ExportCommand();

            c.Parse("--uri mongocon --query {} --collection countries".Split(' '));
            Assert.Equal("mongocon", c.Connection);
            Assert.Equal("{}", c.SearchQueryForExport);
            Assert.Equal("countries", (c as ExportCommand).CollectionName);
            c.Validate();
        }
Ejemplo n.º 3
0
        public void Export_Execute_Simple()
        {
            string executable = null;
            string arguments  = null;

            Program.Exec = (cmd, args) => { executable = cmd; arguments = args; return(127); };
            var c = new ExportCommand();

            c.Parse("--uri mongodb://host:28123/database --collection Countries --query {a:1}".Split(' '));
            c.Execute();

            Assert.Equal(ExportCommand.COMMAND, executable);
            Assert.Equal($"--db database --host host:28123 --collection Countries --query {{a:1}} --type json --out {c.TimePrefix}.Countries.Insert.json", arguments);
        }
Ejemplo n.º 4
0
        public void Export_Execute_Atlas()
        {
            string executable = null;
            string arguments  = null;

            Program.Exec = (cmd, args) => { executable = cmd; arguments = args; return(127); };
            var c = new ExportCommand();

            c.Parse("--uri mongodb://user:password@host:28123,host2:28125/database?replicaSet=Atlas1-shard-0&ssl=true true --collection Countries --query {a:1} --authenticationDatabase admin".Split(' '));
            c.Execute();

            Assert.Equal(ExportCommand.COMMAND, executable);
            Assert.Equal($"--db database --host Atlas1-shard-0/host:28123,host2:28125 --username user --password password --ssl --authenticationDatabase admin --collection Countries --query {{a:1}} --type json --out {c.TimePrefix}.Countries.Insert.json", arguments);
        }
Ejemplo n.º 5
0
        public static Command ParseCommand(params string[] args)
        {
            Command result = new HelpCommand();

            // try parse arguments only when they exist
            if (args != null && args.Length > 0)
            {
                try
                {
                    Command     candidate = new HelpCommand();
                    CommandType cmdType   = Enum.Parse <CommandType>(args[0], true);
                    switch (cmdType)
                    {
                    case CommandType.Help:
                        candidate = new HelpCommand();
                        break;

                    case CommandType.Import:
                        candidate = new ImportCommand();
                        break;

                    case CommandType.Export:
                        candidate = new ExportCommand();
                        break;

                    default: throw new NotImplementedException($"Command {cmdType} not implemented yet");
                    }
                    candidate.CommandType = cmdType;
                    candidate.Parse(args);
                    result = candidate;
                }
                catch (Exception ex)
                {
                    Console(ex.Message);
#if DEBUG
                    Console(ex.StackTrace);
#endif
                }
            }
            return(result);
        }