public static void TestConfigureAndModified() { IEnumerable <IParameter> someCorrupt = new IParameter[] { new DummyParameter(false), new DummyParameter(true), }; IConversationNodeData data = new DummyConversationNodeData(someCorrupt, Id <NodeTemp> .Parse("745fa8ce-174e-4af7-82b7-17e939e9a475")); Func <ConversationNode <DummyUI>, DummyUI> nodeUI = n => new DummyUI(n, false); Func <ConversationNode <DummyUI>, DummyUI> corruptedUI = n => new DummyUI(n, true); ConversationNode <DummyUI> node = new ConversationNode <DummyUI>(data, nodeUI, corruptedUI); int modifications = 0; int undos = 0; int redos = 0; int expectedRedos = 0; //To ensure Modified is triggered AFTER the modification int expectedUndos = 0; //To ensure Modified is triggered AFTER the modification node.Modified += () => { modifications++; Assert.That(redos, Is.EqualTo(expectedRedos)); Assert.That(undos, Is.EqualTo(expectedUndos)); }; Action redo = () => { redos++; }; Action undo = () => { undos++; }; ConfigureResult configure = node.Configure(n => new SimpleUndoPair() { Redo = redo, Undo = undo }); Assert.That(undos, Is.EqualTo(0)); Assert.That(redos, Is.EqualTo(0)); Assert.That(modifications, Is.EqualTo(0)); expectedRedos = 1; configure.Do(a => a.Redo(), b => Assert.Fail("Unexpected Cancelled configuration")); Assert.That(undos, Is.EqualTo(0)); Assert.That(redos, Is.EqualTo(1)); Assert.That(modifications, Is.EqualTo(1)); expectedUndos = 1; configure.Do(a => a.Undo(), b => Assert.Fail("Unexpected Cancelled configuration")); Assert.That(undos, Is.EqualTo(1)); Assert.That(redos, Is.EqualTo(1)); Assert.That(modifications, Is.EqualTo(2)); ConfigureResult cancelConfigure = node.Configure(n => ConfigureResultNotOk.Cancel); cancelConfigure.Do(a => Assert.Fail("Expected configure result to be Cancel"), b => Assert.That(b, Is.EqualTo(ConfigureResultNotOk.Cancel))); ConfigureResult notApplicableConfigure = node.Configure(n => ConfigureResultNotOk.NotApplicable); notApplicableConfigure.Do(a => Assert.Fail("Expected configure result to be Cancel"), b => Assert.That(b, Is.EqualTo(ConfigureResultNotOk.NotApplicable))); }