Esempio n. 1
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected override void Dispose(bool disposing)
        {
            Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed resources here.
                if (m_DummyFwApp != null)
                {
                    m_DummyFwApp.Dispose();
                }
                if (m_mainWnd != null)
                {
                    m_mainWnd.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_DummyFwApp           = null;
            m_mainWnd              = null;
            m_itemProps.ParentForm = null;

            base.Dispose(disposing);
        }
Esempio n. 2
0
        public void IFwTool_CloseDbAndWindows()
        {
            CheckDisposed();

            // Preparations
            string     serverName = MiscUtils.LocalServerName;
            DummyFwApp app        = m_app as DummyFwApp;

            app.SetFdoCache(serverName, "TestLangProj", Cache);

            using (InMemoryFdoCache mockedCache = InMemoryFdoCache.CreateInMemoryFdoCache())
            {
                app.SetFdoCache(serverName, "LelaTeli-2", mockedCache.Cache);

                int pidNew;
                m_app.NewMainWnd(serverName, "TestLangProj", 1, 0, 0, 0, 0, out pidNew);
                m_app.NewMainWnd(serverName, "TestLangProj", 1, 0, 0, 0, 0, out pidNew);
                m_app.NewMainWnd(serverName, "LelaTeli-2", 1, 0, 0, 0, 0, out pidNew);

                Assert.AreEqual(3, app.m_nMainWnd);
                app.m_mainWnd[0].Cache = Cache;
                app.m_mainWnd[1].Cache = Cache;
                app.m_mainWnd[2].Cache = mockedCache.Cache;

                // Here is what we want to test
                ((IFwTool)m_app).CloseDbAndWindows(serverName, "TestLangProj", true);

                Assert.IsTrue(app.m_mainWnd[0].m_fClosed);
                Assert.IsTrue(app.m_mainWnd[1].m_fClosed);
                Assert.IsFalse(app.m_mainWnd[2].m_fClosed);
            }
        }
Esempio n. 3
0
        public override void FixtureSetup()
        {
            CheckDisposed();
            base.FixtureSetup();

            m_DummyFwApp = new WindowlessDummyFwApp(new string[] { "-c", m_sSvrName, "-db", m_sDbName });

            m_mainWnd = new InvisibleFwMainWnd();
            m_itemProps.ParentForm = m_mainWnd;
        }
Esempio n. 4
0
        public void CheckDbVersionCompatability_OldApplication()
        {
            CheckDisposed();

            DummyFwApp app = m_app as DummyFwApp;

            // make app version older than db version
            app.m_appVersion -= 1;
            app.CheckDbVerCompatibility(string.Empty, "TestLangProj");
            Assert.IsTrue(app.m_oldAppWarningCalled);
        }
Esempio n. 5
0
        public void CheckDbVersionCompatability_NewApplication()
        {
            CheckDisposed();

            DummyFwApp app = m_app as DummyFwApp;

            // make dbversion known version
            app.m_internalDbVersion = 5000;
            // make app version newer than db version
            app.m_appVersion = 6000;
            app.CheckDbVerCompatibility(string.Empty, "TestLangProj");
            Assert.IsTrue(app.m_shouldUpgradeDatabaseCalled);
        }
        /// <summary>
        /// Helper method for CreateProjectLauncher tests.
        /// </summary>
        private void AssertCreateProjectLauncherWorks(string expectedPath)
        {
            using (var app = new DummyFwApp())
            {
                var dummyWindow = new DummyMainWindowDelegateCallbacks();
                dummyWindow.Cache = Cache;

                var window = new MainWindowDelegate(dummyWindow);
                window.App = app;

                window.CreateShortcut(Path.GetDirectoryName(expectedPath));

                Assert.That(FileUtils.SimilarFileExists(expectedPath), Is.True,
                            String.Format("Expected file does not exist: {0}", expectedPath));

                string actualLauncherData;
                byte[] launcherBuffer;
                using (var launcher = FileUtils.OpenStreamForRead(expectedPath))
                {
                    launcherBuffer = new byte[launcher.Length];
                    launcher.Read(launcherBuffer, 0, launcherBuffer.Length);
                }
                var enc = new UTF8Encoding(false);
                actualLauncherData = enc.GetString(launcherBuffer);

                var description = ResourceHelper.FormatResourceString(
                    "kstidCreateShortcutLinkDescription", Cache.ProjectId.UiName,
                    app.ApplicationName);
                string expectedLauncherData = String.Format(
                    "[Desktop Entry]{1}" +
                    "Version=1.0{1}" +
                    "Terminal=false{1}" +
                    "Exec=fieldworks-flex -db \"{0}\" -s \"\"{1}" +
                    "Icon=fieldworks-flex{1}" +
                    "Type=Application{1}" +
                    "Name={0}{1}" +
                    "Comment=" + description + "{1}",
                    m_projectName, Environment.NewLine);
                Assert.That(actualLauncherData, Is.EqualTo(expectedLauncherData));
            }
        }
Esempio n. 7
0
        public void IFwTool_CloseMainWnd()
        {
            CheckDisposed();

            // Preparations
            string     serverName = MiscUtils.LocalServerName;
            DummyFwApp app        = m_app as DummyFwApp;

            app.SetFdoCache(serverName, "TestLangProj", Cache);

            int pidNew;
            int hTool = m_app.NewMainWnd(serverName, "TestLangProj",
                                         1, 0, 0, 0, 0, out pidNew);

            app.m_mainWnd[0].Cache = Cache;

            // Here is what we want to test
            m_app.CloseMainWnd(hTool);

            Assert.IsTrue(app.m_mainWnd[0].m_fClosed);
        }
Esempio n. 8
0
        public void IFwTool_NewMainWnd()
        {
            CheckDisposed();

            int pidNew;
            int hTool = m_app.NewMainWnd(MiscUtils.LocalServerName, "TestLangProj",
                                         1, 0, 0, 0, 0, out pidNew);

            DummyFwApp app = m_app as DummyFwApp;

            Assert.IsNotNull(app.m_mainWnd[0]);
            Assert.IsTrue(app.m_mainWnd[0].m_fInitCalled);
            Assert.AreEqual(Process.GetCurrentProcess().Id, pidNew);
            Assert.AreEqual(app.m_mainWnd[0].Handle.ToInt32(), hTool);
            Assert.AreEqual(1, app.m_nSplashScreenShown, "ShowSplashScreen called multiple times");
            // This was taken out as we really don't care!
            //Assert.AreEqual(1, app.m_nSplashScreenClosed, "CloseSplashScreen called multiple times");
            Assert.AreEqual("Loading Project TestLangProj...\nInitializing Window...", app.m_SplashScreenMessages);
            app.m_mainWnd[0].Close();
            app.m_mainWnd[0].Dispose();
        }
        public void CreateShortcut_inNonExistentDirectory_notCreatedAndNoThrow()
        {
            var nonexistentDir = "/nonexistent";
            var path           = Path.Combine(nonexistentDir, m_projectName + m_pathExtension);

            Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
                        "Unit test error. Should be using a nonexistent directory.");

            using (var app = new DummyFwApp())
            {
                var dummyWindow = new DummyMainWindowDelegateCallbacks();
                dummyWindow.Cache = Cache;

                var window = new MainWindowDelegate(dummyWindow);
                window.App = app;

                Assert.DoesNotThrow(() => {
                    window.CreateShortcut(nonexistentDir);
                });
            }

            Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
                        "Nonexistent directory should not have been made to hold launcher.");
        }
		/// <summary>
		/// Helper method for CreateProjectLauncher tests.
		/// </summary>
		private void AssertCreateProjectLauncherWorks(string expectedPath)
		{
			using (var app = new DummyFwApp())
			{
				var dummyWindow = new DummyMainWindowDelegateCallbacks();
				dummyWindow.Cache = Cache;

				var window = new MainWindowDelegate(dummyWindow);
				window.App = app;

				window.CreateShortcut(Path.GetDirectoryName(expectedPath));

				Assert.That(FileUtils.SimilarFileExists(expectedPath), Is.True,
					String.Format("Expected file does not exist: {0}", expectedPath));

				string actualLauncherData;
				byte[] launcherBuffer;
				using (var launcher = FileUtils.OpenStreamForRead(expectedPath))
				{
					launcherBuffer = new byte[launcher.Length];
					launcher.Read(launcherBuffer, 0, launcherBuffer.Length);
				}
				var enc = new UTF8Encoding(false);
				actualLauncherData = enc.GetString(launcherBuffer);

				var description = ResourceHelper.FormatResourceString(
					"kstidCreateShortcutLinkDescription", Cache.ProjectId.UiName,
					app.ApplicationName);
				string expectedLauncherData = String.Format(
					"[Desktop Entry]{1}" +
					"Version=1.0{1}" +
					"Terminal=false{1}" +
					"Exec=fieldworks-flex -db \"{0}\" -s \"\"{1}" +
					"Icon=fieldworks-flex{1}" +
					"Type=Application{1}" +
					"Name={0}{1}" +
					"Comment=" + description + "{1}",
					m_projectName, Environment.NewLine);
				Assert.That(actualLauncherData, Is.EqualTo(expectedLauncherData));
			}
		}
		public void CreateShortcut_inNonExistentDirectory_notCreatedAndNoThrow()
		{
			var nonexistentDir = "/nonexistent";
			var path = Path.Combine(nonexistentDir, m_projectName + m_pathExtension);

			Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
				"Unit test error. Should be using a nonexistent directory.");

			using (var app = new DummyFwApp())
			{
				var dummyWindow = new DummyMainWindowDelegateCallbacks();
				dummyWindow.Cache = Cache;

				var window = new MainWindowDelegate(dummyWindow);
				window.App = app;

				Assert.DoesNotThrow(() => {
					window.CreateShortcut(nonexistentDir);
				});
			}

			Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
				"Nonexistent directory should not have been made to hold launcher.");
		}
