private void MultiThreadedSyncedCommandifiedListAccessTest_ThreadA(CommandifiedList <string> list, WaitHandle waitHandle, Action <Exception> handler) { Console.WriteLine("Thread A started"); try { var random = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < 500; i++) { //Console.WriteLine("\tThread A: iteration: {0}", i); var countBefore = list.Count; var index = random.Next(0, countBefore); list.RemoveAt(index); Assert.AreEqual(countBefore - 1, list.Count); CQManager.UndoLastCommand(); Assert.AreEqual(countBefore, list.Count); Thread.Sleep(1); CQManager.RedoLastCommand(); Assert.AreEqual(countBefore - 1, list.Count); Thread.Sleep(2); CQManager.UndoLastCommand(); Assert.AreEqual(countBefore, list.Count); } } catch (Exception e) { handler(e); } finally { ((AutoResetEvent)waitHandle).Set(); } Console.WriteLine("Thread A ended"); }
public void CommandifiedListRemoveTest() { Guid sessionId = Guid.NewGuid(); CQManager.ActivateCommandQueueStack(sessionId); CommandifiedList <string> toTest = new CommandifiedList <string>() { "Foo", "Bar" }; Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); // perform a remove operation. We'll undo this later on. toTest.Remove("Foo"); Assert.AreEqual(1, toTest.Count); Assert.AreEqual("Bar", toTest[0]); // undo operation. CQManager.UndoLastCommand(); Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); toTest.RemoveAt(1); Assert.AreEqual(1, toTest.Count); Assert.AreEqual("Foo", toTest[0]); // undo operation. CQManager.UndoLastCommand(); Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); CQManager.ActivateCommandQueueStack(Guid.Empty); }
public void CommandifiedListRemoveTest() { Guid sessionId = Guid.NewGuid(); CQManager.ActivateCommandQueueStack(sessionId); CommandifiedList<string> toTest = new CommandifiedList<string>() { "Foo", "Bar" }; Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); // perform a remove operation. We'll undo this later on. toTest.Remove("Foo"); Assert.AreEqual(1, toTest.Count); Assert.AreEqual("Bar", toTest[0]); // undo operation. CQManager.UndoLastCommand(); Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); toTest.RemoveAt(1); Assert.AreEqual(1, toTest.Count); Assert.AreEqual("Foo", toTest[0]); // undo operation. CQManager.UndoLastCommand(); Assert.AreEqual(2, toTest.Count); Assert.AreEqual("Foo", toTest[0]); Assert.AreEqual("Bar", toTest[1]); CQManager.ActivateCommandQueueStack(Guid.Empty); }