예제 #1
0
        public void WriteAndReadArguments()
        {
            // Setup
            Bookmark bookmark = new Bookmark(false, 1, _state, _screen);

            // Act
            _history.AddBookmark(100, bookmark);
            _history.AddBookmark(200, bookmark);
            _mockFile.Clear();
            _file.WriteHistory("Test");
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.AreEqual(1, _mockFile.Lines.Count(line => line.StartsWith("args:")));
            Assert.Zero(_mockFile.Lines.Count(line => line.StartsWith("arg:")));
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
예제 #2
0
        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);
            }
        }