Esempio n. 12
0
 public void Init()
 {
     CheckDisposed();
     m_DummyFwApp = new DummyFwApp(new string[] {
         "-c", m_sSvrName,					// ComputerName (aka the SQL server)
         "-proj", m_ProjName,				// ProjectName
         "-db", m_sDbName});					// DatabaseName;
 }
Esempio n. 13
0
        public void CleanUp()
        {
            CheckDisposed();
            if (m_DummyFwApp != null)
            {
                if (m_DummyFwApp.MainWindows != null && m_DummyFwApp.MainWindows.Count >  0)
                {
                    DummyFwMainWnd mainWindow = ((DummyFwMainWnd)m_DummyFwApp.MainWindows[0]);
                    if (mainWindow != null)
                    {
                        FdoCache cache = mainWindow.Cache;
                        if (cache != null)
                            while (cache.Undo());
                    }

                    m_DummyFwApp.ExitAppplication();
                }
                m_DummyFwApp.Dispose();
            }
            m_DummyFwApp = null;
        }
Esempio n. 14
0
		public override void FixtureSetup()
		{
			CheckDisposed();
			base.FixtureSetup();

			m_DummyFwApp = new WindowlessDummyFwApp(new string[] { "-c", m_sSvrName, "-db", m_sDbName });

			m_mainWnd = new InvisibleFwMainWnd();
			m_itemProps.ParentForm = m_mainWnd;
		}
Esempio n. 15
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected override void Dispose(bool disposing)
		{
			Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_DummyFwApp != null)
					m_DummyFwApp.Dispose();
				if (m_mainWnd != null)
					m_mainWnd.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_DummyFwApp = null;
			m_mainWnd = null;
			m_itemProps.ParentForm = null;

			base.Dispose(disposing);
		}