本文整理汇总了C#中AtomicComposition.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition.Dispose方法的具体用法?C# AtomicComposition.Dispose怎么用?C# AtomicComposition.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicComposition
的用法示例。
在下文中一共展示了AtomicComposition.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dispose_AllMethodsShouldThrow
public void Dispose_AllMethodsShouldThrow()
{
var ct = new AtomicComposition();
ct.Dispose();
ExceptionAssert.ThrowsDisposed(ct, () => ct.AddCompleteAction(() => ct = null));
ExceptionAssert.ThrowsDisposed(ct, () => ct.Complete());
ExceptionAssert.ThrowsDisposed(ct, () => ct.SetValue(ct, 10));
object value;
ExceptionAssert.ThrowsDisposed(ct, () => ct.TryGetValue(ct, out value));
}
示例2: AddRevertAction_ShouldExecuteInReverseOrder
public void AddRevertAction_ShouldExecuteInReverseOrder()
{
var ct = new AtomicComposition();
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
ct.AddRevertAction(() => Assert.AreEqual(1, stack.Pop()));
ct.AddRevertAction(() => Assert.AreEqual(2, stack.Pop()));
ct.AddRevertAction(() => Assert.AreEqual(3, stack.Pop()));
ct.Dispose();
Assert.IsTrue(stack.Count == 0);
}
示例3: AddRevertAction_ShouldNotExecuteWhenCompleteted
public void AddRevertAction_ShouldNotExecuteWhenCompleteted()
{
var ct = new AtomicComposition();
bool executed = false;
ct.AddRevertAction(() => executed = true);
ct.Complete();
Assert.IsFalse(executed);
ct.Dispose();
Assert.IsFalse(executed);
}
示例4: SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow
public void SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow()
{
var ct = new AtomicComposition();
var ct2 = new AtomicComposition(ct);
var key = new object();
ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(key, 1));
object value;
Assert.IsFalse(ct2.TryGetValue(key, out value));
Assert.IsFalse(ct.TryGetValue(key, out value));
// remove the inner atomicComposition so the outer one becomes unlocked.
ct2.Dispose();
ct.SetValue(key, 2);
Assert.IsTrue(ct.TryGetValue(key, out value));
Assert.AreEqual(2, value);
}