public void OperationValueDictionary_SetItem_Test3() { var xs = new KeyValuePair <OperationValueKey, object> [10]; for (int i = 0; i < xs.Length; i++) { var k = OperationValueKey.Create((Key)((int)Key.A + i)); xs[i] = new KeyValuePair <OperationValueKey, object>(k, i + 1); } for (int k = 0; k < 1000; k++) { var dict1 = new Dictionary <OperationValueKey, object>(); var dict2 = OperationValueDictionary.Empty; var r = new Random(3); for (int i = 0, n = r.Next(xs.Length) + 1; i < n; i++) { var x = xs[r.Next(xs.Length)]; dict1[x.Key] = x.Value; dict2 = dict2.SetItem(x.Key, x.Value); } System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(dict1)); System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(dict2)); CollectionAssert.AreEquivalent(dict1.ToList(), dict2.ToList()); } }
public void OperationValueDictionary_SetItem_Test1() { var dict = OperationValueDictionary.Empty; dict = dict.SetItem(OperationValueKey.Create(Key.A), 1); CollectionAssert.Contains(dict.ToList(), new KeyValuePair <OperationValueKey, object>(OperationValueKey.Create(Key.A), 1)); }
public void OperationValueDictionary_Count_Test2() { var dict = OperationValueDictionary.Empty; dict = dict.SetItem(OperationValueKey.Create(Key.A), 1); Assert.AreEqual(1, dict.Count()); Assert.AreEqual(1, dict.GetItem(OperationValueKey.Create(Key.A))); }
public void OperationValueKey_Serialize_Test() { Assert.AreEqual("\"A\"", JsonConvert.SerializeObject(OperationValueKey.Create(A.A))); Assert.AreEqual("\"B\"", JsonConvert.SerializeObject(OperationValueKey.Create(A.B))); Assert.AreEqual("\"C\"", JsonConvert.SerializeObject(OperationValueKey.Create(A.C))); Assert.AreEqual("\"X\"", JsonConvert.SerializeObject(OperationValueKey.Create(B.A))); Assert.AreEqual("\"Y\"", JsonConvert.SerializeObject(OperationValueKey.Create(B.B))); Assert.AreEqual("\"Z\"", JsonConvert.SerializeObject(OperationValueKey.Create(B.C))); }
public void OperationValueKey_ToString_Test() { Assert.AreEqual("A", OperationValueKey.Create(A.A).ToString()); Assert.AreEqual("B", OperationValueKey.Create(A.B).ToString()); Assert.AreEqual("C", OperationValueKey.Create(A.C).ToString()); Assert.AreEqual("X", OperationValueKey.Create(B.A).ToString()); Assert.AreEqual("Y", OperationValueKey.Create(B.B).ToString()); Assert.AreEqual("Z", OperationValueKey.Create(B.C).ToString()); }
public void OperationValueKey_Equality_Test() { var a = OperationValueKey.Create(A.A); var b = OperationValueKey.Create(B.A); Assert.AreEqual(a, a); Assert.AreEqual(b, b); Assert.AreNotEqual(a, b); Assert.AreNotEqual(b, a); }
// ================ public OperationContext WithValue <TKey>(TKey key, object value) where TKey : struct, IComparable, IFormattable, IConvertible { return(new OperationContext( parent: _parent, cancellationToken: CancellationToken, values: _values.SetItem(OperationValueKey.Create(key), value), created: _created, timeout: _timeout, location: _location )); }
public object GetValue <TKey>(TKey key) where TKey : struct, IComparable, IFormattable, IConvertible { return(_values.GetItem(OperationValueKey.Create(key))); }