public void SelectBookmark(bool nullMachine, bool selectEvent) { // Setup HistoryEvent historyEvent = null; MainViewModel viewModel = SetupViewModel(1); _machine.OpenFromFile(_mockFileSystem.Object); _machine.AddBookmark(false); historyEvent = _machine.History.CurrentEvent; viewModel.PromptForBookmark += (sender, args) => { args.SelectedBookmark = selectEvent ? historyEvent : null; }; TestHelpers.Run(_machine, 1000); _machine.AddBookmark(false); // Act viewModel.BrowseBookmarksCommand.Execute(nullMachine ? null : _machine); // Verify if (!nullMachine && selectEvent) { Assert.AreEqual(historyEvent, _machine.History.CurrentEvent); } else { Assert.AreNotEqual(historyEvent, _machine.History.CurrentEvent); } }
public void Setup() { _bookmarkTicks = new List <UInt64>(); LocalMachineTests machineTests = new LocalMachineTests(); machineTests.Setup(); using (LocalMachine machine = machineTests.CreateMachine()) { RunForAWhile(machine); machine.Key(Keys.A, true); RunForAWhile(machine); machine.Key(Keys.A, false); RunForAWhile(machine); machine.LoadDisc(0, null); RunForAWhile(machine); machine.LoadTape(null); RunForAWhile(machine); machine.AddBookmark(false); _bookmarkTicks.Add(machine.Ticks); RunForAWhile(machine); machine.AddBookmark(false); _bookmarkTicks.Add(machine.Ticks); Run(machine, 4000000); _finalHistoryEvent = machine.History.CurrentEvent; } }
static public LocalMachine CreateTestMachine() { Mock <IFileSystem> mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict); mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString())); mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString())); mockFileSystem.Setup(fileSystem => fileSystem.FileLength(AnyString())).Returns(100); MockTextFile mockTextFile = new MockTextFile(); mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile); LocalMachine machine = LocalMachine.New("test", null); // For consistency with automated builds, use all zero ROMs. byte[] zeroROM = new byte[0x4000]; machine.Core.SetLowerROM(zeroROM); machine.Core.SetUpperROM(0, zeroROM); machine.Core.SetUpperROM(7, zeroROM); machine.Core.IdleRequest = () => CoreRequest.RunUntil(machine.Core.Ticks + 1000); RunForAWhile(machine); machine.Key(Keys.A, true); RunForAWhile(machine); machine.Key(Keys.A, false); RunForAWhile(machine); machine.LoadDisc(0, null); RunForAWhile(machine); machine.LoadTape(null); RunForAWhile(machine); machine.AddBookmark(false); RunForAWhile(machine); machine.AddBookmark(false); RunForAWhile(machine); return(machine); }
public void SeekToLastBookmark(bool createBookmark) { // Setup using (LocalMachine machine = LocalMachine.New("test", null)) { machine.Core.IdleRequest = () => CoreRequest.RunUntil(machine.Core.Ticks + 1000); machine.Auditors += _mockAuditor.Object; if (createBookmark) { RunForAWhile(machine); machine.AddBookmark(false); } UInt64 ticks = machine.Core.Ticks; HistoryEvent bookmarkEvent = machine.History.CurrentEvent; byte[] state = machine.Core.GetState(); RunForAWhile(machine); // Act machine.JumpToMostRecentBookmark(); // Verify Assert.AreEqual(machine.History.CurrentEvent, bookmarkEvent); Assert.AreEqual(machine.Core.Ticks, ticks); Assert.AreEqual(state, machine.Core.GetState()); if (createBookmark) { _mockAuditor.Verify(a => a(It.Is <CoreAction>(c => c.Type == CoreRequest.Types.LoadCore && c.Ticks == ticks)), Times.Once); } else { _mockAuditor.Verify(a => a(It.Is <CoreAction>(c => c.Type == CoreRequest.Types.Reset && c.Ticks == 0)), Times.Once); } } }
public void Open() { // Setup _mockTextFile.Clear(); _machine.Persist(_mockFileSystem.Object, _filename); RunForAWhile(_machine); _machine.Key(Keys.A, true); RunForAWhile(_machine); _machine.LoadDisc(0, null); RunForAWhile(_machine); _machine.LoadTape(null); RunForAWhile(_machine); _machine.Reset(); RunForAWhile(_machine); _machine.AddBookmark(false); HistoryEvent bookmarkEvent = _machine.History.CurrentEvent; RunForAWhile(_machine); _machine.JumpToMostRecentBookmark(); HistoryEvent eventToDelete = bookmarkEvent.Children[0]; RunForAWhile(_machine); _machine.DeleteBookmark(bookmarkEvent); _machine.DeleteBranch(eventToDelete); _machine.Close(); using (LocalMachine machine = LocalMachine.OpenFromFile(_mockFileSystem.Object, "test.cpvc")) { // Verify Assert.IsTrue(machine.IsOpen); Assert.AreEqual(machine.PersistantFilepath, "test.cpvc"); Assert.AreEqual(machine.Name, "test"); Assert.IsInstanceOf <RootHistoryEvent>(machine.History.RootEvent); Assert.AreEqual(1, machine.History.RootEvent.Children.Count); CoreActionHistoryEvent coreActionHistoryEvent = machine.History.RootEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(CoreRequest.Types.KeyPress, coreActionHistoryEvent.CoreAction.Type); Assert.AreEqual(Keys.A, coreActionHistoryEvent.CoreAction.KeyCode); Assert.IsTrue(coreActionHistoryEvent.CoreAction.KeyDown); Assert.AreEqual(1, coreActionHistoryEvent.Children.Count); coreActionHistoryEvent = coreActionHistoryEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(CoreRequest.Types.LoadDisc, coreActionHistoryEvent.CoreAction.Type); Assert.AreEqual(0, coreActionHistoryEvent.CoreAction.Drive); Assert.IsNull(coreActionHistoryEvent.CoreAction.MediaBuffer.GetBytes()); Assert.AreEqual(1, coreActionHistoryEvent.Children.Count); coreActionHistoryEvent = coreActionHistoryEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(CoreRequest.Types.LoadTape, coreActionHistoryEvent.CoreAction.Type); Assert.IsNull(coreActionHistoryEvent.CoreAction.MediaBuffer.GetBytes()); Assert.AreEqual(1, coreActionHistoryEvent.Children.Count); coreActionHistoryEvent = coreActionHistoryEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(CoreRequest.Types.Reset, coreActionHistoryEvent.CoreAction.Type); Assert.AreEqual(1, coreActionHistoryEvent.Children.Count); coreActionHistoryEvent = coreActionHistoryEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(1, coreActionHistoryEvent.Children.Count); BookmarkHistoryEvent bookmarkHistoryEvent = coreActionHistoryEvent.Children[0] as BookmarkHistoryEvent; Assert.IsNotNull(bookmarkHistoryEvent); coreActionHistoryEvent = bookmarkHistoryEvent.Children[0] as CoreActionHistoryEvent; Assert.IsNotNull(coreActionHistoryEvent); Assert.AreEqual(CoreRequest.Types.RunUntil, coreActionHistoryEvent.CoreAction.Type); bookmarkHistoryEvent = coreActionHistoryEvent.Children[0] as BookmarkHistoryEvent; Assert.IsNotNull(bookmarkHistoryEvent); Assert.AreEqual(bookmarkHistoryEvent, machine.History.CurrentEvent); _mockAuditor.Verify(a => a(It.Is <CoreAction>(c => c.Type == CoreRequest.Types.LoadCore)), Times.Once); } }