Exemple #1
0
        public void OpenMachineTwice()
        {
            // Setup
            string        filepath  = "test.cpvc";
            MainViewModel viewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem?.Object);

            viewModel.PromptForFile += (sender, args) =>
            {
                if (args.FileType == FileTypes.Machine && args.Existing)
                {
                    args.Filepath = filepath;
                }
            };

            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(filepath)).Returns(mockTextFile);
            viewModel.OpenMachineCommand.Execute(_mockFileSystem.Object);

            // Act
            viewModel.OpenMachineCommand.Execute(_mockFileSystem.Object);

            // Verify
            Assert.AreEqual(1, viewModel.Machines.Count);
        }
Exemple #2
0
        public void Compact()
        {
            // Setup
            string       tmpFilename = String.Format("{0}.tmp", _filename);
            LocalMachine machine     = LocalMachine.OpenFromFile(_mockFileSystem.Object, _filename);

            machine.Close();

            MockTextFile mockNewTextFile = new MockTextFile();

            _mockFileSystem.Setup(fs => fs.OpenTextFile(tmpFilename)).Returns(mockNewTextFile);

            // Act
            machine.Compact(_mockFileSystem.Object);

            // Verify
            int    keyLineCount = 0;
            string line;

            while ((line = mockNewTextFile.ReadLine()) != null)
            {
                if (line.StartsWith("key:"))
                {
                    keyLineCount++;
                }
            }

            Assert.AreEqual(1, keyLineCount);
            _mockFileSystem.Verify(fs => fs.ReplaceFile(_filename, tmpFilename), Times.Once());
        }
Exemple #3
0
        public void Setup()
        {
            _remoteServersSetting = String.Empty;

            _mockSettings = new Mock <ISettings>(MockBehavior.Strict);
            _mockSettings.SetupGet(x => x.RecentlyOpened).Returns(() => _settingGet);
            _mockSettings.SetupSet(x => x.RecentlyOpened = It.IsAny <string>());
            _mockSettings.SetupGet(x => x.RemoteServers).Returns(() => _remoteServersSetting);
            _mockSettings.SetupSet(x => x.RemoteServers = It.IsAny <string>());

            _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);
            _mockFileSystem.Setup(fileSystem => fileSystem.Exists(AnyString())).Returns(true);
            _mockFileSystem.Setup(ReadBytes()).Returns(new byte[1]);

            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile);

            _mockSocket = new Mock <ISocket>();

            _machine       = LocalMachine.New("test", null);
            _mainViewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem.Object);
            _mainViewModel.Model.AddMachine(_machine);
        }
Exemple #4
0
        public void Setup()
        {
            _mockFileSystem = new Mock <IFileSystem>();
            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(TestHelpers.AnyString())).Returns(mockTextFile);
            _machine      = LocalMachine.New("test", null);
            _mockSettings = new Mock <ISettings>();
            _mainModel    = new MainModel(_mockSettings.Object, null);
        }
        public void Setup()
        {
            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict);
            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile);
            _mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString()));
            _mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString()));
            _mockFileSystem.Setup(ReadBytes()).Returns(new byte[1]);

            _history = new History();

            _bookmark1Event = _history.AddBookmark(100, new Bookmark(false, 0, null, null));
            _history.AddCoreAction(CoreAction.RunUntil(100, 400, null));
            _leaf1Event           = _history.AddCoreAction(CoreAction.KeyPress(400, 42, true));
            _history.CurrentEvent = _bookmark1Event;
            _bookmark2Event       = _history.AddBookmark(200, new Bookmark(false, 0, null, null));
            _history.AddCoreAction(CoreAction.RunUntil(200, 300, null));
            _leaf2Event           = _history.AddCoreAction(CoreAction.KeyPress(300, 42, true));
            _history.CurrentEvent = _bookmark2Event;
            _history.AddCoreAction(CoreAction.KeyPress(300, 42, true));
            _history.AddCoreAction(CoreAction.KeyPress(400, 42, false));
            _bookmark3Event       = _history.AddBookmark(500, new Bookmark(false, 0, null, null));
            _history.CurrentEvent = _history.RootEvent;
            _leaf3Event           = _history.AddCoreAction(CoreAction.KeyPress(50, 42, true));
            _history.CurrentEvent = _bookmark3Event;


            // Diagram of this history...
            //
            // 500: o
            // 400: |   |
            // 300: | | |
            // 200: o-/ |
            // 100: o---/
            //  50  |     |
            //   0: o-----/

            _viewModel = new BookmarksViewModel(_history);

            Assert.AreEqual(7, _viewModel.Items.Count);

            _bookmark3ViewItem = _viewModel.Items[0];
            _leaf1ViewItem     = _viewModel.Items[1];
            _leaf2ViewItem     = _viewModel.Items[2];
            _bookmark2ViewItem = _viewModel.Items[3];
            _bookmark1ViewItem = _viewModel.Items[4];
            _leaf3ViewItem     = _viewModel.Items[5];
            _rootViewItem      = _viewModel.Items[6];
        }
