public void CtorTests() { var list = new CLArguments(); TestList(list, 0, KEY, VALUE, "empty list"); list = new CLArguments(ARG_LIST); TestList(list, ARG_LIST.Length, KEY, VALUE, "from enumerable"); list = new CLArguments(item => item == NOT_EXIST_KEY); TestList(list, 0, NOT_EXIST_KEY, KEY, "from predicate"); CLArguments source = this.Template.Clone(); source.Normalize(); list = new CLArguments(source as IDictionary <string, string[]>); TestList(list, source.Count, KEY, VALUE, "from dictionary", this.Template.Keys.Count); list = new CLArguments( ARG_LIST, Enumerable.Range( (int)'a', (int)'z' - (int)'a' + 1).Select(chr => ((char)chr).ToString())); TestList(list, ARG_LIST.Length, VALUE, KEY, "with latin letters designators", 10); }
public void IndexerGetTest() { CLArguments indexerList = this.Template.Clone(); Assert.IsTrue(indexerList[KEY].Contains(VALUE), "Didn't got right values for key"); }
public void RemoveAtTest() { CLArguments removeList = this.Template.Clone(); removeList.RemoveAt(removeList.IndexOf(VALUE)); Assert.IsFalse(removeList.Contains(VALUE), "Existing item removed, but lasted in the list"); }
public void AddValidateValue() { const string VALID_KEY = "-valid_key"; const string INVALID_VALUE = "-invalud_value"; CLArguments addList = this.Template.Clone(); addList.Add(VALID_KEY, INVALID_VALUE); }
public void CopyToTests() { CLArguments copyToList = this.Template.Clone(); string[] argsArray = new string[copyToList.Count]; copyToList.CopyTo(argsArray, 0); Assert.IsTrue(copyToList.SequenceEqual(argsArray), "Copyed array is equal to args list"); }
public void ClearTest() { CLArguments clearList = this.Template.Clone(); clearList.Clear(); Assert.IsTrue(clearList.Count == 0, "Arg list contain items"); Assert.IsTrue(clearList.Keys.Count == 0, "Arg list contain keys"); }
public void RemoveTest() { CLArguments removeList = this.Template.Clone(); Assert.IsFalse(removeList.Remove(NOT_EXIST_VALUE), "Non-existing item was \"removed\""); Assert.IsTrue(removeList.Remove(VALUE), "Exsting item wasn't removed"); Assert.IsFalse(removeList.Contains(VALUE), "Existing item removed, but lasted in the list"); }
public void ContainsKeyTest() { CLArguments containsList = this.Template.Clone(); Assert.IsTrue(containsList.ContainsKey(KEY), "List does not contains existing key"); Assert.IsFalse(containsList.ContainsKey(VALUE), "List contains existing value as key"); Assert.IsFalse(containsList.ContainsKey(NOT_EXIST_KEY), "List contains non-existing key"); Assert.IsFalse(containsList.ContainsKey(NOT_EXIST_VALUE), "List contains non-existing value as key"); }
public void InsertTest() { CLArguments addList = this.Template.Clone(); int keyIndex = addList.IndexOf(KEY); addList.Insert(keyIndex + 1, NOT_EXIST_VALUE); Assert.AreEqual(NOT_EXIST_VALUE, addList[keyIndex + 1], "Item in the index of list wasn't the added value"); string[] lastValues = addList[KEY]; Assert.IsTrue(addList[KEY].Contains(NOT_EXIST_VALUE), "Added item wasn't in key's values list"); }
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"); }
public void IndexerTryGetValuesTest() { CLArguments indexerList = this.Template.Clone(); string[] values; Assert.IsFalse(indexerList.TryGetValue(NOT_EXIST_KEY, out values), "Got result for non-existing key"); Assert.IsNull(values, "Values was returned for non-exsting key"); Assert.IsTrue(indexerList.TryGetValue(KEY, out values), "Failed to get values for existing key"); Assert.IsTrue(values.SequenceEqual(indexerList[KEY]), "Invalid values for existing key"); }
public void LastIndexOfTest() { CLArguments indexOfList = this.Template.Clone(); Assert.AreEqual(-1, indexOfList.LastIndexOf(NOT_EXIST_KEY), "Found index for non-existing key"); Assert.AreEqual(12, indexOfList.LastIndexOf(DUP_KEY), "Invalid index of \"{0}\"" + DUP_KEY); Assert.AreEqual(3, indexOfList.LastIndexOf(DUP_KEY, 4), "False index for second same key in IndexOf_string_int"); Assert.AreEqual(12, indexOfList.LastIndexOf(DUP_KEY, 14, 3), "False index for key in IndexOf_string_int_int"); Assert.AreEqual(-1, indexOfList.LastIndexOf(DUP_KEY, 11, 5), "Found index for existing key, but out of rage"); }
public void CloneTest() { CLArguments clone = this.Template.Clone(); Assert.IsTrue((clone as IEnumerable <string>).SequenceEqual(this.Template), "Clone isn't equal to source"); Assert.IsTrue(clone.Keys.SequenceEqual(this.Template.Keys), "Clones keys aren't equal to source"); IEnumerable <bool> keyValues = clone.Keys.Select(key => clone[key].SequenceEqual(this.Template[key])); Assert.IsTrue(keyValues.All(isEqual => isEqual), "Some keyed list are inequal"); }
public void IndexerTryGetValueTest() { CLArguments indexerList = this.Template.Clone(); string value; Assert.IsFalse(indexerList.TryGetValue(NOT_EXIST_KEY, out value), "Got result for non-existing key"); Assert.IsNull(value, "Value was returned for non-exsting key"); Assert.IsFalse(indexerList.TryGetValue(KEY, out value), "Got result for existing key, with multi values"); Assert.IsTrue(indexerList.TryGetValue(SINGLE_VALUE_KEY, out value), "Failed to get value for existing single value key"); Assert.AreEqual(indexerList[SINGLE_VALUE_KEY][0], value, "Invalid values for existing key"); }
public void RemoveKeyTest() { CLArguments removeList = this.Template.Clone(); Assert.IsFalse(removeList.RemoveKey(NOT_EXIST_KEY), "Did \"removed\" non-existant key"); Assert.IsTrue(removeList.RemoveKey(KEY), "Didn't removed existant key"); var keyAndValuesExistance = new bool[] { removeList.Contains(KEY), removeList.Contains(VALUE), removeList.Contains(SEC_VALUE), }; Assert.IsTrue(keyAndValuesExistance.All(isContain => !isContain), "Key, or some of it's values still exists in list"); }
public void IndexerSetTest() { const string NEW_VALUE = "new_value"; CLArguments indexerList = this.Template.Clone(); var valuesArr = new string[] { NEW_VALUE }; indexerList[KEY] = valuesArr; Assert.IsTrue(indexerList[KEY].SequenceEqual(valuesArr), "Failed to set existing key"); var notExistValueArr = new string[] { NOT_EXIST_VALUE }; indexerList[NOT_EXIST_KEY] = notExistValueArr; Assert.IsTrue(indexerList.ContainsKey(NOT_EXIST_KEY), "Failed to create new key in set"); Assert.IsTrue(indexerList[NOT_EXIST_KEY].SequenceEqual(notExistValueArr), "Failed to create values for key"); }
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)); } }
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"); }
static void Main(string[] args) { args = new string[] { "not", "keyed", "values", "-dup key", "first dup", "second dup", "-first key", "-second key", "first value", "second value", "-third key", "value", "-dup key", "third dup", "forth dup", }; var managedArgs = new CLArguments(args); foreach (string key in managedArgs.Keys) { string printed = key == CLArguments.NO_KEY ? "Unkeyed" : key; Console.WriteLine(printed + ": "); Console.WriteLine(string.Join("; ", managedArgs[key])); Console.WriteLine(); } Console.ReadLine(); }
public void InsertValidateOutOfRage() { CLArguments addList = this.Template.Clone(); addList.Insert(addList.Count + 1, "value"); }
public void InsertValidateNegative() { CLArguments addList = this.Template.Clone(); addList.Insert(-1, "value"); }
public void InitTests() { this.Template = new CLArguments(ARG_LIST); }
public void IndexerSetValidateNegative() { CLArguments indexerList = this.Template.Clone(); indexerList[-1] = NOT_EXIST_VALUE; }
public void IndexerSetValidateOutOfRange() { CLArguments indexerList = this.Template.Clone(); indexerList[indexerList.Count] = NOT_EXIST_VALUE; }
public void IndexerGetValidateOutOfRange() { CLArguments indexerList = this.Template.Clone(); string item = indexerList[indexerList.Count]; }
public void IndexerGetValidateNegative() { CLArguments indexerList = this.Template.Clone(); string item = indexerList[-1]; }
public void RemoveAtValidateNegative() { CLArguments removeList = this.Template.Clone(); removeList.RemoveAt(-1); }
public void RemoveAtValidateOutOfRage() { CLArguments removeList = this.Template.Clone(); removeList.RemoveAt(removeList.Count); }
public void IndexerGetValidateKey() { CLArguments indexerList = this.Template.Clone(); string[] values = indexerList[NOT_EXIST_KEY]; }