JD2022-TU1/main/tools/apps/TRec/Tests/TapeUndoerTests.cs

67 lines
2 KiB
C#

using System;
using System.Linq;
using JD.Application.Actions;
using JD.Timeline.Document;
using TeaBox;
using TeaBox.ObjectModel.Transactions;
using NUnit.Framework;
using JD.Serialization;
using Action = System.Action;
namespace TRecTests
{
[TestFixture]
public class TapeUndoerTests
{
[Test]
public void Test_undoer_can_restore_the_previous_state_of_the_tape()
{
var tape = new Tape();
var undoer = new TapeUndoer(tape, new CommandStack(), new DummyModerator());
AssertClipsAre(tape);
tape.CreateAndAddClip(typeof(AlphaClip));
tape.CreateAndAddClip(typeof(TranslationClip));
AssertClipsAre(tape, typeof(AlphaClip), typeof(TranslationClip));
undoer.CommandStack.Undo();
AssertClipsAre(tape, typeof(AlphaClip));
undoer.CommandStack.Undo();
AssertClipsAre(tape);
}
[Test]
public void Test_undoer_can_redo_operations()
{
var tape = new Tape();
var undoer = new TapeUndoer(tape, new CommandStack(), new DummyModerator());
AssertClipsAre(tape);
tape.CreateAndAddClip(typeof(AlphaClip));
tape.CreateAndAddClip(typeof(TranslationClip));
AssertClipsAre(tape, typeof(AlphaClip), typeof(TranslationClip));
undoer.CommandStack.Undo();
undoer.CommandStack.Undo();
undoer.CommandStack.Redo();
undoer.CommandStack.Redo();
AssertClipsAre(tape, typeof(AlphaClip), typeof(TranslationClip));
}
private void AssertClipsAre(Tape tape, params Type[] types)
{
Assert.That(tape.Clips.Select(clip => clip.GetType()).SequenceEqual(types));
}
private class DummyModerator : IModerator
{
public void TriggerAction()
{
Execute?.Invoke();
}
public event Action Execute;
}
}
}