public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method CopyTo in the KeyCollection 1"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("str1", "Test1"); dic.Add("str2", "Test2"); Dictionary<string, string>.KeyCollection keys = new Dictionary<string, string>.KeyCollection(dic); string[] TKeys = new string[SIZE]; keys.CopyTo(TKeys, 0); string strKeys = null; for (int i = 0; i < TKeys.Length; i++) { if (TKeys[i] != null) { strKeys += TKeys[i].ToString(); } } if (TKeys[0].ToString() != "str1" || TKeys[1].ToString() != "str2" || strKeys != "str1str2") { TestLibrary.TestFramework.LogError("001", "the ExpecResult is not the ActualResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method CopyTo in the ValueCollection 2"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("str1", "Test1"); dic.Add("str2", "Test2"); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = new string[SIZE]; values.CopyTo(TVals, 5); string strVals = null; for (int i = 0; i < TVals.Length; i++) { if (TVals[i] != null) { strVals += TVals[i].ToString(); } } if (TVals[5].ToString() != "Test1" || TVals[6].ToString() != "Test2" || strVals != "Test1Test2") { TestLibrary.TestFramework.LogError("003", "the ExpecResult is not the ActualResult"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e); retVal = false; } return retVal; }
public void Dictionary_CopyTo_requires_destination_of_sufficient_size() { IDictionary<int, string> dictionary = new Dictionary<int, string>(); dictionary[1] = "foo"; dictionary[2] = "foo"; dictionary[3] = "foo"; var destination = new KeyValuePair<int, string>[2]; dictionary.CopyTo(destination, 0); }
public void CopyTo_KeyCollectionWithOneElementDictionary_FirstElementEqualsOne() { var dictionary = new Dictionary<int, int>(); dictionary.Add(1, 1); var keyCollection = new Dictionary<int, int>.KeyCollection(dictionary); // int[] keys = new int[1]; keyCollection.CopyTo(keys, 0); Assert.Equal(1, keys[0]); }
public void CopyTo_KeyCollectionWithOneElementDictionary_FirstElementEqualsOne() { var dictionary = new Dictionary<int, int>(); dictionary.Add(1, 1); var valueCollection = new Dictionary<int, int>.ValueCollection(dictionary); // int[] values = new int[1]; valueCollection.CopyTo(values, 0); Assert.Equal(1, values[0]); }
public void copy_multiple_keys_with_some_misses() { var source = new Dictionary<string, object>(); source.Add("a", 1); //source.Add("b", 1); source.Add("c", 3); var destination = new Dictionary<string, object>(); source.CopyTo(destination, "a", "b", "c"); destination["a"].ShouldBe(1); destination.ContainsKey("b").ShouldBeFalse(); destination["c"].ShouldBe(3); }
public void copy_multiple_keys_that_all_exist_in_source() { var source = new Dictionary<string, object>(); source.Add("a", 1); source.Add("b", 2); source.Add("c", 3); var destination = new Dictionary<string, object>(); source.CopyTo(destination, "a", "b", "c"); destination["a"].ShouldBe(1); destination["b"].ShouldBe(2); destination["c"].ShouldBe(3); }
public bool PosTest1() { bool retVal = true; // Add your scenario description here TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method ICollection.CopyTo(System.Array,System.Int32) ."); try { ICollection<KeyValuePair<String, String>> dictionary = new Dictionary<String, String>(); KeyValuePair<string, string> kvp1 = new KeyValuePair<String, String>("txt", "notepad.exe"); KeyValuePair<string, string> kvp2 = new KeyValuePair<String, String>("bmp", "paint.exe"); KeyValuePair<string, string> kvp3 = new KeyValuePair<String, String>("dib", "paint.exe"); KeyValuePair<string, string> kvp4 = new KeyValuePair<String, String>("rtf", "wordpad.exe"); dictionary.Add(kvp1); dictionary.Add(kvp2); dictionary.Add(kvp3); dictionary.Add(kvp4); KeyValuePair<string, string>[] kvpArray = new KeyValuePair<string, string>[dictionary.Count]; dictionary.CopyTo(kvpArray, 0); bool actual = (kvpArray[0].Equals(kvp1)) && (kvpArray[1].Equals(kvp2)) && (kvpArray[2].Equals(kvp3)) && (kvpArray[3].Equals(kvp4)); bool expected = true; if (actual != expected) { TestLibrary.TestFramework.LogError("001.1", "Method ICollectionCopyTo Err."); TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] actual = " + actual + ", expected = " + expected); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public void CopyToTest() { var Test = new Dictionary<string, int>(); var Test2 = new Dictionary<string, int>(); Test.Add("Q", 4); Test.Add("Z", 2); Test.Add("C", 3); Test.Add("A", 1); Test.CopyTo(Test2); string Value = ""; int Value2 = 0; foreach (string Key in Test2.Keys.OrderBy(x => x)) { Value += Key; Value2 += Test2[Key]; } Assert.Equal("ACQZ", Value); Assert.Equal(10, Value2); }
public bool NegTest4() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest4:The number of elements in the source Dictionary.ValueCollection is greater than the available space from index to the end of the destination array"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("str1", "Test1"); dic.Add("str1", "Test1"); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = new string[SIZE]; int index = SIZE - 1; values.CopyTo(TVals, index); TestLibrary.TestFramework.LogError("N007", "The ExpectResult should throw exception but the ActualResult not throw exception"); retVal = false; } catch (ArgumentException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N008", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool NegTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest3:The argument index is larger than array length"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("str1", "Test1"); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = new string[SIZE]; int index = SIZE + 1; values.CopyTo(TVals, index); TestLibrary.TestFramework.LogError("N005", "The argument index is larger than array length but not throw exception"); retVal = false; } catch (ArgumentException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N006", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool NegTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest2:The argument index is less than zero"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = new string[SIZE]; int index = -1; values.CopyTo(TVals, index); TestLibrary.TestFramework.LogError("N003", "The argument index is less than zero but not throw exception"); retVal = false; } catch (ArgumentOutOfRangeException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N004", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool NegTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest1:The argument array is null"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = null; values.CopyTo(TVals, 0); TestLibrary.TestFramework.LogError("N001", "The argument array is null but not throw exception"); retVal = false; } catch (ArgumentNullException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("N002", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3:Invoke the method CopyTo in the ValueCollection 3"); try { Dictionary<string, string> dic = new Dictionary<string, string>(); Dictionary<string, string>.ValueCollection values = new Dictionary<string, string>.ValueCollection(dic); string[] TVals = new string[SIZE]; values.CopyTo(TVals, 0); for (int i = 0; i < TVals.Length; i++) { if (TVals[i] != null) { TestLibrary.TestFramework.LogError("005", "the ExpecResult is not the ActualResult"); retVal = false; } } } catch (Exception e) { TestLibrary.TestFramework.LogError("006", "Unexpect exception:" + e); retVal = false; } return retVal; }
public bool NegTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("NegTest1: ArgumentNullException is not thrown when array is null ref."); try { ICollection<KeyValuePair<String, String>> dictionary = new Dictionary<String, String>(); KeyValuePair<string, string> kvp1 = new KeyValuePair<String, String>("txt", "notepad.exe"); KeyValuePair<string, string> kvp2 = new KeyValuePair<String, String>("bmp", "paint.exe"); KeyValuePair<string, string> kvp3 = new KeyValuePair<String, String>("dib", "paint.exe"); KeyValuePair<string, string> kvp4 = new KeyValuePair<String, String>("rtf", "wordpad.exe"); dictionary.Add(kvp1); dictionary.Add(kvp2); dictionary.Add(kvp3); dictionary.Add(kvp4); KeyValuePair<string, string>[] kvpArray = null; dictionary.CopyTo(kvpArray, 0); TestLibrary.TestFramework.LogError("101.1", "ArgumentNullException is not thrown."); retVal = false; } catch (ArgumentNullException) { } catch (Exception e) { TestLibrary.TestFramework.LogError("101.2", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }