Ejemplo n.º 1
0
        public static void Run(IEnumerable<string> commandLineArguments, IEnumerable<ArgInfo> defs, Action<int, int> action)
        {
            var args = new NoteArguments(commandLineArguments, defs);
            var note = args.Validation();

            if (!note.IsValid)
            {
                note.Errors.ToList().ForEach(Console.WriteLine);
                return;
            }

            var result = args.Dictionary;

            int x;
            if (!Int32.TryParse(result["x"], out x))
            {
                Console.WriteLine("Could not parse x");
                return;
            }

            int y;
            if (!Int32.TryParse(result["y"], out y))
            {
                Console.WriteLine("Could not parse y");
                return;
            }

            action(x, y);
        }
Ejemplo n.º 2
0
        public void Parse_Rainy_Tests(string args, string err)
        {
            var a = new NoteArguments(args.Split(';'), new List<ArgInfo>());
            var note = new Notification();
            var parsed = a.Parse(note);

            Check.That(note.HasErrors).IsTrue();
            Check.That(note.Errors.Count()).IsEqualTo(1);
            Check.That(note.Errors.First()).IsEqualTo(err);
        }
Ejemplo n.º 3
0
        public void Parse_Happy_Tests(string args, string expected, int expectedCount)
        {
            var a = new NoteArguments(args.Split(';'), new List<ArgInfo>());
            var note = new Notification();
            var parsed = a.Parse(note);

            var expectedParsed = expected.Split(';').Select(x => x.Split('='));

            Check.That(parsed.Count()).IsEqualTo(expectedCount);
            for (var i = 0; i < parsed.Count(); i++)
            {
                Check.That(parsed.ElementAt(i)).ContainsExactly(expectedParsed.ElementAt(i));
            }
            Check.That(note.IsValid).IsTrue();
        }
Ejemplo n.º 4
0
 public void Dictionary_invalid_throws()
 {
     var args = new NoteArguments(new[] {"-x", "42"}, new List<ArgInfo>());
     Check.ThatCode(() => args.Dictionary).Throws<Exception>();
 }