public virtual void TestSettingCtor() { SetOnce <Integer> set = new SetOnce <Integer>(new Integer(5)); Assert.AreEqual(5, set.Get().value); Assert.Throws <AlreadySetException>(() => set.Set(new Integer(7))); }
public virtual void TestSetMultiThreaded() { SetOnce <Integer> set = new SetOnce <Integer>(); SetOnceThread[] threads = new SetOnceThread[10]; Random random = Random; for (int i = 0; i < threads.Length; i++) { threads[i] = new SetOnceThread(random); threads[i].Name = "t-" + (i + 1); threads[i].set = set; } foreach (ThreadJob t in threads) { t.Start(); } foreach (ThreadJob t in threads) { t.Join(); } foreach (SetOnceThread t in threads) { if (t.success) { int expectedVal = Convert.ToInt32(t.Name.Substring(2)); Assert.AreEqual(expectedVal, t.set.Get().value, "thread " + t.Name); } } }
public virtual void TestSettingCtor() { SetOnce <int?> set = new SetOnce <int?>(new int?(5)); Assert.AreEqual(5, (int)set.Get()); set.Set(new int?(7)); }
public virtual void TestSettingCtor() { SetOnce <int?> set = new SetOnce <int?>(new int?(5)); Assert.AreEqual(5, (int)set.Get()); Assert.Throws <SetOnce <int?> .AlreadySetException>(() => { set.Set(new int?(7)); }); }
public virtual void TestEmptyCtor() { SetOnce <Integer> set = new SetOnce <Integer>(); Assert.IsNull(set.Get()); }