Exemplo n.º 1
0
        public void AddTest()
        {
            const string TO_LAST_KEY             = "value_to_the_last_key";
            const string ADDED_LONE_KEY          = "-added_lone_key";
            const string ADDED_TO_EXISTING_VALUE = "added_to_existing_value";
            const string ADDED_WITH_VALUE_KEY    = "-added_with_value_key";
            const string ADDED_TO_MISSING_KEY    = "added_to_missing_key";

            CLArguments addList = this.Template.Clone();
            string      lastKey = CLArguments.NO_KEY;

            for (int i = addList.Count - 1; i >= 0; i--)
            {
                if (addList.IsKey(addList[i]))
                {
                    lastKey = addList[i];
                    break;
                }
            }

            addList.Add(TO_LAST_KEY);

            Assert.AreEqual(TO_LAST_KEY, addList[addList.Count - 1],
                            "Last item in list wasn't the added value");

            string[] lastValues = addList[lastKey];
            Assert.AreEqual(TO_LAST_KEY, lastValues[lastValues.Length - 1],
                            "Last item in last key's values list wasn't teh added value");

            addList.Add(ADDED_LONE_KEY);
            Assert.AreEqual(ADDED_LONE_KEY, addList[addList.Count - 1],
                            "Last item isn't the added key");
            Assert.IsTrue(addList.IsKey(addList[addList.Count - 1]),
                          "Last key isn't considered as a key");

            addList.Add(ADDED_LONE_KEY, ADDED_TO_EXISTING_VALUE);
            Assert.IsTrue(addList[ADDED_LONE_KEY].Any(),
                          "Existing key doesn't contain values");
            Assert.AreEqual(ADDED_TO_EXISTING_VALUE,
                            addList[ADDED_LONE_KEY][addList[ADDED_LONE_KEY].Length - 1],
                            "Last value of existing key is invalid");

            addList.Add(ADDED_WITH_VALUE_KEY, ADDED_TO_MISSING_KEY);
            Assert.IsTrue(addList.ContainsKey(ADDED_WITH_VALUE_KEY),
                          "New key doesn't exist");
            Assert.IsTrue(addList[ADDED_WITH_VALUE_KEY].Length == 1,
                          "New key have incorrent number of values");
            Assert.AreEqual(ADDED_TO_MISSING_KEY, addList[ADDED_WITH_VALUE_KEY][0],
                            "New key doesn't contains the correct value");
        }
Exemplo n.º 2
0
        private void TestList(
            CLArguments list,
            int expectedSize,
            string keyExample,
            string valueExample,
            string listName,
            int?keyCount = null)
        {
            Assert.AreEqual(expectedSize, list.Count,
                            string.Format("Size mismatch for '{0}'", listName));
            Assert.IsTrue(list.IsKey(keyExample),
                          string.Format("Misidentified key for '{0}'", listName));
            Assert.IsFalse(list.IsKey(valueExample),
                           string.Format("Misidentified value for '{0}'", listName));

            if (keyCount.HasValue)
            {
                Assert.AreEqual(keyCount, list.Keys.Count,
                                string.Format("Key count mismatch for '{0}'", listName));
            }
        }
Exemplo n.º 3
0
        public void PropertiesTests()
        {
            CLArguments propList = this.Template.Clone();

            HashSet <string> keys   = new HashSet <string>(ARG_LIST.Where(item => propList.IsKey(item)));
            HashSet <string> values = new HashSet <string>(ARG_LIST.Where(item => !propList.IsKey(item)));

            IEnumerable <string> listValues = from valueList in propList.Values
                                              from value in valueList
                                              select value;

            keys.Add(CLArguments.NO_KEY);

            // Checking count
            Assert.AreEqual(ARG_LIST.Length, propList.Count,
                            "Count mismatch");
            Assert.IsTrue((keys.Count == propList.Keys.Count) &&
                          propList.Keys.All(key => keys.Contains(key)),
                          "Keys property isn't match to keys");
            Assert.IsTrue(listValues.All(value => values.Contains(value)),
                          "Values mismatch");
        }