/// <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."); }