public void Add_Key_Value_Pair() { var pvs = new PersistentVariablesSource(); var kvp = new KeyValuePair <string, VariablesGroup>("theKey", new VariablesGroup()); pvs.Add(kvp); Assert.That(pvs.Contains(new KeyValuePair <string, VariablesGroup>(kvp.Key, kvp.Value))); }
public void Add_Item_With_Illegal_Name_Should_Throw() { var pvs = new PersistentVariablesSource(); var vg = new VariablesGroup(); // Name must not be empty Assert.That(code: () => vg.Add(string.Empty, new IntVariable(1)), Throws.ArgumentException); Assert.That(code: () => pvs.Add(string.Empty, vg), Throws.ArgumentException); }
public void Copy_To_Array() { var pvs = new PersistentVariablesSource(); var kvp1 = new KeyValuePair <string, VariablesGroup>("key1", new VariablesGroup()); var kvp2 = new KeyValuePair <string, VariablesGroup>("key2", new VariablesGroup()); pvs.Add(kvp1); pvs.Add(kvp2); var array = new KeyValuePair <string, VariablesGroup> [pvs.Count]; pvs.CopyTo(array, 0); Assert.That(pvs.Count, Is.EqualTo(array.Length)); for (var i = 0; i < array.Length; i++) { Assert.That(pvs.ContainsKey(array[i].Key)); } }
public void Clear_All_Items() { var pvs = new PersistentVariablesSource(); var kvp = new KeyValuePair <string, VariablesGroup>("theKey", new VariablesGroup()); pvs.Add(kvp); pvs.Clear(); Assert.That(pvs.Count, Is.EqualTo(0)); }
public void Remove_Item() { var pvs = new PersistentVariablesSource(); var kvp = new KeyValuePair <string, VariablesGroup>("theKey", new VariablesGroup()); pvs.Add(kvp); pvs.Remove(kvp); Assert.That(pvs.Count, Is.EqualTo(0)); Assert.That(pvs.Remove("non-existent"), Is.EqualTo(false)); }
public void Shallow_Copy() { var pvs = new PersistentVariablesSource(); var kvp1 = new KeyValuePair <string, IVariable>("theKey1", new ObjectVariable("123")); var kvp2 = new KeyValuePair <string, IVariable>("theKey2", new FloatVariable(987.654f)); var vg1 = new VariablesGroup { kvp1 }; var vg2 = new VariablesGroup { kvp2 }; pvs.Add(vg1.First().Key, vg1); pvs.Add(vg2.First().Key, vg2); var pvsCopy = pvs.Clone(); Assert.That(pvsCopy.Count, Is.EqualTo(pvs.Count)); Assert.That(pvsCopy.Values, Is.EquivalentTo(pvs.Values)); Assert.That(pvsCopy.Keys, Is.EquivalentTo(pvs.Keys)); }
public void KeyValuePairs_By_Enumerators() { var pvs = new PersistentVariablesSource(); var kvp = new KeyValuePair <string, VariablesGroup>("theKey", new VariablesGroup()); pvs.Add(kvp); var kvpFromEnumerator = pvs.FirstOrDefault(keyValuePair => keyValuePair.Key.Equals("theKey")); // Test GetEnumerator() foreach (var keyValuePair in pvs) { Assert.That(keyValuePair, Is.EqualTo(kvp)); } // Test IEnumerator<KeyValuePair<string, VariablesGroup>> Assert.That(kvpFromEnumerator, Is.EqualTo(kvp)); }
public void Add_And_Get_Items() { const string groupName1 = "global"; const string groupName2 = "secret"; var pvs = new PersistentVariablesSource(); var vg1 = new VariablesGroup(); var vg2 = new VariablesGroup(); pvs.Add(groupName1, vg1); pvs[groupName2] = vg2; Assert.That(pvs.Count, Is.EqualTo(2)); Assert.That(pvs[groupName1], Is.EqualTo(vg1)); Assert.That(pvs[groupName2], Is.EqualTo(vg2)); Assert.That(pvs.Keys.Count, Is.EqualTo(2)); Assert.That(pvs.ContainsKey(groupName1)); Assert.That(pvs.Values.Count, Is.EqualTo(2)); Assert.That(pvs.Values.Contains(vg1)); Assert.That(pvs.Values.Contains(vg2)); Assert.That(pvs.ContainsKey(groupName2)); Assert.That(pvs.TryGetValue(groupName1, out _), Is.True); Assert.That(pvs.TryGetValue(groupName1 + "False", out _), Is.False); }