public void TryMixedTypeSave()
        {
            // 1. write data to notes
            _setupforlayoutests();
            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataInterface note = null;

            for (int i = 0; i < count; i++)
            {
                note = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML));                //new NoteDataXML ();

                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }

            // store a SECOND TYPE into the mix
            note         = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML_RichText));
            note.Caption = "textnote";
            string guid = note.GuidForNote;

            _w.output("new guid" + guid);
            layoutPanel.AddNote(note);
            note.CreateParent(layoutPanel);
            layoutPanel.SaveLayout();
        }
        /*// I made the decision to suppress Errors (hence not required CreateParent, for the purpose of MOVING notes
         * // This violated an earlier decision I had made and I had to disable the TryToSaveWithoutCreating a Parent Exception
         * [Test]
         * [ExpectedException]
         * public void TryToSaveWithoutCreatingAParent()
         * {
         *      Type TypeToTest = typeof(NoteDataXML_RichText);
         *      // 1. write data to notes
         *      _setupforlayoutests ();
         *      int count = 25;
         *      FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
         *      LayoutPanel layoutPanel = new LayoutPanel ();
         *
         *      NoteDataInterface note = null;
         *      for (int i = 0; i < count; i++) {
         *              note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);//new NoteDataXML ();
         *      //	note.CreateParent(layoutPanel);
         *              note.Caption = "boo" + i.ToString ();
         *              layout.Add (note);
         *      }
         *
         *
         *      note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
         *      note.Caption = "snake";
         *      string guid = note.GuidForNote;
         *      //note.CreateParent(layoutPanel);
         *      _w.output("new guid" + guid);
         *      layout.Add (note);
         *      layout.SaveTo ();
         *      _w.output ("save worked");
         * }*/

        /// <summary>
        /// Creates the lots of notes to test different types and return proper caption.
        ///
        /// Testing NOTE: You must CreateParent when building items. Else the save cannot work.
        ///
        /// </summary>
        /// <returns>
        /// The lots of notes to test different types and return proper caption.
        /// </returns>
        /// <param name='TestCaption'>
        /// Test caption.
        /// </param>
        /// <param name='TypeToTest'>
        /// Type to test.
        /// </param>
        private string CreateLotsOfNotesToTestDifferentTypesAndReturnProperCaption(string TestCaption, Type TypeToTest)
        {
            // 1. write data to notes
            //System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);

            NoteDataInterface note = null;

            for (int i = 0; i < count; i++)
            {
                note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);                //new NoteDataXML ();

                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }


            note         = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
            note.Caption = TestCaption;
            string guid = note.GuidForNote;

            note.CreateParent(layoutPanel);
            _w.output("new guid" + guid);
            layoutPanel.AddNote(note);
            layoutPanel.SaveLayout();
            _w.output("save worked");

            // 2. Now we pretend that later one, elsewhere in code, we need to get access to this (i.e., a Random Table)
            layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel.LoadLayout("testguid", false, null);

            //layoutPanel.LoadLayout( (null);
            //	_w.output (layout.Backup ());
            //_w.output(layoutPanel.GetNotes().Count.ToString());
            foreach (NoteDataXML _note in layoutPanel.GetAllNotes())
            {
                if (_note.GuidForNote == guid)
                {
                    _w.output(_note.Caption);
                    return(note.Caption);
                }
            }
            return("<error>");
        }
        public void SaveNotequired()
        {
            _setupforlayoutests();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataXML_RichText note = new NoteDataXML_RichText();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();
                //note.UpdateLocation();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }
            // cannot actually save becaue LayoutPanel is just fake for this test
            // but we check that the flag was set correclty -- i..e, nothing improtant changes, nothing needs tob e saved
            //	layout.SaveTo();
            //layoutPanel.SaveLayout();

            // April 2013 - This test was flagged as Assert.False but I don't understand
            // We WANT the flag to say we need a save, no?
            Assert.True(layoutPanel.GetSaveRequired);
        }
        public void SaveAndLoadTest_Works()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            int linktable      = 1;
            int extranodeadded = 1;
            int count          = 25;
            ///FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            //layout.LoadFrom(layoutPanel);
            NoteDataXML note = new NoteDataXML();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
            }

            layoutPanel.SaveLayout();
            _w.output("save worked");
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.LoadLayout("testguid", false, null);
            //layout.LoadFrom(layoutPanel);

            //	_w.output (layout.Backup ());
            //_w.output(layout.GetNotes().Count.ToString());
            Assert.AreEqual(count + linktable + extranodeadded, layoutPanel.GetAllNotes().Count);
        }
        //[Ignore]
        public void NoCrashIfSaveEmptyPanel()
        {
            _setupforlayoutests();

            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataXML_Panel note = new NoteDataXML_Panel();

            layoutPanel.AddNote(note);
            note.CreateParent(layoutPanel);
            layoutPanel.SaveLayout();

            _w.output("This often fails if we have added a new Layout Variable and it has not been set to a default value in constructor");
        }
        public void LayoutShouldNotExist()
        {
            _setupforlayoutests();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            NoteDataXML note = new NoteDataXML();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }
            //	layout.SaveTo(); no save, so note should not exist

            Assert.False(MasterOfLayouts.ExistsByGUID("testguid"));
        }
        public void SaveRequired()
        {
            _setupforlayoutests();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", false, null);
            NoteDataXML_RichText note = new NoteDataXML_RichText();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();

                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
                note.UpdateLocation();
            }
            //layout.SaveTo();
            Assert.True(layoutPanel.GetSaveRequired);
        }
        public void SaveAndLoadStressLoad()
        {
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            _TestSingleTon.Instance._SetupForLayoutPanelTests();
            int linktable      = 1;
            int extranodeadded = 1;

            _w.output("this is a slow test. 6 minutes?");
            int count = 200;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);
            form.Controls.Add(layoutPanel);
            form.Show();

            NoteDataXML note = new NoteDataXML();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }
            //_w.output(String.Format ("{0} Notes in Layout before save", layout.GetNotes().Count.ToString()));
            layoutPanel.SaveLayout();

            //_w.output(String.Format ("{0} Objects Saved", layout.ObjectsSaved().ToString()));
            //layoutPanel = new FakeLayoutDatabase ("testguid");
            layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.LoadLayout("testguid", false, null);
            //layoutPanel.LoadFrom(layoutPanel);

            //_w.output(String.Format ("{0} Objects Loaded", layout.GetNotes().Count));
            //NOT DONE YET
            Assert.AreEqual(count + linktable + extranodeadded, layoutPanel.GetAllNotes().Count);
        }
        public void LayoutExists()
        {
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            _w.output("1");
            _TestSingleTon.Instance._SetupForLayoutPanelTests();
            _w.output("2");
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);

            layoutPanel.NewLayout("testguid", true, null);

            NoteDataXML note = new NoteDataXML();

            for (int i = 0; i < count; i++)
            {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote(note);
                note.CreateParent(layoutPanel);
            }
            layoutPanel.SaveLayout();
            layoutPanel.Dispose();
            Assert.True(MasterOfLayouts.ExistsByGUID("testguid"));
        }
        public void SaveRequired()
        {
            _setupforlayoutests ();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", false, null);
            NoteDataXML_RichText note = new NoteDataXML_RichText ();
            for (int i = 0; i < count; i++) {

                note.Caption = "boo" + i.ToString ();

                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
                note.UpdateLocation();
            }
            //layout.SaveTo();
            Assert.True (layoutPanel.GetSaveRequired);
        }
        public void SaveNotequired()
        {
            _setupforlayoutests ();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout ("testguid", true, null);
            NoteDataXML_RichText note = new NoteDataXML_RichText ();
            for (int i = 0; i < count; i++) {

                note.Caption = "boo" + i.ToString ();
                //note.UpdateLocation();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }
            // cannot actually save becaue LayoutPanel is just fake for this test
            // but we check that the flag was set correclty -- i..e, nothing improtant changes, nothing needs tob e saved
            //	layout.SaveTo();
            //layoutPanel.SaveLayout();

            // April 2013 - This test was flagged as Assert.False but I don't understand
            // We WANT the flag to say we need a save, no?
            Assert.True (layoutPanel.GetSaveRequired);
        }
        public void SaveAndLoadTest_Works()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            int linktable = 1;
            int extranodeadded = 1;
            int count = 25;
            ///FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);
            //layout.LoadFrom(layoutPanel);
            NoteDataXML note = new NoteDataXML ();
            for (int i = 0; i < count; i++) {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote (note);
            }

            layoutPanel.SaveLayout();
            _w.output("save worked");
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.LoadLayout("testguid", false, null);
            //layout.LoadFrom(layoutPanel);

            //	_w.output (layout.Backup ());
            //_w.output(layout.GetNotes().Count.ToString());
            Assert.AreEqual(count+linktable +extranodeadded, layoutPanel.GetAllNotes().Count);
        }
        public void SaveAndLoadStressLoad()
        {
            System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            _TestSingleTon.Instance._SetupForLayoutPanelTests();
            int linktable = 1;
            int extranodeadded = 1;
            _w.output("this is a slow test. 6 minutes?");
            int count = 200;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);
            form.Controls.Add (layoutPanel);
            form.Show ();

            NoteDataXML note = new NoteDataXML ();
            for (int i = 0; i < count; i++) {
                note.Caption = "boo" + i.ToString();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }
            //_w.output(String.Format ("{0} Notes in Layout before save", layout.GetNotes().Count.ToString()));
            layoutPanel.SaveLayout();

            //_w.output(String.Format ("{0} Objects Saved", layout.ObjectsSaved().ToString()));
            //layoutPanel = new FakeLayoutDatabase ("testguid");
             layoutPanel = new LayoutPanel(CoreUtilities.Constants.BLANK, false);
            layoutPanel.LoadLayout("testguid", false, null);
            //layoutPanel.LoadFrom(layoutPanel);

            //_w.output(String.Format ("{0} Objects Loaded", layout.GetNotes().Count));
            //NOT DONE YET
            Assert.AreEqual (count + linktable + extranodeadded, layoutPanel.GetAllNotes().Count);
        }
        public void NoCrashIfSaveEmptyPanel()
        {
            _setupforlayoutests ();

            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);
            NoteDataXML_Panel note = new NoteDataXML_Panel ();
            layoutPanel.AddNote (note);
            note.CreateParent(layoutPanel);
            layoutPanel.SaveLayout();

            _w.output("This often fails if we have added a new Layout Variable and it has not been set to a default value in constructor");
        }
        public void LayoutShouldNotExist()
        {
            _setupforlayoutests ();
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);
            NoteDataXML note = new NoteDataXML ();
            for (int i = 0; i < count; i++) {

                note.Caption = "boo" + i.ToString ();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }
            //	layout.SaveTo(); no save, so note should not exist

            Assert.False (MasterOfLayouts.ExistsByGUID("testguid"));
        }
        public void TryMixedTypeSave()
        {
            // 1. write data to notes
            _setupforlayoutests ();
            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);
            NoteDataInterface note = null;
            for (int i = 0; i < count; i++) {
                note = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML));//new NoteDataXML ();

                note.Caption = "boo" + i.ToString ();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }

            // store a SECOND TYPE into the mix
            note = (NoteDataInterface)Activator.CreateInstance(typeof(NoteDataXML_RichText));
            note.Caption = "textnote";
            string guid = note.GuidForNote;

            _w.output("new guid" + guid);
            layoutPanel.AddNote (note);
            note.CreateParent(layoutPanel);
            layoutPanel.SaveLayout ();
        }
        /*// I made the decision to suppress Errors (hence not required CreateParent, for the purpose of MOVING notes
        // This violated an earlier decision I had made and I had to disable the TryToSaveWithoutCreating a Parent Exception
        [Test]
        [ExpectedException]
        public void TryToSaveWithoutCreatingAParent()
        {
            Type TypeToTest = typeof(NoteDataXML_RichText);
            // 1. write data to notes
            _setupforlayoutests ();
            int count = 25;
            FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel ();

            NoteDataInterface note = null;
            for (int i = 0; i < count; i++) {
                note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);//new NoteDataXML ();
            //	note.CreateParent(layoutPanel);
                note.Caption = "boo" + i.ToString ();
                layout.Add (note);
            }

            note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
            note.Caption = "snake";
            string guid = note.GuidForNote;
            //note.CreateParent(layoutPanel);
            _w.output("new guid" + guid);
            layout.Add (note);
            layout.SaveTo ();
            _w.output ("save worked");
        }*/
        /// <summary>
        /// Creates the lots of notes to test different types and return proper caption.
        /// 
        /// Testing NOTE: You must CreateParent when building items. Else the save cannot work.
        /// 
        /// </summary>
        /// <returns>
        /// The lots of notes to test different types and return proper caption.
        /// </returns>
        /// <param name='TestCaption'>
        /// Test caption.
        /// </param>
        /// <param name='TypeToTest'>
        /// Type to test.
        /// </param>
        private string CreateLotsOfNotesToTestDifferentTypesAndReturnProperCaption(string TestCaption, Type TypeToTest)
        {
            // 1. write data to notes
            //System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            int count = 25;
            //	FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);

            NoteDataInterface note = null;
            for (int i = 0; i < count; i++) {
                note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);//new NoteDataXML ();

                note.Caption = "boo" + i.ToString ();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }

            note = (NoteDataInterface)Activator.CreateInstance(TypeToTest);
            note.Caption = TestCaption;
            string guid = note.GuidForNote;
            note.CreateParent(layoutPanel);
            _w.output("new guid" + guid);
            layoutPanel.AddNote (note);
            layoutPanel.SaveLayout ();
            _w.output ("save worked");

            // 2. Now we pretend that later one, elsewhere in code, we need to get access to this (i.e., a Random Table)
            layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            //layout = new FakeLayoutDatabase ("testguid");
            layoutPanel.LoadLayout("testguid",false, null);

            //layoutPanel.LoadLayout( (null);
            //	_w.output (layout.Backup ());
            //_w.output(layoutPanel.GetNotes().Count.ToString());
            foreach (NoteDataXML _note in layoutPanel.GetAllNotes()) {

                if( _note.GuidForNote == guid)
                {
                    _w.output(_note.Caption);
                    return note.Caption;
                }

            }
            return "<error>";
        }
        public void LayoutExists()
        {
            System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            _w.output("1");
            _TestSingleTon.Instance._SetupForLayoutPanelTests();
            _w.output("2");
            int count = 25;
            //FakeLayoutDatabase layout = new FakeLayoutDatabase ("testguid");
            LayoutPanel layoutPanel = new LayoutPanel (CoreUtilities.Constants.BLANK, false);
            layoutPanel.NewLayout("testguid", true, null);

            NoteDataXML note = new NoteDataXML ();
            for (int i = 0; i < count; i++) {

                note.Caption = "boo" + i.ToString ();
                layoutPanel.AddNote (note);
                note.CreateParent(layoutPanel);
            }
            layoutPanel.SaveLayout();
            layoutPanel.Dispose ();
            Assert.True (MasterOfLayouts.ExistsByGUID("testguid"));
        }