Exemple #6
0
        public void Setup()
        {
            _mockFile = new MockTextFile();
            _history  = new History();
            _file     = new MachineFile(_mockFile, _history);

            _state  = new byte[1000];
            _screen = new byte[1000];

            for (int i = 0; i < 1000; i++)
            {
                _state[i]  = (byte)(i % 256);
                _screen[i] = (byte)((i + 1) % 256);
            }
        }
Exemple #7
0
        public void OpenNonExistentFile()
        {
            // Setup
            Mock <ISocket> mockSocket = new Mock <ISocket>();

            _settingGet = "test.cpvc";
            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Throws(new Exception());

            // Act
            MainViewModel viewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem.Object);

            // Verify
            Assert.AreEqual(0, viewModel.Machines.Count);
        }
Exemple #8
0
        public void OpenInvalid()
        {
            // Setup
            PromptForFileEventHandler mockPrompt = (object sender, PromptForFileEventArgs args) => args.Filepath = "test.cpvc";

            Mock <ISocket> mockSocket = new Mock <ISocket>();
            MainViewModel  viewModel  = new MainViewModel(_mockSettings.Object, _mockFileSystem.Object);

            viewModel.PromptForFile += mockPrompt;
            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(It.IsAny <string>())).Throws(new Exception());

            // Act and Verify
            Assert.Throws <Exception>(() => viewModel.OpenMachineCommand.Execute(_mockFileSystem.Object));
        }
Exemple #9
0
        public void Setup()
        {
            _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 = new MockTextFile();
            _mockTextFile.WriteLine("name:Test");
            _mockTextFile.WriteLine("key:1,10,58,True");
            _mockTextFile.WriteLine("key:2,20,58,False");
            _mockTextFile.WriteLine("current:1");
            _mockTextFile.WriteLine("deletebranch:2");
            _mockFileSystem.Setup(fs => fs.OpenTextFile(_filename)).Callback(() => _mockTextFile.SeekToStart()).Returns(_mockTextFile);

            _mockAuditor = new Mock <MachineAuditorDelegate>();

            _machine = CreateMachine();
        }
Exemple #10
0
        public void CloseAll(bool newMachine, bool persistedMachine, bool nonPersistableMachine, bool confirmClose, bool expectedResult)
        {
            // Setup
            MainViewModel mainViewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem.Object);

            if (newMachine)
            {
                mainViewModel.NewMachineCommand.Execute(_mockFileSystem.Object);
            }

            if (persistedMachine)
            {
                mainViewModel.PromptForFile += (sender, args) =>
                {
                    args.Filepath = "test.cpvc";
                };

                MockTextFile mockTextFile = new MockTextFile();
                mockTextFile.WriteLine("name:Test");
                _mockFileSystem.Setup(fs => fs.OpenTextFile("test.cpvc")).Returns(mockTextFile);

                _mainViewModel.OpenCommand.Execute(_mockFileSystem.Object);
            }

            if (nonPersistableMachine)
            {
                History history = new History();

                mainViewModel.OpenReplayMachine("Test (Replay)", history.RootEvent);
            }

            mainViewModel.ConfirmClose += (sender, args) =>
            {
                args.Result = confirmClose;
            };

            // Act
            bool result = mainViewModel.CloseAll();

            // Verify
            Assert.AreEqual(expectedResult, result);
        }
Exemple #11
0
        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);
        }