Пример #1
0
        public void MainCtrl_InsertImage_InMap_Null()
        {
            var imageAdded = false;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                MetaModel.MetaModel.Initialize();
                var sut  = new MainCtrl();
                var form = new MainForm();
                DialogManager dialogs = A.Fake <DialogManager>();
                A.CallTo(() => dialogs.GetImageFile()).Returns(null);
                sut.InitMindMate(form, dialogs);
                MainMenuCtrl mainMenuCtrl = new MainMenuCtrl(form.MainMenu, sut);
                form.MainMenuCtrl         = mainMenuCtrl;
                form.Shown += (sender, args) =>
                {
                    sut.ReturnFocusToMapView();
                    sut.InsertImage();
                    imageAdded = sut.CurrentMapCtrl.MapView.Tree.SelectedNodes.All(n => n.HasImage);
                };
                Timer timer = new Timer {
                    Interval = 5
                };                                        //timer is used because the Dirty property is updated in the next event of GUI thread.
                timer.Tick += delegate
                {
                    if (timer.Tag == null)
                    {
                        timer.Tag = "First Event Fired";
                    }
                    else if (timer.Tag.Equals("First Event Fired"))
                    {
                        timer.Tag = "Second Event Fired";
                    }
                    else
                    {
                        foreach (var f in sut.PersistenceManager)
                        {
                            f.IsDirty = false; //to avoid save warning dialog
                        }
                        form.Close();
                    }
                };

                timer.Start();
                form.ShowDialog();
                timer.Stop();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsFalse(imageAdded);
        }
Пример #2
0
        public void InsertImage_InNote()
        {
            var imageAdded = false;

            System.Threading.Thread t = new System.Threading.Thread(() =>
            {
                MetaModel.MetaModel.Initialize();
                var sut  = new MainCtrl();
                var form = new MainForm();
                DialogManager dialogs = A.Fake <DialogManager>();
                A.CallTo(() => dialogs.GetImageFile()).Returns(@"Resources\TestImage.png");
                sut.InitMindMate(form, dialogs);
                MainMenuCtrl mainMenuCtrl = new MainMenuCtrl(form.MainMenu, sut);
                form.MainMenuCtrl         = mainMenuCtrl;
                form.Shown += (sender, args) =>
                {
                    form.NoteEditor.Focus();
                    sut.InsertImage();
                    imageAdded = form.NoteEditor.HTML.Contains("IMG") || form.NoteEditor.HTML.Contains("img");
                };
                Timer timer = new Timer {
                    Interval = 5
                };                                        //timer is used because the Dirty property is updated in the next event of GUI thread.
                timer.Tick += delegate
                {
                    if (timer.Tag == null)
                    {
                        timer.Tag = "First Event Fired";
                    }
                    else if (timer.Tag.Equals("First Event Fired"))
                    {
                        timer.Tag = "Second Event Fired";
                    }
                    else
                    {
                        foreach (var f in sut.PersistenceManager)
                        {
                            f.IsDirty = false; //to avoid save warning dialog
                        }
                        form.Close();
                    }
                };

                timer.Start();
                form.ShowDialog();
                timer.Stop();
            });
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start();
            t.Join();

            Assert.IsTrue(imageAdded);
        }