public void UnsyncedWillThrow() { var fsm = new FileEventStateMachine(); Assert.Throws <ArgumentOutOfRangeException> (() => fsm.Set("a", 0, 0, false, FileState.Removed)); // Add a busted FileEventData var eventData = new FileEventData { Kind = EventDataKind.Changed, Args = new FileEventArgs(), }; Assert.Throws <ArgumentOutOfRangeException> (() => fsm.Set("a", 0, 0, false, FileState.Removed)); }
public void AddAndRemove() { var fsm = new FileEventStateMachine(); var eventData = new FileEventData { Kind = EventDataKind.Changed, Args = new FileEventArgs("a", false), }; fsm.Queue(eventData); fsm.Set("a", 0, 0, false, FileState.Removed); fsm.RemoveLastEventData("a"); Assert.IsFalse(fsm.TryGet("a", out var state)); fsm.RemoveLastEventData("a"); Assert.IsFalse(fsm.TryGet("a", out state)); }
public void Functionality() { var fsm = new FileEventStateMachine(); FilePath a = "a", b = "b", c = "c"; var eventData = new FileEventData { Kind = EventDataKind.Changed, Args = new FileEventArgs(new [] { a, b, c }, false), }; fsm.Queue(eventData); Assert.AreEqual(false, fsm.TryGet(a, out var state)); fsm.Set(a, 0, 0, false, FileState.Changed); fsm.Set(b, 0, 1, false, FileState.Changed); fsm.Set(c, 0, 2, false, FileState.Changed); Assert.AreEqual(true, fsm.TryGet(a, out state)); AssertState(state, FileState.Changed, 1, 0, 0); Assert.AreEqual(true, fsm.TryGet(b, out state)); AssertState(state, FileState.Changed, 1, 0, 1); Assert.AreEqual(true, fsm.TryGet(c, out state)); AssertState(state, FileState.Changed, 1, 0, 2); eventData = new FileEventData { Kind = EventDataKind.Removed, Args = new FileEventArgs(new [] { b, a, c }, false), }; fsm.Queue(eventData); fsm.Set(a, 1, 1, false, FileState.Removed); fsm.Set(b, 1, 0, false, FileState.Removed); fsm.Set(c, 1, 2, false, FileState.Removed); Assert.AreEqual(true, fsm.TryGet(a, out state)); AssertState(state, FileState.Removed, 2, 1, 1); Assert.AreEqual(true, fsm.TryGet(b, out state)); AssertState(state, FileState.Removed, 2, 1, 0); Assert.AreEqual(true, fsm.TryGet(c, out state)); AssertState(state, FileState.Removed, 2, 1, 2); fsm.RemoveLastEventData(c); Assert.AreEqual(true, fsm.TryGet(a, out state)); AssertState(state, FileState.Removed, 2, 1, 1); Assert.AreEqual(true, fsm.TryGet(b, out state)); AssertState(state, FileState.Removed, 2, 1, 0); Assert.AreEqual(true, fsm.TryGet(c, out state)); AssertState(state, FileState.Changed, 1, 0, 2); fsm.RemoveLastEventData(c); Assert.AreEqual(false, fsm.TryGet(c, out state)); Assert.IsNull(state); void AssertState(FileEventState s, FileState fs, int count, int eventIndex, int fileIndex) { Assert.AreEqual(fs, state.FinalState); Assert.AreEqual(count, state.Indices.Count); if (count == 0) { return; } Assert.AreEqual(eventIndex, state.Indices [count - 1].EventIndex); Assert.AreEqual(fileIndex, state.Indices [count - 1].FileIndex); } }