public void ParseCommandLine_OneSlashStyleCommandLineOptionWithNoArguments_ReturnsMatchingKey()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /Help";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            Assert.IsTrue(commandLineArgs.ContainsKey("Help"));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var commandLineArgs = new ParseCommandLine(Environment.CommandLine);
            if (TheHelpTextShouldBeShown(commandLineArgs))
            {
                ShowHelp();
                return;
            }

            var outputPath = commandLineArgs["output"][0];
            var texturesPath = commandLineArgs.GetFirstOrSubstitute("textures", "");
            var rows = commandLineArgs.GetFirstOrSubstitute("rows", 7);
            var cols = commandLineArgs.GetFirstOrSubstitute("cols", 7);
            var jiggleX = commandLineArgs.GetFirstOrSubstitute("jiggleX", 40);
            var jiggleY = commandLineArgs.GetFirstOrSubstitute("jiggleY", 40);
            var numberOfImages = commandLineArgs.GetFirstOrSubstitute("numberOfImages", 1);
            var colours = commandLineArgs.GetFirstOrSubstitute("colours", "#C5C9C7,#D4DAE1,#DEE1DD,#EDF0F1,#C7D8E4,#92ADD9,#FDE818,#A94637"); //colours inspired by Ben Nicholson's June 1937

            var screenHeight = (int)SystemParameters.PrimaryScreenHeight;
            var screenWidth = (int)SystemParameters.PrimaryScreenWidth;

            var triangleGrid = new TriangleGrid(texturesPath, colours, rows, cols, jiggleX, jiggleY, screenWidth, screenHeight);
            for (var i = 0; i <= numberOfImages; i++)
            {
                var fileName = string.Format("{0}.jpg", i);
                var outputFileName = Path.Combine(outputPath, fileName);
                triangleGrid.Draw(outputFileName);
            }
        }
Exemplo n.º 3
0
        private static bool TheHelpTextShouldBeShown(ParseCommandLine commandLineArgs)
        {
            if (commandLineArgs.ContainsKey("help") || commandLineArgs.ContainsKey("?")) return true;
            if (!commandLineArgs.ContainsKey("output")) return true;

            var outputFolder = commandLineArgs["output"][0];
            return !Directory.Exists(outputFolder);
        }
        public void GetFirstOrSubstitute_KeyPresent_ReturnsArgument()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /key=value";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            var actual = commandLineArgs.GetFirstOrSubstitute("Key", "FOO");
            Assert.AreEqual("value", actual);
        }
        public void GetFirstOrSubstitute_IlegalCastArgument_ReturnsSubstituteValue()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /key=NotANumber";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            int actual = commandLineArgs.GetFirstOrSubstitute("key", 2);
            Assert.AreEqual(2, actual);
        }
        public void ParseCommandLine_OneSlashStyleCommandLineOptionWithEqualsStyleArgument_ReturnsMatchingKeyAndValue()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /key=value";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            var actual = commandLineArgs["key"].ToList();
            var expected = new List<string> { "value" };
            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void ParseCommandLine_TwoCommandLineOptionWithDifferentKeys_ReturnsMatchingKeysAndValues()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /key1=value1 /key2=value2";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            var actualFirstKey = commandLineArgs["key1"].ToList();
            var expectedFirstKey = new List<string> { "value1" };
            CollectionAssert.AreEquivalent(expectedFirstKey, actualFirstKey);

            var actualSecondKey = commandLineArgs["key2"].ToList();
            var expectedSecondKey = new List<string> { "value2" };
            CollectionAssert.AreEquivalent(expectedSecondKey, actualSecondKey);
        }
        public void ParseCommandLine_TwoCommandLineOptionWithSameKeys_ReturnsMatchingKeyAndValues()
        {
            const string testCommandLine = @"c:\foo\ProgramName.exe /key=value1 /key=value2";
            var commandLineArgs = new ParseCommandLine(testCommandLine);

            var actual = commandLineArgs["key"].ToList();
            var expected = new List<string> { "value1", "value2" };
            CollectionAssert.AreEquivalent(expected, actual);
        }