Пример #1
0
        public void StdFileHandlingTest()
        {
            Interlocked.Increment(ref WaitForN);
            this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate()
            {

                MainWindowVM_Accessor<AvalonDocumentWrapper> target = new MainWindowVM_Accessor<AvalonDocumentWrapper>(TheCompiler.Instance); 
            // To execute commands, we need to take a detour and bind them in a dummy
            StackPanel dummy = new StackPanel();
            dummy.CommandBindings.Add((target.Target as MainWindowVM<AvalonDocumentWrapper>).GetSaveAsCommandBinding());
            dummy.CommandBindings.Add((target.Target as MainWindowVM<AvalonDocumentWrapper>).GetNewCommandBinding());
            dummy.CommandBindings.Add((target.Target as MainWindowVM<AvalonDocumentWrapper>).GetSaveCommandBinding());
            dummy.CommandBindings.Add((target.Target as MainWindowVM<AvalonDocumentWrapper>).GetOpenCommandBinding());

            // create a new file 
            ApplicationCommands.New.Execute(null, dummy);
            GlobUI.LastMessage = "";
            GlobUI.MockResult = DialogResult.Cancel;
            // create a new file again, the file was not changed, so the use should not be asked to save
            ApplicationCommands.New.Execute(null, dummy);
            Assert.AreEqual(GlobUI.LastMessage, "");
            //Application.DoEvents();
        //    Thread.Sleep(1000);
            //DispatcherUtil.DoEvents();

            // now change the file a bit
            target.TheDocument.Document.Replace(0, 0, "   ");
            string oldText = target.TheDocument.Document.Text;

       //     Thread.Sleep(1000);
            //DispatcherUtil.DoEvents();

            // try to override again
            ApplicationCommands.New.Execute(null, dummy);
            // now a messagebox must have been shown, and the file contents should be unchanged
            Assert.IsTrue(GlobUI.LastMessage != "");
            Assert.AreEqual(target.TheDocument.Document.Text, oldText);

        //    Thread.Sleep(1000);
            //DispatcherUtil.DoEvents();

            // Now save the file to a temp file
            string filename = Directory.GetCurrentDirectory() + "\\temp.tex";
            if (File.Exists(filename))
                File.Delete(filename);

       //     Thread.Sleep(1000);
           // DispatcherUtil.DoEvents();

            GlobUI.MockFileDialogFileName = filename;
            GlobUI.MockFileDialogResult = true;
            ApplicationCommands.SaveAs.Execute(null, dummy);
            Assert.IsTrue(File.Exists(filename));

            
            // Let pdflatex do its job (hack)
        //    Thread.Sleep(2000);
            //DispatcherUtil.DoEvents();

            //return;
            // check that temp files are removed, but pdf should exist
            Assert.IsTrue(File.Exists(filename+".preview.pdf"));
            //Assert.IsFalse(File.Exists("temp.tex.preview.log")); // are deleted upon destruction
            //Assert.IsFalse(File.Exists("temp.tex.preview.aux"));
            
            // change file on disk... change should be detected, and user asked to reload file
            GlobUI.MockResult = DialogResult.Yes; // reload the file
            File.WriteAllText(filename, "\\begin{tikzpicture} \r\n blabla\r\n \\end{tikzpicture}");
            System.Threading.Thread.Sleep(1000);
            DispatcherUtil.DoEvents();
            System.Threading.Thread.Sleep(1000);
            DispatcherUtil.DoEvents();
            Assert.IsTrue(target.TheDocument.Document.Text.Contains("blabla"));
            // file should not be marked as changed
            Assert.IsFalse(target.TheDocument.ChangesMade);

          //  Thread.Sleep(1000);

            } ) );
            Interlocked.Decrement(ref WaitForN);
       //     Dispatcher.Run();

        }
Пример #2
0
        public void StdFileHandlingTest()
        {
            Interlocked.Increment(ref WaitForN);
            this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate()
            {
                MainWindowVM_Accessor <AvalonDocumentWrapper> target = new MainWindowVM_Accessor <AvalonDocumentWrapper>(TheCompiler.Instance);
                // To execute commands, we need to take a detour and bind them in a dummy
                StackPanel dummy = new StackPanel();
                dummy.CommandBindings.Add((target.Target as MainWindowVM <AvalonDocumentWrapper>).GetSaveAsCommandBinding());
                dummy.CommandBindings.Add((target.Target as MainWindowVM <AvalonDocumentWrapper>).GetNewCommandBinding());
                dummy.CommandBindings.Add((target.Target as MainWindowVM <AvalonDocumentWrapper>).GetSaveCommandBinding());
                dummy.CommandBindings.Add((target.Target as MainWindowVM <AvalonDocumentWrapper>).GetOpenCommandBinding());

                // create a new file
                ApplicationCommands.New.Execute(null, dummy);
                GlobUI.LastMessage = "";
                GlobUI.MockResult  = DialogResult.Cancel;
                // create a new file again, the file was not changed, so the use should not be asked to save
                ApplicationCommands.New.Execute(null, dummy);
                Assert.AreEqual(GlobUI.LastMessage, "");
                //Application.DoEvents();
                //    Thread.Sleep(1000);
                //DispatcherUtil.DoEvents();

                // now change the file a bit
                target.TheDocument.Document.Replace(0, 0, "   ");
                string oldText = target.TheDocument.Document.Text;

                //     Thread.Sleep(1000);
                //DispatcherUtil.DoEvents();

                // try to override again
                ApplicationCommands.New.Execute(null, dummy);
                // now a messagebox must have been shown, and the file contents should be unchanged
                Assert.IsTrue(GlobUI.LastMessage != "");
                Assert.AreEqual(target.TheDocument.Document.Text, oldText);

                //    Thread.Sleep(1000);
                //DispatcherUtil.DoEvents();

                // Now save the file to a temp file
                string filename = Directory.GetCurrentDirectory() + "\\temp.tex";
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }

                //     Thread.Sleep(1000);
                // DispatcherUtil.DoEvents();

                GlobUI.MockFileDialogFileName = filename;
                GlobUI.MockFileDialogResult   = true;
                ApplicationCommands.SaveAs.Execute(null, dummy);
                Assert.IsTrue(File.Exists(filename));


                // Let pdflatex do its job (hack)
                //    Thread.Sleep(2000);
                //DispatcherUtil.DoEvents();

                //return;
                // check that temp files are removed, but pdf should exist
                Assert.IsTrue(File.Exists(filename + ".preview.pdf"));
                //Assert.IsFalse(File.Exists("temp.tex.preview.log")); // are deleted upon destruction
                //Assert.IsFalse(File.Exists("temp.tex.preview.aux"));

                // change file on disk... change should be detected, and user asked to reload file
                GlobUI.MockResult = DialogResult.Yes; // reload the file
                File.WriteAllText(filename, "\\begin{tikzpicture} \r\n blabla\r\n \\end{tikzpicture}");
                System.Threading.Thread.Sleep(1000);
                DispatcherUtil.DoEvents();
                System.Threading.Thread.Sleep(1000);
                DispatcherUtil.DoEvents();
                Assert.IsTrue(target.TheDocument.Document.Text.Contains("blabla"));
                // file should not be marked as changed
                Assert.IsFalse(target.TheDocument.ChangesMade);

                //  Thread.Sleep(1000);
            }));
            Interlocked.Decrement(ref WaitForN);
            //     Dispatcher.Run();
        }