diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs new file mode 100644 index 0000000000..beb9c1491d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AbstractActivePackageFilesViewCommand.cs @@ -0,0 +1,40 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public abstract class AbstractActivePackageFilesViewCommand : AbstractMenuCommand + { + IWorkbench workbench; + ActivePackageFilesView activePackageFilesView; + + public AbstractActivePackageFilesViewCommand() + : this(WorkbenchSingleton.Workbench) + { + } + + public AbstractActivePackageFilesViewCommand(IWorkbench workbench) + { + this.workbench = workbench; + activePackageFilesView = new ActivePackageFilesView(workbench); + } + + public override void Run() + { + PackageFilesView view = activePackageFilesView.GetActiveView(); + if (view != null) { + Run(view); + } + } + + protected abstract void Run(PackageFilesView view); + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs index 94488731ca..1807895300 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs @@ -6,7 +6,7 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { @@ -14,11 +14,20 @@ namespace ICSharpCode.WixBinding /// Adds a directory and all its contents to the currently selected directory /// node. /// - public class AddDirectoryCommand : AbstractMenuCommand + public class AddDirectoryCommand : AbstractActivePackageFilesViewCommand { - public override void Run() + public AddDirectoryCommand() { - PackageFilesView.ActiveView.AddDirectory(); + } + + public AddDirectoryCommand(IWorkbench workbench) + : base(workbench) + { + } + + protected override void Run(PackageFilesView view) + { + view.AddDirectory(); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs index dbd64e09b3..aafdfe5bf1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddElementCommand.cs @@ -7,6 +7,7 @@ using System; using System.Windows.Forms; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { @@ -16,16 +17,29 @@ namespace ICSharpCode.WixBinding public class AddElementCommand : ToolStripMenuItem { string name; + IWorkbench workbench; + ActivePackageFilesView activePackageFilesView; - public AddElementCommand(string name) : base(name) + public AddElementCommand(string name) + : this(name, WorkbenchSingleton.Workbench) + { + } + + public AddElementCommand(string name, IWorkbench workbench) { this.name = name; + this.workbench = workbench; + activePackageFilesView = new ActivePackageFilesView(workbench); } protected override void OnClick(EventArgs e) { base.OnClick(e); - PackageFilesView.ActiveView.AddElement(name); + + PackageFilesView view = activePackageFilesView.GetActiveView(); + if (view != null) { + view.AddElement(name); + } } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs new file mode 100644 index 0000000000..2be1582f0d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesCommand.cs @@ -0,0 +1,30 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public class AddFilesCommand : AbstractActivePackageFilesViewCommand + { + public AddFilesCommand() + { + } + + public AddFilesCommand(IWorkbench workbench) + : base(workbench) + { + } + + protected override void Run(PackageFilesView view) + { + view.AddFiles(); + } + } +} + diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs index c4986b3764..a22a99ec33 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/HideDiffCommand.cs @@ -6,18 +6,27 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { /// /// Hides the diff control from the Setup Files window. /// - public class HideDiffCommand : AbstractMenuCommand + public class HideDiffCommand : AbstractActivePackageFilesViewCommand { - public override void Run() + public HideDiffCommand() { - PackageFilesView.ActiveView.HideDiff(); + } + + public HideDiffCommand(IWorkbench workbench) + : base(workbench) + { + } + + protected override void Run(PackageFilesView view) + { + view.HideDiff(); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs index cac5de603c..81639038c6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/RemoveElementCommand.cs @@ -6,18 +6,27 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { /// /// Remove the selected element from the Wix document. /// - public class RemoveElementCommand : AbstractMenuCommand + public class RemoveElementCommand : AbstractActivePackageFilesViewCommand { - public override void Run() + public RemoveElementCommand() { - PackageFilesView.ActiveView.RemoveSelectedElement(); + } + + public RemoveElementCommand(IWorkbench workbench) + : base(workbench) + { + } + + protected override void Run(PackageFilesView view) + { + view.RemoveSelectedElement(); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs index 8d3db88f82..e05225f1bc 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ShowDiffCommand.cs @@ -6,15 +6,24 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { - public class ShowDiffCommand : AbstractMenuCommand + public class ShowDiffCommand : AbstractActivePackageFilesViewCommand { - public override void Run() + public ShowDiffCommand() { - PackageFilesView.ActiveView.ShowDiff(); + } + + public ShowDiffCommand(IWorkbench workbench) + : base(workbench) + { + } + + protected override void Run(PackageFilesView view) + { + view.CalculateDiff(); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs index 5cb00cb648..dceeb2ab29 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewDialogXmlCommand.cs @@ -54,7 +54,8 @@ namespace ICSharpCode.WixBinding try { WorkbenchTextFileReader workbenchTextFileReader = new WorkbenchTextFileReader(); using (TextReader reader = workbenchTextFileReader.Create(fileName)) { - return WixDocument.GetStartElementLocation(reader, "Dialog", id); + WixDocumentReader wixReader = new WixDocumentReader(reader); + return wixReader.GetStartElementLocation("Dialog", id); } } catch (XmlException ex) { WixBindingService.ShowErrorInErrorList(fileName, ex); diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs index c434951d52..e4e9c34311 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/ViewSetupFilesCommand.cs @@ -17,12 +17,54 @@ namespace ICSharpCode.WixBinding /// public class ViewSetupFilesCommand : AbstractMenuCommand { + IPackageFilesViewFactory factory; + IWorkbench workbench; + + public ViewSetupFilesCommand() + : this(new PackageFilesViewFactory(), WorkbenchSingleton.Workbench) + { + } + + public ViewSetupFilesCommand(IPackageFilesViewFactory factory, IWorkbench workbench) + { + this.factory = factory; + this.workbench = workbench; + } + public override void Run() { WixProject project = ProjectService.CurrentProject as WixProject; if (project != null) { - PackageFilesView.Show(project, WorkbenchSingleton.Workbench); + Run(project); } } + + public void Run(WixProject project) + { + PackageFilesView openView = GetOpenPackageFilesView(project); + if (openView != null) { + openView.WorkbenchWindow.SelectWindow(); + } else { + OpenNewPackageFilesView(project); + } + } + + void OpenNewPackageFilesView(WixProject project) + { + PackageFilesView view = factory.Create(project, workbench); + workbench.ShowView(view); + view.ShowFiles(); + } + + PackageFilesView GetOpenPackageFilesView(WixProject project) + { + foreach (IViewContent view in workbench.ViewContentCollection) { + PackageFilesView packageFilesView = view as PackageFilesView; + if ((packageFilesView != null) && (packageFilesView.IsForProject(project))) { + return packageFilesView; + } + } + return null; + } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs new file mode 100644 index 0000000000..ef40fc921f --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/DefaultFileLoader.cs @@ -0,0 +1,28 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Drawing; +using System.IO; + +namespace ICSharpCode.WixBinding +{ + public class DefaultFileLoader : IFileLoader + { + public DefaultFileLoader() + { + } + + public Bitmap LoadBitmap(string fileName) + { + if (File.Exists(fileName)) { + return new Bitmap(fileName); + } + return null; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs new file mode 100644 index 0000000000..508ab37a58 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/ActivePackageFilesView.cs @@ -0,0 +1,27 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public class ActivePackageFilesView + { + IWorkbench workbench; + + public ActivePackageFilesView(IWorkbench workbench) + { + this.workbench = workbench; + } + + public PackageFilesView GetActiveView() + { + return workbench.ActiveContent as PackageFilesView; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs similarity index 63% rename from src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs rename to src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs index 06dbadcba2..752837629a 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/IFormsDesignerView.cs @@ -6,15 +6,12 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; namespace ICSharpCode.WixBinding { - public class AddFilesToComponentCommand : AbstractMenuCommand + public interface IFormsDesignerView { - public override void Run() - { - PackageFilesView.ActiveView.AddFiles(); - } + OpenedFile PrimaryFile { get; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs new file mode 100644 index 0000000000..37fdd535b5 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/OpenTextEditors.cs @@ -0,0 +1,42 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public class OpenTextEditors + { + IWorkbench workbench; + + public OpenTextEditors(IWorkbench workbench) + { + this.workbench = workbench; + } + + public ITextEditor FindTextEditorForDocument(WixDocument document) + { + foreach (IViewContent view in workbench.ViewContentCollection) { + ITextEditorProvider textEditorProvider = view as ITextEditorProvider; + if (textEditorProvider != null) { + if (AreFileNamesEqual(view.PrimaryFileName, document.FileName)) { + return textEditorProvider.TextEditor; + } + } + } + return null; + } + + bool AreFileNamesEqual(FileName lhs, string rhs) + { + return FileUtility.IsEqualFileName(lhs.ToString(), rhs); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs index 9c04ca082b..a036215aaa 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs @@ -10,59 +10,79 @@ using System.IO; using System.Windows.Forms; using System.Xml; +using ICSharpCode.AvalonEdit; +using ICSharpCode.AvalonEdit.AddIn.Options; using ICSharpCode.Core; using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Gui; -using ICSharpCode.TextEditor; -using ICSharpCode.TextEditor.Document; namespace ICSharpCode.WixBinding { /// /// Displays the setup package files. /// - public class PackageFilesView : AbstractViewContentWithoutFile, ITextFileReader, IWixDocumentWriter + public class PackageFilesView : AbstractViewContentWithoutFile, IWixDocumentWriter { - WixPackageFilesControl packageFilesControl; - WorkbenchTextFileReader textFileReader = new WorkbenchTextFileReader(); + IWixPackageFilesControl packageFilesControl; WixProject project; + IWorkbench workbench; bool reload; - - public override object Control { - get { - return packageFilesControl; - } + WixDocumentWindow wixDocumentWindow; + OpenTextEditors openTextEditors; + WixTextWriter wixTextWriter; + + public PackageFilesView(WixProject project, IWorkbench workbench) + : this(project, workbench, new WixPackageFilesControl()) + { } - PackageFilesView(WixProject project) + public PackageFilesView(WixProject project, IWorkbench workbench, IWixPackageFilesControl packageFilesControl) + : this(project, workbench, packageFilesControl, null) { - packageFilesControl = new WixPackageFilesControl(); + wixTextWriter = new WixTextWriter(GetTextEditorOptions()); + } + + public PackageFilesView(WixProject project, + IWorkbench workbench, + IWixPackageFilesControl packageFilesControl, + WixTextWriter wixTextWriter) + { + this.packageFilesControl = packageFilesControl; packageFilesControl.DirtyChanged += delegate { base.RaiseIsDirtyChanged(); }; SetLocalizedTitle("${res:ICSharpCode.WixBinding.PackageFilesView.Title}"); this.project = project; - WorkbenchSingleton.Workbench.ActiveViewContentChanged += ActiveViewContentChanged; + this.workbench = workbench; + wixDocumentWindow = new WixDocumentWindow(workbench); + workbench.ActiveViewContentChanged += ActiveViewContentChanged; + + this.wixTextWriter = wixTextWriter; + + openTextEditors = new OpenTextEditors(workbench); } - public static PackageFilesView ActiveView { - get { - return WorkbenchSingleton.Workbench.ActiveContent as PackageFilesView; - } + static ITextEditorOptions GetTextEditorOptions() + { + ICSharpCode.AvalonEdit.TextEditor editor = new ICSharpCode.AvalonEdit.TextEditor(); + AvalonEditTextEditorAdapter adapter = new AvalonEditTextEditorAdapter(editor); + return adapter.Options; } - /// - /// Gets the project that this view is associated with. - /// - public WixProject Project { - get { - return project; - } - set { - project = value; - } + public override object Control { + get { return packageFilesControl; } + } + + public bool IsActiveWindow { + get { return Object.ReferenceEquals(workbench.ActiveViewContent, this); } + } + + public bool IsForProject(WixProject project) + { + return this.project == project; } public override void Load() @@ -75,46 +95,28 @@ namespace ICSharpCode.WixBinding } public override bool IsDirty { - get { - return packageFilesControl.IsDirty; - } - } - - /// - /// Shows the view for the specified project. - /// - public static void Show(WixProject project, IWorkbench workbench) - { - PackageFilesView openView = GetOpenPackageFilesView(project, workbench); - if (openView != null) { - openView.WorkbenchWindow.SelectWindow(); - } else { - PackageFilesView newView = new PackageFilesView(project); - workbench.ShowView(newView); - newView.ShowFiles(); - } + get { return packageFilesControl.IsDirty; } } public override void Dispose() { if (packageFilesControl != null) { - WorkbenchSingleton.Workbench.ActiveViewContentChanged -= ActiveViewContentChanged; + workbench.ActiveViewContentChanged -= ActiveViewContentChanged; packageFilesControl.Dispose(); packageFilesControl = null; } base.Dispose(); } - public TextReader Create(string fileName) - { - return textFileReader.Create(fileName); - } - public void Write(WixDocument document) { - if (!UpdateOpenFile(document)) { - ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance; - document.Save(properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize); + ITextEditor openTextEditor = openTextEditors.FindTextEditorForDocument(document); + if (openTextEditor != null) { + UpdateOpenTextEditor(openTextEditor, document); + } else { + using (XmlWriter xmlWriter = wixTextWriter.Create(document.FileName)) { + document.Save(xmlWriter); + } } packageFilesControl.IsDirty = false; } @@ -145,7 +147,7 @@ namespace ICSharpCode.WixBinding public void ShowFiles() { - packageFilesControl.ShowFiles(project, this, this); + packageFilesControl.ShowFiles(project, new WorkbenchTextFileReader(), this); } /// @@ -157,9 +159,9 @@ namespace ICSharpCode.WixBinding packageFilesControl.AddDirectory(); } - public void ShowDiff() + public void CalculateDiff() { - packageFilesControl.ShowDiff(); + packageFilesControl.CalculateDiff(); } public void HideDiff() @@ -167,46 +169,13 @@ namespace ICSharpCode.WixBinding packageFilesControl.IsDiffVisible = false; } - /// - /// Gets the package files view that is already open and displaying the files - /// for the specified project. - /// - static PackageFilesView GetOpenPackageFilesView(WixProject project, IWorkbench workbench) - { - foreach (IViewContent view in workbench.ViewContentCollection) { - PackageFilesView packageFilesView = view as PackageFilesView; - if (packageFilesView != null && packageFilesView.Project == project) { - return packageFilesView; - } - } - return null; - } - - TextAreaControl GetTextAreaControl(string fileName) - { - ITextEditorControlProvider textEditorControlProvider = FileService.GetOpenFile(fileName) as ITextEditorControlProvider; - if (textEditorControlProvider != null) { - return textEditorControlProvider.TextEditorControl.ActiveTextAreaControl; - } - return null; - } - - /// - /// Merges the changes to the Wix document to the file currently open in - /// SharpDevelop. - /// - bool UpdateOpenFile(WixDocument wixDocument) + void UpdateOpenTextEditor(ITextEditor textEditor, WixDocument document) { - TextAreaControl textAreaControl = GetTextAreaControl(packageFilesControl.Document.FileName); - if (textAreaControl != null) { - if (wixDocument.IsProductDocument) { - UpdateOpenFileWithRootDirectoryChanges(wixDocument, textAreaControl); - } else { - // Directory ref. - UpdateOpenFileWithRootDirectoryRefChanges(wixDocument, textAreaControl); - } + if (document.HasProduct) { + UpdateOpenTextEditorWithRootDirectoryChanges(textEditor, document); + } else { + UpdateOpenTextEditorWithRootDirectoryRefChanges(textEditor, document); } - return false; } /// @@ -221,8 +190,11 @@ namespace ICSharpCode.WixBinding // Set IsDirty to false first since we get another workbench window // changed event whilst updating the open file. The // DefaultDocument.Replace method triggers this. - packageFilesControl.IsDirty= false; - UpdateOpenFile(packageFilesControl.Document); + ITextEditor textEditor = openTextEditors.FindTextEditorForDocument(packageFilesControl.Document); + if (textEditor != null) { + UpdateOpenTextEditor(textEditor, packageFilesControl.Document); + packageFilesControl.IsDirty = false; + } } reload = true; } else if (reload && IsActiveWindow) { @@ -231,93 +203,40 @@ namespace ICSharpCode.WixBinding } } - /// - /// Checks whether the active window is the Wix document window. - /// bool IsWixDocumentWindowActive { - get { - WixDocument document = packageFilesControl.Document; - if (document != null) { - IViewContent view = WorkbenchSingleton.Workbench.ActiveViewContent; - if (view != null) { - return FileUtility.IsEqualFileName(view.PrimaryFileName, document.FileName); - } - } - return false; - } + get { return wixDocumentWindow.IsActive(packageFilesControl.Document); } } - /// - /// Checks whether the active window is this window. - /// - bool IsActiveWindow { - get { - return Object.ReferenceEquals(WorkbenchSingleton.Workbench.ActiveViewContent, this); - } - } - - bool UpdateOpenFileWithRootDirectoryChanges(WixDocument wixDocument, TextAreaControl textAreaControl) + void UpdateOpenTextEditorWithRootDirectoryChanges(ITextEditor textEditor, WixDocument document) { - // Get the xml for the root directory. - WixDirectoryElement rootDirectory = wixDocument.RootDirectory; - string xml = GetWixXml(rootDirectory); - - // Find the root directory location. - bool updated = ReplaceElement(rootDirectory.Id, WixDirectoryElement.DirectoryElementName, textAreaControl, xml); - if (updated) { - return true; + WixDirectoryElement rootDirectory = document.GetRootDirectory(); + string xml = rootDirectory.GetXml(wixTextWriter); + + WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor); + DomRegion region = documentEditor.ReplaceElement(rootDirectory.Id, WixDirectoryElement.DirectoryElementName, xml); + if (!region.IsEmpty) { + return; } // Find the product end element location. - IDocument document = textAreaControl.Document; - Location location = WixDocument.GetEndElementLocation(new StringReader(document.TextContent), "Product", wixDocument.Product.GetAttribute("Id")); + XmlElement productElement = document.GetProduct(); + StringReader reader = new StringReader(textEditor.Document.Text); + string productId = productElement.GetAttribute("Id"); + WixDocumentReader wixReader = new WixDocumentReader(reader); + Location location = wixReader.GetEndElementLocation("Product", productId); if (!location.IsEmpty) { // Insert the xml with an extra new line at the end. - ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance; - WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl); - documentEditor.Insert(location.Y, location.X, String.Concat(xml, properties.LineTerminator)); - return true; + documentEditor.InsertIndented(location, String.Concat(xml, "\r\n")); } - return false; } - bool UpdateOpenFileWithRootDirectoryRefChanges(WixDocument wixDocument, TextAreaControl textAreaControl) + void UpdateOpenTextEditorWithRootDirectoryRefChanges(ITextEditor textEditor, WixDocument document) { - // Get the xml for the root directory ref. - WixDirectoryRefElement rootDirectoryRef = wixDocument.RootDirectoryRef; - string xml = GetWixXml(rootDirectoryRef); - - // Find the root directory ref location. - return ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, textAreaControl, xml); - } - - /// - /// Gets the Wix xml for the specified element. - /// - string GetWixXml(XmlElement element) - { - ITextEditorProperties properties = SharpDevelopTextEditorProperties.Instance; - return WixDocument.GetXml(element, properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize); - } - - /// - /// Tries to replace the element defined by element name and its Id attribute in the - /// text editor with the specified xml. - /// - /// The Id attribute of the element. - /// The name of the element. - /// The text area control to update. - /// The replacement xml. - bool ReplaceElement(string id, string elementName, TextAreaControl textAreaControl, string xml) - { - WixDocumentEditor documentEditor = new WixDocumentEditor(textAreaControl); - IDocument document = textAreaControl.Document; - DomRegion region = WixDocument.GetElementRegion(new StringReader(document.TextContent), elementName, id); - if (!region.IsEmpty) { - documentEditor.Replace(region, xml); - return true; - } - return false; + WixDirectoryRefElement rootDirectoryRef = document.GetRootDirectoryRef(); + string xml = rootDirectoryRef.GetXml(wixTextWriter); + + WixDocumentEditor documentEditor = new WixDocumentEditor(textEditor); + documentEditor.ReplaceElement(rootDirectoryRef.Id, WixDirectoryRefElement.DirectoryRefElementName, xml); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs index 9e026deabe..cea941cc5c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/SetupDialogListPad.cs @@ -140,7 +140,8 @@ namespace ICSharpCode.WixBinding { WorkbenchTextFileReader workbenchTextFileReader = new WorkbenchTextFileReader(); using (TextReader reader = workbenchTextFileReader.Create(fileName)) { - setupDialogListView.AddDialogs(fileName, WixDocument.GetDialogIds(reader)); + WixDocumentReader wixReader = new WixDocumentReader(reader); + setupDialogListView.AddDialogs(fileName, wixReader.GetDialogIds()); } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs index 492ee0fc7e..6eba959202 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesigner.cs @@ -5,7 +5,6 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Refactoring; using System; using System.Collections.ObjectModel; using System.IO; @@ -13,10 +12,10 @@ using System.Xml; using ICSharpCode.FormsDesigner; using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.TextEditor; +using ICSharpCode.SharpDevelop.Refactoring; namespace ICSharpCode.WixBinding { @@ -88,8 +87,8 @@ namespace ICSharpCode.WixBinding // and text selection operations done by the WiX designer actually // become visible in the text editor. if (!this.SourceCodeStorage.ContainsFile(file)) { - TextEditorControl editor = ((ITextEditorControlProvider)this.PrimaryViewContent).TextEditorControl; - this.SourceCodeStorage.AddFile(file, new TextEditorDocument(editor.Document), editor.Encoding ?? ParserService.DefaultFileEncoding, true); + ITextEditor editor = ((ITextEditorProvider)this.PrimaryViewContent).TextEditor; + this.SourceCodeStorage.AddFile(file, editor.Document, ParserService.DefaultFileEncoding, true); } try { @@ -120,7 +119,7 @@ namespace ICSharpCode.WixBinding public override bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView) { - return newView == this || newView == this.PrimaryViewContent; + return (newView == this) || (newView == this.PrimaryViewContent); } public override void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView) @@ -132,8 +131,8 @@ namespace ICSharpCode.WixBinding public override bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView) { - return this.DesignerCodeFile != null && - (oldView == this || oldView == this.PrimaryViewContent); + return (this.DesignerCodeFile != null) && + ((oldView == this) || (oldView == this.PrimaryViewContent)); } public override void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView) @@ -149,18 +148,14 @@ namespace ICSharpCode.WixBinding /// Gets the Wix document filename. /// public string DocumentFileName { - get { - return this.PrimaryFileName; - } + get { return this.PrimaryFileName; } } /// /// Gets the wix project containing the document open in the designer. /// public WixProject Project { - get { - return wixProject; - } + get { return wixProject; } } /// @@ -203,9 +198,11 @@ namespace ICSharpCode.WixBinding /// string GetDialogIdSelectedInTextEditor() { - TextAreaControl textArea = ActiveTextAreaControl; - if (textArea != null) { - return WixDocument.GetDialogId(new StringReader(textArea.Document.TextContent), textArea.Caret.Line); + ITextEditor textEditor = ActiveTextEditor; + if (textEditor != null) { + StringReader reader = new StringReader(textEditor.Document.Text); + WixDocumentReader wixReader = new WixDocumentReader(reader); + return wixReader.GetDialogId(textEditor.Caret.Line); } return null; } @@ -215,10 +212,11 @@ namespace ICSharpCode.WixBinding /// string GetFirstDialogIdInTextEditor() { - TextAreaControl textArea = ActiveTextAreaControl; - if (textArea != null) { - StringReader reader = new StringReader(textArea.Document.TextContent); - ReadOnlyCollection ids = WixDocument.GetDialogIds(reader); + ITextEditor textEditor = ActiveTextEditor; + if (textEditor != null) { + StringReader reader = new StringReader(textEditor.Document.Text); + WixDocumentReader wixReader = new WixDocumentReader(reader); + ReadOnlyCollection ids = wixReader.GetDialogIds(); if (ids.Count > 0) { return ids[0]; } @@ -229,11 +227,11 @@ namespace ICSharpCode.WixBinding /// /// Gets the active text area control. /// - TextAreaControl ActiveTextAreaControl { + ITextEditor ActiveTextEditor { get { - ITextEditorControlProvider provider = this.PrimaryViewContent as ITextEditorControlProvider; + ITextEditorProvider provider = this.PrimaryViewContent as ITextEditorProvider; if (provider != null) { - return provider.TextEditorControl.ActiveTextAreaControl; + return provider.TextEditor; } return null; } @@ -274,10 +272,12 @@ namespace ICSharpCode.WixBinding { try { if (dialogId != null) { - TextAreaControl textArea = ActiveTextAreaControl; - if (textArea != null) { - Location location = WixDocument.GetStartElementLocation(new StringReader(textArea.Document.TextContent), "Dialog", dialogId); - textArea.JumpTo(location.Y); + ITextEditor textEditor = ActiveTextEditor; + if (textEditor != null) { + StringReader reader = new StringReader(textEditor.Document.Text); + WixDocumentReader wixReader = new WixDocumentReader(reader); + Location location = wixReader.GetStartElementLocation("Dialog", dialogId); + textEditor.JumpTo(location.Y, 1); } } } catch (XmlException) { @@ -301,9 +301,7 @@ namespace ICSharpCode.WixBinding public override object ToolsContent { - get { - return SetupDialogControlsToolBox; - } + get { return SetupDialogControlsToolBox; } } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs index f9b9e069af..e310f39bd0 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerDisplayBinding.cs @@ -7,7 +7,7 @@ using System; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding @@ -19,38 +19,30 @@ namespace ICSharpCode.WixBinding } public bool ReattachWhenParserServiceIsReady { - get { - return false; - } + get { return false; } } /// /// Wix dialog designer can attach to Wix source files (.wxs) and /// Wix include files (.wxi). /// - public bool CanAttachTo(IViewContent content) + public bool CanAttachTo(IViewContent view) { - ITextEditorControlProvider textAreaControlProvider = content as ITextEditorControlProvider; - if (textAreaControlProvider == null) { - return false; - } - - string fileName = GetViewContentFileName(content); - if (fileName == null) { - return false; + if (IsViewTextEditorProvider(view)) { + return WixFileName.IsWixFileName(view.PrimaryFileName); } - - return WixDocument.IsWixFileName(fileName); + return false; } - public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent) + public IViewContent[] CreateSecondaryViewContent(IViewContent view) { - return new IViewContent[] {new WixDialogDesigner(viewContent)}; + return new IViewContent[] {new WixDialogDesigner(view)}; } - static string GetViewContentFileName(IViewContent viewContent) + bool IsViewTextEditorProvider(IViewContent view) { - return viewContent.PrimaryFileName; + ITextEditorProvider textEditorProvider = view as ITextEditorProvider; + return textEditorProvider != null; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs index ad7cb07854..3a3fca65d1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs @@ -18,7 +18,6 @@ using System.Xml; using ICSharpCode.Core; using ICSharpCode.FormsDesigner; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.TextEditor; @@ -44,30 +43,26 @@ namespace ICSharpCode.WixBinding public class WixDialogDesignerGenerator : IDesignerGenerator, IWixDialogDesignerGenerator { FormsDesignerViewContent view; - - public WixDialogDesignerGenerator() - { - } + ITextEditor textEditor; public CodeDomProvider CodeDomProvider { - get { - return new CSharpCodeProvider(); - } + get { return new CSharpCodeProvider(); } } public FormsDesignerViewContent ViewContent { - get { return this.view; } + get { return view; } } public IEnumerable GetSourceFiles(out OpenedFile designerCodeFile) { - designerCodeFile = this.view.PrimaryFile; + designerCodeFile = view.PrimaryFile; return new [] {designerCodeFile}; } - public void Attach(FormsDesignerViewContent viewContent) + public void Attach(FormsDesignerViewContent view) { - this.view = viewContent; + this.view = view; + textEditor = ((ITextEditorProvider)view.PrimaryViewContent).TextEditor; } public void Detach() @@ -80,20 +75,32 @@ namespace ICSharpCode.WixBinding /// void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement) { - // Get the text region we are replacing. - IDocument document = view.DesignerCodeFileDocument; - DomRegion region = WixDocument.GetElementRegion(new StringReader(document.Text), "Dialog", dialogId); + DomRegion region = GetTextEditorRegionForDialogElement(dialogId); if (region.IsEmpty) { - throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), dialogId)); + ThrowDialogElementCouldNotBeFoundError(dialogId); } - // Get the replacement dialog xml. - TextEditorControl textEditorControl = ((ITextEditorControlProvider)view.PrimaryViewContent).TextEditorControl; - var properties = textEditorControl.TextEditorProperties; - string replacementXml = WixDocument.GetXml(dialogElement, properties.LineTerminator, properties.ConvertTabsToSpaces, properties.IndentationSize); - - // Replace the xml and select the inserted text. - WixDocumentEditor editor = new WixDocumentEditor(textEditorControl.ActiveTextAreaControl); - editor.Replace(region, replacementXml); + + WixTextWriter writer = new WixTextWriter(textEditor.Options); + WixDialogElement wixDialogElement = (WixDialogElement)dialogElement; + string newDialogXml = wixDialogElement.GetXml(writer); + + WixDocumentEditor editor = new WixDocumentEditor(textEditor); + editor.Replace(region, newDialogXml); + } + + DomRegion GetTextEditorRegionForDialogElement(string dialogId) + { + IDocument document = view.DesignerCodeFileDocument; + StringReader reader = new StringReader(document.Text); + WixDocumentReader wixReader = new WixDocumentReader(reader); + return wixReader.GetElementRegion("Dialog", dialogId); + } + + void ThrowDialogElementCouldNotBeFoundError(string dialogId) + { + string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"); + string message = String.Format(messageFormat, dialogId); + throw new FormsDesignerLoadException(message); } public void MergeFormChanges(CodeCompileUnit unit) diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs index 76b1b53d80..1fd0f0d7b2 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerLoader.cs @@ -10,6 +10,7 @@ using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Security.Permissions; using System.Windows.Forms; +using System.Xml; using ICSharpCode.Core; using ICSharpCode.FormsDesigner; @@ -27,7 +28,7 @@ namespace ICSharpCode.WixBinding IWixDialogDesigner designer; public WixDialogDesignerLoader(IWixDialogDesigner designer, IWixDialogDesignerGenerator generator) - : this(designer, generator, null) + : this(designer, generator, new DefaultFileLoader()) { } @@ -42,51 +43,83 @@ namespace ICSharpCode.WixBinding this.fileLoader = fileLoader; if (designer == null) { - throw new ArgumentException("Cannot be null.", "designer"); + throw new ArgumentNullException("designer"); } if (generator == null) { - throw new ArgumentException("Cannot be null.", "generator"); + throw new ArgumentNullException("generator"); } } - /// - /// Gets the designer used by the loader. - /// public IWixDialogDesigner Designer { - get { - return designer; - } + get { return designer; } } - /// - /// Gets the designer generator used by the loader. - /// public IWixDialogDesignerGenerator Generator { - get { - return generator; - } + get { return generator; } } public override void BeginLoad(IDesignerLoaderHost host) { - // Check dialog id. - if (designer.DialogId == null) { - throw new FormsDesignerLoadException(StringParser.Parse("${res:ICSharpCode.WixBinding.WixDialogDesigner.NoDialogSelectedInDocumentMessage}")); - } + VerifyDesignerHasDialogId(); - // Get dialog element. + GetDialogElement(); + VerifyDialogElementFound(); + + AddServicesToHost(host); + + base.BeginLoad(host); + } + + void VerifyDesignerHasDialogId() + { + if (DesignerHasDialogId) { + ThrowNoDialogSelectedInDocumentException(); + } + } + + bool DesignerHasDialogId { + get { return designer.DialogId == null; } + } + + void ThrowNoDialogSelectedInDocumentException() + { + string message = StringParser.Parse("${res:ICSharpCode.WixBinding.WixDialogDesigner.NoDialogSelectedInDocumentMessage}"); + throw new FormsDesignerLoadException(message); + } + + void GetDialogElement() + { WixDocument document = CreateWixDocument(); document.LoadXml(designer.GetDocumentXml()); - wixDialog = document.GetDialog(designer.DialogId, new WorkbenchTextFileReader()); + wixDialog = document.CreateWixDialog(designer.DialogId, new WorkbenchTextFileReader()); + } + + WixDocument CreateWixDocument() + { + WixDocument document = new WixDocument(designer.Project, fileLoader); + document.FileName = designer.DocumentFileName; + return document; + } + + void VerifyDialogElementFound() + { if (wixDialog == null) { - throw new FormsDesignerLoadException(String.Format(StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"), designer.DialogId)); + ThrowDialogIdNotFoundException(designer.DialogId); } - + } + + void ThrowDialogIdNotFoundException(string dialogId) + { + string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}"); + string message = String.Format(messageFormat, designer.DialogId); + throw new FormsDesignerLoadException(message); + } + + void AddServicesToHost(IDesignerLoaderHost host) + { host.AddService(typeof(ComponentSerializationService), new CodeDomComponentSerializationService((IServiceProvider)host)); host.AddService(typeof(INameCreationService), new XmlDesignerNameCreationService(host)); host.AddService(typeof(IDesignerSerializationService), new DesignerSerializationService(host)); - - base.BeginLoad(host); } /// @@ -103,28 +136,24 @@ namespace ICSharpCode.WixBinding /// protected override void PerformFlush(IDesignerSerializationManager serializationManager) { - Form dialog = (Form)base.LoaderHost.RootComponent; - generator.MergeFormChanges(designer.DialogId, wixDialog.UpdateDialogElement(dialog)); + XmlElement updatedDialogElement = GenerateNewDialogElementFromDesignedForm(); + MergeDialogChangesIntoFullWixDocument(updatedDialogElement); } - protected override void PerformLoad(IDesignerSerializationManager serializationManager) + XmlElement GenerateNewDialogElementFromDesignedForm() { - wixDialog.CreateDialog(this); + Form form = (Form)base.LoaderHost.RootComponent; + return wixDialog.UpdateDialogElement(form); } - WixDocument CreateWixDocument() + void MergeDialogChangesIntoFullWixDocument(XmlElement updatedDialogElement) { - WixDocument document; - - if (fileLoader != null && designer != null) { - document = new WixDocument(designer.Project, fileLoader); - } else if (designer != null) { - document = new WixDocument(designer.Project); - } else { - document = new WixDocument(); - } - document.FileName = designer.DocumentFileName; - return document; + generator.MergeFormChanges(designer.DialogId, updatedDialogElement); + } + + protected override void PerformLoad(IDesignerSerializationManager serializationManager) + { + wixDialog.CreateDialog(this); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs index 8662453d86..59afb3d720 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs @@ -6,24 +6,45 @@ // using System; -using System.Drawing; +using System.IO; +using System.Text; +using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.TextEditor; -using ICSharpCode.TextEditor.Document; +using ICSharpCode.SharpDevelop.Editor; namespace ICSharpCode.WixBinding { /// /// A utility class that can replace xml in a Wix document currently open /// in the text editor. - /// + /// public class WixDocumentEditor { - TextAreaControl textAreaControl; + ITextEditor textEditor; + IDocument document; - public WixDocumentEditor(TextAreaControl textAreaControl) + public WixDocumentEditor(ITextEditor textEditor) { - this.textAreaControl = textAreaControl; + this.textEditor = textEditor; + this.document = textEditor.Document; + } + + + /// + /// Tries to replace the element defined by element name and its Id attribute in the + /// text editor with the specified xml. + /// + /// The Id attribute of the element. + /// The name of the element. + /// The replacement xml. + public DomRegion ReplaceElement(string elementAttributeId, string elementName, string replacementXml) + { + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(document.Text)); + DomRegion region = wixReader.GetElementRegion(elementName, elementAttributeId); + if (!region.IsEmpty) { + Replace(region, replacementXml); + } + return region; } /// @@ -32,92 +53,146 @@ namespace ICSharpCode.WixBinding /// public void Replace(DomRegion region, string xml) { - IDocument document = textAreaControl.Document; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); - - // Replace the original xml with the new xml and indent it. - int originalLineCount = document.TotalNumberOfLines; - document.Replace(segment.Offset, segment.Length, xml); - int addedLineCount = document.TotalNumberOfLines - originalLineCount; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); - // Make sure the text inserted is visible. - textAreaControl.ScrollTo(region.BeginLine); + using (textEditor.Document.OpenUndoGroup()) { - // Indent the xml. - int insertedCharacterCount = IndentLines(textAreaControl.TextArea, region.BeginLine + 1, region.EndLine + addedLineCount, document.FormattingStrategy); + // Replace the original xml with the new xml and indent it. + int originalLineCount = document.TotalNumberOfLines; + int initialIndent = GetIndent(region.BeginLine); + document.Replace(segment.Offset, segment.Length, xml); + int addedLineCount = document.TotalNumberOfLines - originalLineCount; + + // Indent the xml. + int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent); + + // Select the text just inserted. + int textInsertedLength = insertedCharacterCount + xml.Length; + textEditor.Select(segment.Offset, textInsertedLength); - // Select the text just inserted. - SelectText(textAreaControl.SelectionManager, document, segment.Offset, xml.Length + insertedCharacterCount); + // Make sure the text inserted is visible. + textEditor.JumpTo(region.BeginLine + 1, 1); + + textEditor.Caret.Position = document.OffsetToPosition(segment.Offset + textInsertedLength); + } } - /// - /// Inserts and indents the xml at the specified location. - /// - public void Insert(int line, int column, string xml) + public void InsertIndented(Location location, string xml) { - IDocument document = textAreaControl.Document; - ISegment segment = document.GetLineSegment(line); - - // Insert the xml and indent it. - int originalLineCount = document.TotalNumberOfLines; - int offset = segment.Offset + column; - document.Insert(offset, xml); - int addedLineCount = document.TotalNumberOfLines - originalLineCount; - - // Make sure the text inserted is visible. - textAreaControl.ScrollTo(line); - - // Indent the xml. - int insertedCharacterCount = IndentLines(textAreaControl.TextArea, line, line + addedLineCount, document.FormattingStrategy); - - // Select the text just inserted. - SelectText(textAreaControl.SelectionManager, document, offset, xml.Length + insertedCharacterCount); + InsertIndented(location.Y, location.X, xml); } /// - /// Selects the specified text range. + /// Inserts and indents the xml at the specified location. /// - static void SelectText(SelectionManager selectionManager, IDocument document, int startOffset, int length) + /// + /// Lines and columns are zero based. + /// + public void InsertIndented(int line, int column, string xml) { - selectionManager.ClearSelection(); - TextLocation selectionStart = document.OffsetToPosition(startOffset); - TextLocation selectionEnd = document.OffsetToPosition(startOffset + length); - selectionManager.SetSelection(selectionStart, selectionEnd); + using (textEditor.Document.OpenUndoGroup()) { + + // Insert the xml and indent it. + IDocumentLine documentLine = document.GetLine(line + 1); + int initialIndent = GetIndent(line); + int offset = documentLine.Offset + column; + int originalLineCount = document.TotalNumberOfLines; + document.Insert(offset, xml); + int addedLineCount = document.TotalNumberOfLines - originalLineCount; + + // Indent the xml. + int insertedCharacterCount = IndentLines(line, line + addedLineCount, initialIndent); + + // Select the text just inserted. + int textInsertedLength = xml.Length + insertedCharacterCount; + textEditor.Select(offset, textInsertedLength); + + // Make sure the text inserted is visible. + textEditor.JumpTo(line + 1, 1); + + textEditor.Caret.Position = document.OffsetToPosition(offset + textInsertedLength); + } } - + /// /// Indents the lines and returns the total number of extra characters added. /// - static int IndentLines(TextArea textArea, int begin, int end, IFormattingStrategy formattingStrategy) + int IndentLines(int begin, int end, int initialIndent) { int totalInsertedCharacters = 0; - textArea.Document.UndoStack.StartUndoGroup(); for (int i = begin; i <= end; ++i) { - int existingCharacterCount = GetIndent(textArea, i); - int insertedCharacterCount = formattingStrategy.IndentLine(textArea, i) - existingCharacterCount; - totalInsertedCharacters += insertedCharacterCount; + if ((i == end) || (i == begin)) { + totalInsertedCharacters += IndentLine(i, initialIndent); + } else { + totalInsertedCharacters += IndentLine(i, initialIndent + 1); + } } - textArea.Document.UndoStack.EndUndoGroup(); - return totalInsertedCharacters; } + int IndentAllLinesTheSame(int begin, int end, int indent) + { + int totalInsertedCharacters = 0; + for (int i = begin; i <= end; ++i) { + totalInsertedCharacters += IndentLine(i, indent); + } + return totalInsertedCharacters; + } + /// /// Gets the current indentation for the specified line. /// - static int GetIndent(TextArea textArea, int line) + int GetIndent(int line) { - int indentCount = 0; - string lineText = TextUtilities.GetLineAsString(textArea.Document, line); + int whitespaceCharacterCount = 0; + string lineText = GetLineAsString(line); foreach (char ch in lineText) { if (Char.IsWhiteSpace(ch)) { - indentCount++; + whitespaceCharacterCount++; } else { break; } } - return indentCount; + if (textEditor.Options.ConvertTabsToSpaces) { + return (whitespaceCharacterCount / textEditor.Options.IndentationSize); + } + return whitespaceCharacterCount; + } + + string GetLineAsString(int line) + { + IDocumentLine documentLine = document.GetLine(line + 1); + return documentLine.Text; + } + + int IndentLine(int line, int howManyIndents) + { + IDocumentLine documentLine = document.GetLine(line + 1); + int offset = documentLine.Offset; + + string indentationString = GetIndentationString(howManyIndents); + document.Insert(offset, indentationString); + return indentationString.Length; + } + + string GetIndentationString(int howManyIndents) + { + string singleIndent = GetSingleIndentString(); + + StringBuilder indent = new StringBuilder(); + for (int i = 0; i < howManyIndents; ++i) { + indent.Append(singleIndent); + } + return indent.ToString(); + } + + string GetSingleIndentString() + { + if (textEditor.Options.ConvertTabsToSpaces) { + return new String(' ', textEditor.Options.IndentationSize); + } + return "\t"; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs new file mode 100644 index 0000000000..a6023d3028 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentWindow.cs @@ -0,0 +1,34 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public class WixDocumentWindow + { + IWorkbench workbench; + + public WixDocumentWindow(IWorkbench workbench) + { + this.workbench = workbench; + } + + public bool IsActive(WixDocument document) + { + if (document != null) { + IViewContent view = workbench.ActiveViewContent; + if (view != null) { + return FileUtility.IsEqualFileName(view.PrimaryFileName, document.FileName); + } + } + return false; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs index 6150e4e023..172094ffa8 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs @@ -17,7 +17,7 @@ using ICSharpCode.SharpDevelop; namespace ICSharpCode.WixBinding { - public class WixPackageFilesControl : System.Windows.Forms.UserControl, IWixPackageFilesView + public class WixPackageFilesControl : System.Windows.Forms.UserControl, IWixPackageFilesView, IWixPackageFilesControl { bool errorMessageTextBoxVisible; bool diffVisible; @@ -32,25 +32,19 @@ namespace ICSharpCode.WixBinding InitializeComponent(); diffControl.ContextMenuStrip = MenuService.CreateContextMenu(this, "/AddIns/WixBinding/WixPackageFilesDiffControl/ContextMenu"); } - - public delegate void DirtyChangedEventHandler(object source, EventArgs e); - + /// /// Raised when the files are changed and require saving. /// - public event DirtyChangedEventHandler DirtyChanged; + public event EventHandler DirtyChanged; /// /// Gets or sets the error message that will be displayed instead of the /// property grid. /// public string ErrorMessage { - get { - return errorMessageTextBox.Text; - } - set { - errorMessageTextBox.Text = value; - } + get { return errorMessageTextBox.Text; } + set { errorMessageTextBox.Text = value; } } /// @@ -58,9 +52,7 @@ namespace ICSharpCode.WixBinding /// error message text box replaces the property grid. /// public bool IsErrorMessageTextBoxVisible { - get { - return errorMessageTextBoxVisible; - } + get { return errorMessageTextBoxVisible; } set { errorMessageTextBoxVisible = value; if (value) { @@ -75,9 +67,7 @@ namespace ICSharpCode.WixBinding /// Shows or hides the diff panel. /// public bool IsDiffVisible { - get { - return diffVisible; - } + get { return diffVisible; } set { if (diffVisible != value) { diffVisible = value; @@ -94,9 +84,7 @@ namespace ICSharpCode.WixBinding /// Gets the project that is currently being displayed. /// public WixProject Project { - get { - return project; - } + get { return project; } } /// @@ -120,9 +108,7 @@ namespace ICSharpCode.WixBinding } public bool IsDirty { - get { - return dirty; - } + get { return dirty; } set { bool oldValue = dirty; dirty = value; @@ -149,9 +135,7 @@ namespace ICSharpCode.WixBinding } public XmlElement SelectedElement { - get { - return packageFilesTreeView.SelectedElement; - } + get { return packageFilesTreeView.SelectedElement; } set { packageFilesTreeView.SelectedElement = value; if (value == null) { @@ -164,9 +148,7 @@ namespace ICSharpCode.WixBinding /// Gets the attributes for the selected xml element. /// public WixXmlAttributeCollection Attributes { - get { - return wixXmlAttributes; - } + get { return wixXmlAttributes; } } /// @@ -179,9 +161,7 @@ namespace ICSharpCode.WixBinding } public StringCollection AllowedChildElements { - get { - return packageFilesTreeView.AllowedChildElements; - } + get { return packageFilesTreeView.AllowedChildElements; } } public void ShowNoRootDirectoryFoundMessage() @@ -297,9 +277,9 @@ namespace ICSharpCode.WixBinding /// Wix document and the files on the file system and displays /// the results. /// - public void ShowDiff() + public void CalculateDiff() { - editor.ShowDiff(); + editor.CalculateDiff(); } /// diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs index 6a2898c35c..27d7c901e4 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs @@ -46,18 +46,14 @@ namespace ICSharpCode.WixBinding /// initialized then all the child nodes have been added to this node. /// public bool IsInitialized { - get { - return isInitialized; - } + get { return isInitialized; } } /// /// Can delete all Wix tree nodes. /// public override bool EnableDelete { - get { - return true; - } + get { return true; } } public override void Delete() @@ -70,15 +66,11 @@ namespace ICSharpCode.WixBinding /// Gets the XmlElement associated with this tree node. /// public XmlElement XmlElement { - get { - return element; - } + get { return element; } } public WixPackageFilesTreeView WixPackageFilesTreeView { - get { - return (WixPackageFilesTreeView)TreeView; - } + get { return (WixPackageFilesTreeView)TreeView; } } /// diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs index 9e99d96d56..b063e5277b 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IFileLoader.cs @@ -21,6 +21,6 @@ namespace ICSharpCode.WixBinding /// /// if the file does not exist. /// - Bitmap GetBitmap(string fileName); + Bitmap LoadBitmap(string fileName); } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs similarity index 60% rename from src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs rename to src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs index 885f912276..e0bc64c21d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToDirectoryCommand.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IPackageFilesViewFactory.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -6,16 +6,12 @@ // using System; -using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.WixBinding { - public class AddFilesToDirectoryCommand : AbstractMenuCommand + public interface IPackageFilesViewFactory { - public override void Run() - { - PackageFilesView.ActiveView.AddFiles(); - } + PackageFilesView Create(WixProject project, IWorkbench workbench); } } - diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs new file mode 100644 index 0000000000..c50dbf47cf --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPackageFilesControl.cs @@ -0,0 +1,31 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.WixBinding +{ + public interface IWixPackageFilesControl : IDisposable + { + event EventHandler DirtyChanged; + bool IsDirty { get; set; } + + void Save(); + + void AddElement(string name); + void RemoveSelectedElement(); + + void AddFiles(); + void AddDirectory(); + void ShowFiles(WixProject project, ITextFileReader fileReader, IWixDocumentWriter documentWriter); + + void CalculateDiff(); + bool IsDiffVisible { get; set; } + + WixDocument Document { get; } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs new file mode 100644 index 0000000000..797d1e849d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IWixPropertyValueProvider.cs @@ -0,0 +1,23 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.WixBinding +{ + /// + /// Interface that allows a class to convert a Wix property name into a value. + /// + public interface IWixPropertyValueProvider + { + /// + /// Gets the property value for the specified name. Wix property names are + /// case sensitive. + /// + string GetValue(string name); + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs new file mode 100644 index 0000000000..0dfe9f4c2a --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/PackageFilesViewFactory.cs @@ -0,0 +1,24 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WixBinding +{ + public class PackageFilesViewFactory : IPackageFilesViewFactory + { + public PackageFilesViewFactory() + { + } + + public PackageFilesView Create(WixProject project, IWorkbench workbench) + { + return new PackageFilesView(project, workbench); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs index 0f3074359c..26a47c28ce 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Project/WixProject.cs @@ -68,7 +68,7 @@ namespace ICSharpCode.WixBinding { switch (StartAction) { case StartAction.Project: - return CreateStartInfo(InstallerFullPath); + return CreateStartInfo(GetInstallerFullPath()); default: return base.CreateStartInfo(); } @@ -111,49 +111,39 @@ namespace ICSharpCode.WixBinding /// Gets the full path to the installer file that will be generated by /// the Wix compiler and linker. /// - public string InstallerFullPath { - get { - string outputPath = GetEvaluatedProperty("OutputPath") ?? String.Empty; - string outputType = GetEvaluatedProperty("OutputType") ?? String.Empty; - string outputName = GetEvaluatedProperty("OutputName") ?? String.Empty; - string fileName = String.Concat(outputName, GetInstallerExtension(outputType)); - return Path.Combine(Path.Combine(Directory, outputPath), fileName); - } + public string GetInstallerFullPath() + { + string outputPath = GetEvaluatedProperty("OutputPath") ?? String.Empty; + string outputType = GetEvaluatedProperty("OutputType") ?? String.Empty; + string outputName = GetEvaluatedProperty("OutputName") ?? String.Empty; + string fileName = String.Concat(outputName, GetInstallerExtension(outputType)); + return Path.Combine(Directory, outputPath, fileName); } - + /// /// Adds a set of Wix libraries (.wixlib) to the project. /// - public void AddWixLibraries(string[] files) + public void AddWixLibraries(string[] fileNames) { - foreach (string fileName in files) { + foreach (string fileName in fileNames) { AddWixLibrary(fileName); } } - /// - /// Adds a Wix library (.wixlib) to the project. - /// public void AddWixLibrary(string fileName) { WixLibraryProjectItem projectItem = new WixLibraryProjectItem(this); projectItem.FileName = fileName; ProjectService.AddProjectItem(this, projectItem); } - - /// - /// Adds a set of Wix extensions to the project. - /// - public void AddWixExtensions(string[] files) + + public void AddWixExtensions(string[] fileNames) { - foreach (string fileName in files) { + foreach (string fileName in fileNames) { AddWixExtension(fileName); } } - /// - /// Adds a Wix extension to the project. - /// public void AddWixExtension(string fileName) { WixExtensionProjectItem projectItem = new WixExtensionProjectItem(this); @@ -166,14 +156,14 @@ namespace ICSharpCode.WixBinding /// their filename. /// public ReadOnlyCollection WixFiles { - get { return GetMatchingFiles(WixDocument.IsWixFileName); } + get { return GetMatchingFiles(WixFileName.IsWixFileName); } } /// /// Returns the file project items that are Wix source files (.wxs). /// public ReadOnlyCollection WixSourceFiles { - get { return GetMatchingFiles(WixDocument.IsWixSourceFileName); } + get { return GetMatchingFiles(WixFileName.IsWixSourceFileName); } } /// @@ -189,9 +179,7 @@ namespace ICSharpCode.WixBinding /// /// TODO: This can be configuration specific. /// - /// The preprocessor variable name. - /// An empty string if the name cannot be found. - public string GetVariable(string name) + public string GetPreprocessorVariableValue(string name) { string constants = GetEvaluatedProperty("DefineConstants") ?? String.Empty; NameValuePairCollection nameValuePairs = new NameValuePairCollection(constants); @@ -201,7 +189,7 @@ namespace ICSharpCode.WixBinding /// /// Gets the MSBuild Property value for the given name. /// - public string GetValue(string name) + string IWixPropertyValueProvider.GetValue(string name) { string propertyValue; if (MSBuildEngine.MSBuildProperties.TryGetValue(name, out propertyValue)) { @@ -220,10 +208,10 @@ namespace ICSharpCode.WixBinding /// in MSBuildBasedProject is called. public override ItemType GetDefaultItemType(string fileName) { - if (WixDocument.IsWixFileName(fileName)) + if (WixFileName.IsWixFileName(fileName)) { return ItemType.Compile; - else - return base.GetDefaultItemType(fileName); + } + return base.GetDefaultItemType(fileName); } /// diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs index 9d44bc4acb..3df1f438ef 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaries.cs @@ -100,7 +100,7 @@ namespace ICSharpCode.WixBinding document.FileName = fileName; foreach (WixBinaryElement element in document.GetBinaries()) { if (!binaries.ContainsKey(element.Id)) { - binaries.Add(element.Id, element.FileName); + binaries.Add(element.Id, element.GetFileName()); } } } catch (FileNotFoundException) { diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs index 63648c387d..b73018aeb8 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixBinaryElement.cs @@ -11,24 +11,15 @@ using System.Xml; namespace ICSharpCode.WixBinding { - public class WixBinaryElement : XmlElement + public class WixBinaryElement : WixElementBase { public const string BinaryElementName = "Binary"; public WixBinaryElement(WixDocument document) - : base(document.WixNamespacePrefix, BinaryElementName, WixNamespaceManager.Namespace, document) + : base(BinaryElementName, document) { } - public string Id { - get { - return GetAttribute("Id"); - } - set { - SetAttribute("Id", value); - } - } - public string Source { get { if (HasAttribute("SourceFile")) { @@ -44,18 +35,19 @@ namespace ICSharpCode.WixBinding /// /// The full path is generated by using the WixDocument's filename. /// - public string FileName { - get { - WixDocument document = (WixDocument)OwnerDocument; - string binaryFileName = WixPropertyParser.Parse(Source, document); - - // If we have the Wix document filename return the full filename. - string documentFileName = document.FileName; - if (documentFileName.Length > 0) { - return Path.Combine(Path.GetDirectoryName(documentFileName), binaryFileName); - } - return binaryFileName; + public string GetFileName() + { + string relativeFileName = WixPropertyParser.Parse(Source, OwnerWixDocument); + return GetFullPath(relativeFileName); + } + + string GetFullPath(string relativeFileName) + { + string documentFileName = OwnerWixDocument.FileName; + if (!String.IsNullOrEmpty(documentFileName)) { + return Path.Combine(Path.GetDirectoryName(documentFileName), relativeFileName); } + return relativeFileName; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs index e18511e9aa..6554313e45 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs @@ -12,12 +12,12 @@ using System.Xml; namespace ICSharpCode.WixBinding { - public class WixComponentElement : XmlElement + public class WixComponentElement : WixElementBase { public const string ComponentElementName = "Component"; public WixComponentElement(WixDocument document) - : base(document.WixNamespacePrefix, ComponentElementName, WixNamespaceManager.Namespace, document) + : base(ComponentElementName, document) { } @@ -26,76 +26,59 @@ namespace ICSharpCode.WixBinding set { SetAttribute("Guid", value); } } - public string Id { - get { return GetAttribute("Id"); } - set { SetAttribute("Id", value); } - } - public string DiskId { get { return GetAttribute("DiskId"); } set { SetAttribute("DiskId", value); } } - /// - /// Checks whether the disk id has already been set for this component. - /// public bool HasDiskId { get { return HasAttribute("DiskId"); } } - /// - /// Generates a new guid for this component element. - /// public void GenerateNewGuid() { Guid = System.Guid.NewGuid().ToString().ToUpperInvariant(); } + public WixFileElement[] GetFiles() + { + List files = new List(); + foreach (XmlNode childNode in ChildNodes) { + WixFileElement childElement = childNode as WixFileElement; + if (childElement != null) { + files.Add(childElement); + } + } + return files.ToArray(); + } + /// /// Creates a new file element with the specified filename. /// public WixFileElement AddFile(string fileName) { WixFileElement fileElement = new WixFileElement(this, fileName); - return (WixFileElement)AppendChild(fileElement); + AppendChild(fileElement); + return fileElement; } - /// - /// Creates an id from the filename. - /// /// /// Takes the filename, removes all periods, and /// capitalises the first character and first extension character. /// - /// The Wix document is used to make sure the - /// id generated is unique for that document. - /// The full filename including the directory to - /// use when generating the id. - public static string GenerateIdFromFileName(WixDocument document, string fileName) + public void GenerateUniqueIdFromFileName(string fileName) { - string id = GenerateIdFromFileName(fileName); - if (!document.ComponentIdExists(id)) { - return id; + Id = GenerateIdFromFileName(fileName); + if (!OwnerWixDocument.ComponentIdExists(Id)) { + return; } - // Add the parent folder to the id. - string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName)); - parentDirectory = FirstCharacterToUpperInvariant(parentDirectory); - parentDirectory = WixFileElement.GenerateId(parentDirectory).Replace(".", String.Empty); - id = String.Concat(parentDirectory, id); - if (!document.ComponentIdExists(id)) { - return id; + Id = GenerateIdFromParentDirectoryAndFileName(fileName, Id); + if (!OwnerWixDocument.ComponentIdExists(Id)) { + return; } - // Add a number to the end until we generate a unique id. - int count = 0; - string baseId = id; - do { - ++count; - id = String.Concat(baseId, count); - } while (document.ComponentIdExists(id)); - - return id; + Id = GenerateUniqueIdByAppendingNumberToEnd(Id); } /// @@ -105,44 +88,77 @@ namespace ICSharpCode.WixBinding /// Takes the filename, removes all periods, and /// capitalises the first character and first extension character. /// - public static string GenerateIdFromFileName(string fileName) + public string GenerateIdFromFileName(string fileName) + { + string fileNameWithoutExtension = UpperCaseFirstCharacterOfFileNameWithoutExtension(fileName); + fileNameWithoutExtension = RemoveDotCharacters(fileNameWithoutExtension); + + string extension = GetFileExtensionWithoutDotCharacter(fileName); + extension = UpperCaseFirstCharacter(extension); + + string modifiedFileName = String.Concat(fileNameWithoutExtension, extension); + return WixFileElement.GenerateId(modifiedFileName); + } + + string UpperCaseFirstCharacterOfFileNameWithoutExtension(string fileName) { string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName); - string idStart = String.Empty; if (fileNameNoExtension.Length > 0) { - idStart = FirstCharacterToUpperInvariant(fileNameNoExtension).Replace(".", String.Empty); + return UpperCaseFirstCharacter(fileNameNoExtension); } - - // Remove period from extension and uppercase first extension char. + return String.Empty; + } + + string GetFileExtensionWithoutDotCharacter(string fileName) + { string extension = Path.GetExtension(fileName); - string idEnd = String.Empty; - if (extension.Length > 1) { - idEnd = FirstCharacterToUpperInvariant(extension.Substring(1)); + if (!String.IsNullOrEmpty(extension)) { + return extension.Substring(1); } - return WixFileElement.GenerateId(String.Concat(idStart, idEnd)); + return String.Empty; } - /// - /// Gets any child file elements. - /// - public WixFileElement[] GetFiles() + string UpperCaseFirstCharacter(string s) { - List files = new List(); - foreach (XmlNode childNode in ChildNodes) { - WixFileElement childElement = childNode as WixFileElement; - if (childElement != null) { - files.Add(childElement); - } + if (!String.IsNullOrEmpty(s)) { + string firstCharacter = s.Substring(0, 1); + string restOfString = s.Substring(1); + return String.Concat(firstCharacter.ToUpperInvariant(), restOfString); } - return files.ToArray(); + return String.Empty; } - /// - /// Upper cases first character of string. - /// - static string FirstCharacterToUpperInvariant(string s) + string GenerateIdFromParentDirectoryAndFileName(string fileName, string idGeneratedFromFileName) { - return String.Concat(s.Substring(0, 1).ToUpperInvariant(), s.Substring(1)); + string id = GenerateIdFromParentDirectory(fileName); + return String.Concat(id, idGeneratedFromFileName); + } + + string GenerateIdFromParentDirectory(string fileName) + { + string fullParentDirectory = Path.GetDirectoryName(fileName); + string lastFolder = WixDirectoryElement.GetLastFolderInDirectoryName(fullParentDirectory); + string id = UpperCaseFirstCharacter(lastFolder); + id = WixFileElement.GenerateId(id); + id = RemoveDotCharacters(id); + return id; + } + + string RemoveDotCharacters(string text) + { + return text.Replace(".", String.Empty); + } + + string GenerateUniqueIdByAppendingNumberToEnd(string id) + { + int count = 0; + string baseId = id; + do { + ++count; + id = String.Concat(baseId, count); + } while (OwnerWixDocument.ComponentIdExists(id)); + + return id; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs index 9d2e64bae7..9884b2c2dd 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialog.cs @@ -52,8 +52,8 @@ namespace ICSharpCode.WixBinding /// /// The dialog XML element loaded from /// the Wix document - public WixDialog(WixDocument document, XmlElement dialogElement) : - this(document, dialogElement, null) + public WixDialog(WixDocument document, XmlElement dialogElement) + : this(document, dialogElement, null) { } @@ -1141,9 +1141,9 @@ namespace ICSharpCode.WixBinding { if (binaries != null) { string fileName = binaries.GetBinaryFileName(id); - return document.GetBitmapFromFileName(fileName); + return document.LoadBitmapWithFileName(fileName); } - return document.GetBitmapFromId(id); + return document.LoadBitmapWithId(id); } static string XmlEncode(string item) diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs new file mode 100644 index 0000000000..752cdb08fb --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDialogElement.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Xml; + +namespace ICSharpCode.WixBinding +{ + public class WixDialogElement : WixElementBase + { + public const string DialogElementName = "Dialog"; + + public WixDialogElement(WixDocument document) + : base(DialogElementName, document) + { + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs index b039f6f1cb..63775d60d7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs @@ -24,18 +24,10 @@ namespace ICSharpCode.WixBinding { } - /// - /// Determines whether the specified element name refers to a Directory element. - /// - public static bool IsDirectoryElement(string name) - { - return name == DirectoryElementName; - } - /// /// Returns the last directory specified in the path /// - public static string GetLastDirectoryName(string path) + public static string GetLastFolderInDirectoryName(string path) { int index = path.LastIndexOf(Path.DirectorySeparatorChar); return path.Substring(index + 1); @@ -55,12 +47,13 @@ namespace ICSharpCode.WixBinding /// /// Adds a new component element to this directory element. /// - public WixComponentElement AddComponent(string id) + public WixComponentElement AddComponent(string fileName) { WixComponentElement componentElement = new WixComponentElement((WixDocument)OwnerDocument); + componentElement.GenerateUniqueIdFromFileName(fileName); componentElement.GenerateNewGuid(); - componentElement.Id = id; - return (WixComponentElement)AppendChild(componentElement); + AppendChild(componentElement); + return componentElement; } public string SourceName { diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs index 2fc70357f3..a10e7e3f1d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs @@ -17,18 +17,13 @@ namespace ICSharpCode.WixBinding /// Common base class for the WixDirectoryElement and WixDirectoryRefElement /// classes. /// - public abstract class WixDirectoryElementBase : XmlElement + public abstract class WixDirectoryElementBase : WixElementBase { public WixDirectoryElementBase(string localName, WixDocument document) - : base(document.WixNamespacePrefix, localName, WixNamespaceManager.Namespace, document) + : base(localName, document) { } - public string Id { - get { return GetAttribute("Id"); } - set { SetAttribute("Id", value); } - } - /// /// Gets any child directory elements. /// @@ -38,9 +33,7 @@ namespace ICSharpCode.WixBinding foreach (XmlNode childNode in ChildNodes) { WixDirectoryElement childElement = childNode as WixDirectoryElement; if (childElement != null) { - if (WixDirectoryElement.IsDirectoryElement(childElement.LocalName)) { - directories.Add(childElement); - } + directories.Add(childElement); } } return directories.ToArray(); @@ -70,7 +63,8 @@ namespace ICSharpCode.WixBinding WixDirectoryElement directoryElement = new WixDirectoryElement((WixDocument)OwnerDocument); directoryElement.Id = WixFileElement.GenerateId(name); directoryElement.DirectoryName = name; - return (WixDirectoryElement)AppendChild(directoryElement); - } + AppendChild(directoryElement); + return directoryElement; + } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs index 0cfff9e7f3..7aeb4a4803 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs @@ -16,7 +16,7 @@ using System.Xml; using ICSharpCode.Core; using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.TextEditor.Document; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.XmlEditor; namespace ICSharpCode.WixBinding @@ -25,64 +25,19 @@ namespace ICSharpCode.WixBinding /// A Wix document (.wxs or .wxi). /// public class WixDocument : XmlDocument, IWixPropertyValueProvider - { - public const string WixSourceFileExtension = ".wxs"; - public const string WixIncludeFileExtension = ".wxi"; - - /// - /// Class used to store the line number and dialog id of the - /// dialog element start tag. - /// - class DialogStartElement - { - int line = -1; - string id = String.Empty; - - public DialogStartElement(int line, string id) - { - this.id = id; - this.line = line; - } - - public int Line { - get { - return line; - } - } - - public string Id { - get { - return id; - } - } - } - - /// - /// Default IFileLoader implementation which tries to load - /// the bitmap from the specified filename. If the file does - /// not exist the bitmap is not loaded. - /// - class FileLoader : IFileLoader - { - public Bitmap GetBitmap(string fileName) - { - if (File.Exists(fileName)) { - return new Bitmap(fileName); - } - return null; - } - } - + { WixNamespaceManager namespaceManager; IFileLoader fileLoader; WixProject project; string fileName = String.Empty; - public WixDocument() : this((WixProject)null) + public WixDocument() + : this((WixProject)null) { } - public WixDocument(WixProject project) : this(project, new FileLoader()) + public WixDocument(WixProject project) + : this(project, new DefaultFileLoader()) { } @@ -94,411 +49,82 @@ namespace ICSharpCode.WixBinding { this.project = project; this.fileLoader = fileLoader; + if (fileLoader == null) { - throw new ArgumentException("Cannot be null.", "fileLoader"); + throw new ArgumentNullException("fileLoader"); } + namespaceManager = new WixNamespaceManager(NameTable); } - /// - /// Gets the project that this document belongs to. - /// public WixProject Project { - get { - return project; - } + get { return project; } } - /// - /// Gets or sets the filename for the Wix Document. - /// public string FileName { - get { - return fileName; - } - set { - fileName = value; - } + get { return fileName; } + set { fileName = value; } } /// - /// Gets the dialogs from a Wix file. - /// - public static ReadOnlyCollection GetDialogIds(string fileName) - { - using (XmlTextReader reader = new XmlTextReader(new FileStream(fileName, FileMode.Open, FileAccess.Read))) { - return GetDialogIds(reader); - } - } - - /// - /// Gets the dialogs from a Wix file. - /// - public static ReadOnlyCollection GetDialogIds(TextReader reader) - { - XmlTextReader xmlReader = new XmlTextReader(reader); - return GetDialogIds(xmlReader); - } - - /// - /// Gets the dialog Ids in a Wix file. - /// - public static ReadOnlyCollection GetDialogIds(XmlTextReader reader) - { - using (reader) { - List dialogIds = new List(); - object dialogElementName = reader.NameTable.Add("Dialog"); - while (reader.Read()) { - switch (reader.NodeType) { - case XmlNodeType.Element: - if (IsElementMatch(dialogElementName, reader.LocalName)) { - AddDialogId(reader, dialogIds); - } - break; - } - } - return new ReadOnlyCollection(dialogIds); - } - } - - /// - /// Gets the line and column where the specified element starts. The column - /// returned is the column containing the opening tag (<). - /// - /// The element name. - /// The id attribute value. - public static Location GetStartElementLocation(TextReader reader, string name, string id) - { - XmlTextReader xmlReader = new XmlTextReader(reader); - return GetStartElementLocation(xmlReader, name, id); - } - - /// - /// Gets the line and column where the specified element starts. The column - /// returned is the column containing the opening tag (<). - /// - /// The element name. - /// The id attribute value. - public static Location GetStartElementLocation(XmlTextReader reader, string name, string id) - { - using (reader) { - object elementName = reader.NameTable.Add(name); - while (reader.Read()) { - switch (reader.NodeType) { - case XmlNodeType.Element: - if (IsElementMatch(elementName, reader.LocalName)) { - Location location = GetStartElementLocationIfMatch(reader, id); - if (!location.IsEmpty) { - return location; - } - } - break; - } - } - } - return Location.Empty; - } - - /// - /// Gets the line and column where the specified element ends. The column - /// returned is the column containing the opening tag (<) of the end element. - /// - /// The element name. - /// The id attribute value. - public static Location GetEndElementLocation(TextReader reader, string name, string id) - { - XmlTextReader xmlReader = new XmlTextReader(reader); - return GetEndElementLocation(xmlReader, name, id); - } - - /// - /// Gets the line and column where the specified element ends. The column - /// returned is the column containing the opening tag (<) of the end element. - /// - /// The element name. - /// The id attribute value. - public static Location GetEndElementLocation(XmlTextReader reader, string name, string id) - { - using (reader) { - bool startElementFound = false; - object elementName = reader.NameTable.Add(name); - while (reader.Read()) { - switch (reader.NodeType) { - case XmlNodeType.Element: - if (IsElementMatch(elementName, reader.LocalName)) { - Location location = GetStartElementLocationIfMatch(reader, id); - startElementFound = !location.IsEmpty; - } - break; - case XmlNodeType.EndElement: - if (startElementFound) { - if (IsElementMatch(elementName, reader.LocalName)) { - // Take off an extra 2 from the line position so we get the - // correct column for the < tag rather than the element name. - return new Location(reader.LinePosition - 3, reader.LineNumber - 1); - } - } - break; - } - } - } - return Location.Empty; - } - - /// - /// Gets the dialog id at the specified line. - /// - /// Line numbers start from zero. - /// The dialog id found at the specified line; - /// if no dialog found. - public static string GetDialogId(TextReader reader, int line) - { - XmlTextReader xmlReader = new XmlTextReader(reader); - return GetDialogId(xmlReader, line); - } - - /// - /// Gets the dialog id at the specified line. + /// Gets a WixDialog object for the specified dialog id. /// - /// Line numbers start from zero. - /// The dialog id found at the specified line; - /// if no dialog found. - public static string GetDialogId(XmlTextReader reader, int line) + public WixDialog CreateWixDialog(string id, ITextFileReader reader) { - // Add one to line since XmlTextReader line numbers start from one. - ++line; - - DialogStartElement dialogStartElement = null; - - using (reader) { - object dialogElementName = reader.NameTable.Add("Dialog"); - while (reader.Read()) { - switch (reader.NodeType) { - case XmlNodeType.Element: - if (IsElementMatch(dialogElementName, reader.LocalName)) { - if (line < reader.LineNumber) { - return null; - } else if (line == reader.LineNumber) { - return GetIdFromCurrentNode(reader); - } else if (reader.IsStartElement()) { - dialogStartElement = new DialogStartElement(reader.LineNumber, GetIdFromCurrentNode(reader)); - } - } - break; - case XmlNodeType.EndElement: - if (IsElementMatch(dialogElementName, reader.LocalName)) { - if (line > dialogStartElement.Line && line <= reader.LineNumber) { - return dialogStartElement.Id; - } - } - break; - } - } + XmlElement dialogElement = GetDialogElement(id); + if (dialogElement != null) { + return new WixDialog(this, dialogElement, new WixBinaries(this, reader)); } return null; } - - /// - /// Checks the file extension to see if the file is a Wix file. The file - /// can either be a Wix source file (.wxs) or a Wix include file (.wxi). - /// - public static bool IsWixFileName(string fileName) - { - if (fileName == null) { - return false; - } - string extension = Path.GetExtension(fileName.ToLowerInvariant()); - switch (extension) { - case WixSourceFileExtension: - return true; - case WixIncludeFileExtension: - return true; - } - return false; - } - - /// - /// Checks whether the file extension is for a Wix source file (.wxs). - /// - public static bool IsWixSourceFileName(string fileName) - { - return String.Compare(Path.GetExtension(fileName), WixSourceFileExtension, true) == 0; - } - /// - /// Converts a DomRegion to an ISegment for the given document. - /// - public static ISegment ConvertRegionToSegment(IDocument document, DomRegion region) + XmlElement GetDialogElement(string id) { - // Single line region - if (region.BeginLine == region.EndLine) { - ICSharpCode.TextEditor.Document.LineSegment documentSegment = document.GetLineSegment(region.BeginLine); - return new WixDocumentLineSegment(documentSegment.Offset + region.BeginColumn, - region.EndColumn + 1 - region.BeginColumn); - } - - // Multiple line region. - int length = 0; - int startOffset = 0; - for (int line = region.BeginLine; line <= region.EndLine; ++line) { - ICSharpCode.TextEditor.Document.LineSegment currentSegment = document.GetLineSegment(line); - if (line == region.BeginLine) { - length += currentSegment.TotalLength - region.BeginColumn; - startOffset = currentSegment.Offset + region.BeginColumn; - } else if (line < region.EndLine) { - length += currentSegment.TotalLength; - } else { - length += region.EndColumn + 1; - } - } - return new WixDocumentLineSegment(startOffset, length); + string xpath = GetXPath("//w:Dialog[@Id='{0}']", id); + return (XmlElement)SelectSingleElement(xpath); } - /// - /// Creates an XML fragment string for the specified element. - /// - /// The line terminator. - /// Indicates whether tabs will be converted to spaces. - /// The indent to be used when converting tabs to spaces. - /// An XML fragment string without any Wix namespace attributes. - public static string GetXml(XmlElement element, string lineTerminator, bool tabsToSpaces, int tabIndent) + string GetXPath(string xpathFormat, string arg) { - StringBuilder xml = new StringBuilder(); - StringWriter stringWriter = new StringWriter(xml); - XmlWriterSettings xmlWriterSettings = CreateXmlWriterSettings(lineTerminator, tabsToSpaces, tabIndent); - using (XmlWriter xmlWriter = XmlTextWriter.Create(stringWriter, xmlWriterSettings)) { - element.WriteTo(xmlWriter); - } - return xml.ToString().Replace(String.Concat(" xmlns=\"", WixNamespaceManager.Namespace, "\""), String.Empty);; + return String.Format(xpathFormat, XmlEncode(arg)); } - /// - /// Gets the region (start line, column to end line, column) of the xml - /// element that has the specified id. This includes the start and end tags, the start column is the column - /// containing the start tag and the end column is the column containing the final - /// end tag marker. - /// - /// The name of the element. - /// The id attribute value of the element. - public static DomRegion GetElementRegion(TextReader reader, string name, string id) + string GetXPath(string xpathFormat, string arg1, string arg2) { - XmlTextReader xmlTextReader = new XmlTextReader(reader); - return GetElementRegion(xmlTextReader, name, id); + return String.Format(xpathFormat, XmlEncode(arg1), XmlEncode(arg2)); } - /// - /// Gets the region (start line, column to end line, column) of the xml - /// element that has the specified id. This includes the start and end tags, the start column is the column - /// containing the start tag and the end column is the column containing the final - /// end tag marker. - /// - /// The name of the element. - /// The id attribute value of the element. - public static DomRegion GetElementRegion(XmlTextReader reader, string name, string id) + string XmlEncode(string item) { - Location startLocation = Location.Empty; - - using (reader) { - int nestedElementsCount = -1; - object elementName = reader.NameTable.Add(name); - while (reader.Read()) { - switch (reader.NodeType) { - case XmlNodeType.Element: - if (IsElementMatch(elementName, reader.LocalName)) { - if (nestedElementsCount == -1) { - bool isEmptyElement = reader.IsEmptyElement; - startLocation = GetStartElementLocationIfMatch(reader, id); - if (!startLocation.IsEmpty) { - nestedElementsCount = 0; - if (isEmptyElement) { - Location endLocation = GetEmptyElementEnd(reader); - return DomRegion.FromLocation(startLocation, endLocation); - } - } - } else if (!reader.IsEmptyElement) { - ++nestedElementsCount; - } - } - break; - case XmlNodeType.EndElement: - if (!startLocation.IsEmpty && IsElementMatch(elementName, reader.LocalName)) { - if (nestedElementsCount == 0) { - Location endLocation = GetEndElementEnd(reader); - return DomRegion.FromLocation(startLocation, endLocation); - } - --nestedElementsCount; - } - break; - } - } - } - return DomRegion.Empty; + char quoteChar = '\''; + return XmlEncoder.Encode(item, quoteChar); } - /// - /// Gets a WixDialog object for the specified dialog id. - /// - /// The id of the dialog. - /// A for the dialog id - /// found; otherwise if no dialog - /// with the specified id can be found. - public WixDialog GetDialog(string id) + XmlElement SelectSingleElement(string xpath) { - XmlElement dialogElement = GetDialogElement(id); - if (dialogElement != null) { - return new WixDialog(this, dialogElement); - } - return null; + return (XmlElement)SelectSingleNode(xpath, namespaceManager); } - /// - /// Gets a WixDialog object for the specified dialog id. - /// - /// The id of the dialog. - /// The text file reader to use when looking up - /// binary filenames. - /// A for the dialog id - /// found; otherwise if no dialog - /// with the specified id can be found. - public WixDialog GetDialog(string id, ITextFileReader reader) + public Bitmap LoadBitmapWithId(string id) { - XmlElement dialogElement = GetDialogElement(id); - if (dialogElement != null) { - return new WixDialog(this, dialogElement, new WixBinaries(this, reader)); - } - return null; + string bitmapFileName = GetBinaryFileName(id); + return LoadBitmapWithFileName(bitmapFileName); } - /// - /// Gets the binary filename for the specified id. - /// - /// if the id cannot be found. public string GetBinaryFileName(string id) { - string xpath = String.Concat("//w:Binary[@Id='", XmlEncode(id), "']"); - WixBinaryElement binaryElement = (WixBinaryElement)SelectSingleNode(xpath, namespaceManager); + string xpath = GetXPath("//w:Binary[@Id='{0}']", id); + WixBinaryElement binaryElement = (WixBinaryElement)SelectSingleElement(xpath); if (binaryElement != null) { - return binaryElement.FileName; + return binaryElement.GetFileName(); } return null; } - /// - /// Loads the bitmap using the Wix Bitmap id. - /// - public Bitmap GetBitmapFromId(string id) - { - string bitmapFileName = GetBinaryFileName(id); - return GetBitmapFromFileName(bitmapFileName); - } - - /// - /// Loads the bitmap. - /// - public Bitmap GetBitmapFromFileName(string fileName) + public Bitmap LoadBitmapWithFileName(string fileName) { if (fileName != null) { - return fileLoader.GetBitmap(fileName); + return fileLoader.LoadBitmap(fileName); } return null; } @@ -506,24 +132,20 @@ namespace ICSharpCode.WixBinding /// /// Gets a property value defined in the Wix document. /// - /// The property value if it is found; an empty string otherwise. public string GetProperty(string name) { - string xpath = String.Concat("//w:Property[@Id='", XmlEncode(name), "']"); - XmlElement textStyleElement = (XmlElement)SelectSingleNode(xpath, namespaceManager); + string xpath = GetXPath("//w:Property[@Id='{0}']", name); + XmlElement textStyleElement = SelectSingleElement(xpath); if (textStyleElement != null) { return textStyleElement.InnerText; } return String.Empty; } - /// - /// Gets the preprocessor variable value from the WixProject. - /// - public string GetValue(string name) + string IWixPropertyValueProvider.GetValue(string name) { if (project != null) { - return project.GetVariable(name); + return project.GetPreprocessorVariableValue(name); } return null; } @@ -531,100 +153,59 @@ namespace ICSharpCode.WixBinding /// /// Gets the top SOURCEDIR directory. /// - public WixDirectoryElement RootDirectory { - get { - string xpath = String.Concat("//w:Product/w:Directory[@Id='", WixDirectoryElement.RootDirectoryId, "']"); - return (WixDirectoryElement)SelectSingleNode(xpath, namespaceManager); - } + public WixDirectoryElement GetRootDirectory() + { + string xpath = GetXPath("//w:Product/w:Directory[@Id='{0}']", WixDirectoryElement.RootDirectoryId); + return (WixDirectoryElement)SelectSingleElement(xpath); } /// /// Gets a reference to the root directory. /// - public WixDirectoryRefElement RootDirectoryRef { - get { - string xpath = String.Concat("//w:DirectoryRef[@Id='", WixDirectoryElement.RootDirectoryId, "']"); - return (WixDirectoryRefElement)SelectSingleNode(xpath, namespaceManager); - } + public WixDirectoryRefElement GetRootDirectoryRef() + { + string xpath = GetXPath("//w:DirectoryRef[@Id='{0}']", WixDirectoryElement.RootDirectoryId); + return (WixDirectoryRefElement)SelectSingleElement(xpath); } - /// - /// The Wix document contains the Product element. - /// - public bool IsProductDocument { - get { - return Product != null; - } + public bool HasProduct { + get { return GetProduct() != null; } } - /// - /// Gets the prefix used for the Wix namespace. - /// - public string WixNamespacePrefix { - get { - XmlElement documentElement = DocumentElement; - if (documentElement != null) { - return documentElement.GetPrefixOfNamespace(WixNamespaceManager.Namespace); - } - return String.Empty; + public string GetWixNamespacePrefix() + { + XmlElement documentElement = DocumentElement; + if (documentElement != null) { + return documentElement.GetPrefixOfNamespace(WixNamespaceManager.Namespace); } + return String.Empty; } - /// - /// Adds a new root directory. - /// public WixDirectoryElement AddRootDirectory() { - // Add product element if it does not exist. - XmlElement productElement = Product; + XmlElement productElement = GetProduct(); if (productElement == null) { - productElement = CreateWixElement("Product"); - DocumentElement.AppendChild(productElement); + productElement = AddProduct(); } - - // Add root directory. - WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this); - return (WixDirectoryElement)productElement.AppendChild(rootDirectory); + return AddRootDirectoryToProduct(productElement); } - /// - /// Creates a new Xml element belonging to the Wix namespace. - /// - public XmlElement CreateWixElement(string name) + XmlElement AddProduct() { - return CreateElement(WixNamespacePrefix, name, WixNamespaceManager.Namespace); + XmlElement productElement = CreateWixElement("Product"); + DocumentElement.AppendChild(productElement); + return productElement; } - /// - /// Saves the document to the location specified by WixDocument.FileName. - /// - public void Save(string lineTerminator, bool tabsToSpaces, int tabIndent) + WixDirectoryElement AddRootDirectoryToProduct(XmlElement parentProductElement) { - XmlWriterSettings xmlWriterSettings = CreateXmlWriterSettings(lineTerminator, tabsToSpaces, tabIndent); - using (XmlWriter xmlWriter = XmlTextWriter.Create(fileName, xmlWriterSettings)) { - Save(xmlWriter); - } - } - - /// - /// Gets the Product element. - /// - public XmlElement Product { - get { - return (XmlElement)SelectSingleNode("w:Wix/w:Product", namespaceManager); - } + WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this); + return (WixDirectoryElement)parentProductElement.AppendChild(rootDirectory); } - /// - /// Gets the binary elements defined in this document. - /// - public WixBinaryElement[] GetBinaries() + public XmlElement CreateWixElement(string name) { - List binaries = new List(); - foreach (WixBinaryElement element in SelectNodes("//w:Binary", namespaceManager)) { - binaries.Add(element); - } - return binaries.ToArray(); + return CreateElement(GetWixNamespacePrefix(), name, WixNamespaceManager.Namespace); } /// @@ -644,6 +225,8 @@ namespace ICSharpCode.WixBinding return new WixDirectoryRefElement(this); case WixBinaryElement.BinaryElementName: return new WixBinaryElement(this); + case WixDialogElement.DialogElementName: + return new WixDialogElement(this); } } return base.CreateElement(prefix, localName, namespaceURI); @@ -658,6 +241,13 @@ namespace ICSharpCode.WixBinding return ElementIdExists(WixFileElement.FileElementName, id); } + bool ElementIdExists(string elementName, string id) + { + string xpath = GetXPath("//w:{0}[@Id='{1}']", elementName, id); + XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable)); + return nodes.Count > 0; + } + /// /// Checks to see if a Component element exists with the specified id in this /// document. @@ -673,7 +263,7 @@ namespace ICSharpCode.WixBinding /// public string GetFullPath(string relativePath) { - if (fileName != null && fileName.Length > 0) { + if (!String.IsNullOrEmpty(fileName)) { string basePath = Path.GetDirectoryName(fileName); return FileUtility.GetAbsolutePath(basePath, relativePath); } @@ -686,149 +276,25 @@ namespace ICSharpCode.WixBinding /// public string GetRelativePath(string fullPath) { - if (fileName != null && fileName.Length > 0) { + if (!String.IsNullOrEmpty(fileName)) { string basePath = Path.GetDirectoryName(fileName); return FileUtility.GetRelativePath(basePath, fullPath); } return fullPath; } - /// - /// Reads the dialog id and adds it to the list of dialogs found so far. - /// - /// An XmlReader which is currently at the dialog start element. - static void AddDialogId(XmlReader reader, List dialogIds) + public XmlElement GetProduct() { - string id = GetIdFromCurrentNode(reader); - if (id.Length > 0) { - dialogIds.Add(id); - } + return SelectSingleElement("w:Wix/w:Product"); } - /// - /// Gets the id for the current element. - /// - /// An XmlReader which is currently at the start element. - static string GetIdFromCurrentNode(XmlReader reader) - { - if (reader.MoveToAttribute("Id")) { - if (reader.Value != null) { - return reader.Value; - } - } - return String.Empty; - } - - /// - /// Checks that the atomised element names match. - /// - static bool IsElementMatch(object elementName, object currentElementName) - { - return elementName == currentElementName; - } - - /// - /// Gets the line and column position if the dialog id matches the dialog - /// element at the current reader position. This returns the column for the - /// starting less than start tag. - /// - /// A dialog id. - /// An XmlTextReader currently at the dialog start element. - /// if the dialog id does not match. - static Location GetStartElementLocationIfMatch(XmlTextReader reader, string id) - { - // Store the column and line position since the call to GetDialogId will - // move to the Id attribute. - int line = reader.LineNumber - 1; - int column = reader.LinePosition - 2; // Take off 2 to so the '<' is located. - - if (id == GetIdFromCurrentNode(reader)) { - return new Location(column, line); - } - return Location.Empty; - } - - /// - /// Determines the end of the end element including the final end tag marker - /// (the greater than sign). This method moves the XmlTextReader to the end of - /// the end tag. - /// - static Location GetEndElementEnd(XmlTextReader reader) - { - reader.ReadEndElement(); - int line = reader.LineNumber - 1; - - // Take off two as we have moved passed the end tag column. - int column = reader.LinePosition - 2; - - // If ReadEndElement has moved to the start of another element - // take off one from the column value otherwise the column - // value includes the start tag of the next element. - if (reader.NodeType == XmlNodeType.Element) { - --column; - } - return new Location(column, line); - } - - /// - /// Determines the end of the empty element including the final end tag marker - /// (the greater than sign). This method moves the XmlTextReader to the end - /// of the element tag. - /// - static Location GetEmptyElementEnd(XmlTextReader reader) - { - reader.ReadStartElement(); - int line = reader.LineNumber - 1; - - // Take off two as we have moved passed the end tag - // column. - int column = reader.LinePosition - 2; - return new Location(column, line); - } - - /// - /// Creates an XmlWriterSettings based on the text editor properties. - /// - static XmlWriterSettings CreateXmlWriterSettings(string lineTerminator, bool tabsToSpaces, int tabIndent) + public WixBinaryElement[] GetBinaries() { - XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); - xmlWriterSettings.CloseOutput = true; - xmlWriterSettings.Indent = true; - xmlWriterSettings.NewLineChars = lineTerminator; - xmlWriterSettings.OmitXmlDeclaration = true; - - if (tabsToSpaces) { - string spaces = " "; - xmlWriterSettings.IndentChars = spaces.PadRight(tabIndent); - } else { - xmlWriterSettings.IndentChars = "\t"; + List binaries = new List(); + foreach (WixBinaryElement element in SelectNodes("//w:Binary", namespaceManager)) { + binaries.Add(element); } - return xmlWriterSettings; - } - - /// - /// Gets the dialog element with the specified id. - /// - XmlElement GetDialogElement(string id) - { - string xpath = String.Concat("//w:Dialog[@Id='", XmlEncode(id), "']"); - return (XmlElement)SelectSingleNode(xpath, namespaceManager); - } - - /// - /// Checks to see if an element exists with the specified Id attribute. - /// - bool ElementIdExists(string elementName, string id) - { - string xpath = String.Concat("//w:", elementName, "[@Id='", XmlEncode(id), "']"); - XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable)); - return nodes.Count > 0; - } - - static string XmlEncode(string item) - { - char quoteChar = '\''; - return XmlEncoder.Encode(item, quoteChar); + return binaries.ToArray(); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs index 1355194b0a..371c237641 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentLineSegment.cs @@ -6,11 +6,12 @@ // using System; -using ICSharpCode.TextEditor.Document; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Editor; namespace ICSharpCode.WixBinding { - public class WixDocumentLineSegment : ISegment + public class WixDocumentLineSegment { int offset; int length; @@ -22,21 +23,13 @@ namespace ICSharpCode.WixBinding } public int Offset { - get { - return offset; - } - set { - offset = value; - } + get { return offset; } + set { offset = value; } } public int Length { - get { - return length; - } - set { - length = value; - } + get { return length; } + set { length = value; } } public override string ToString() @@ -51,10 +44,50 @@ namespace ICSharpCode.WixBinding public override bool Equals(object obj) { - WixDocumentLineSegment lineSegment = obj as WixDocumentLineSegment; - if (lineSegment == null) return false; - if (this == lineSegment) return true; - return offset == lineSegment.offset && length == lineSegment.length; + WixDocumentLineSegment rhs = obj as WixDocumentLineSegment; + if (rhs != null) { + return (offset == rhs.offset) && (length == rhs.length); + } + return false; + } + + public static WixDocumentLineSegment ConvertRegionToSegment(IDocument document, DomRegion region) + { + // Single line region + if (IsSingleLineRegion(region)) { + return ConvertRegionToSingleLineSegment(document, region); + } + return ConvertRegionToMultiLineSegment(document, region); + } + + static bool IsSingleLineRegion(DomRegion region) + { + return region.BeginLine == region.EndLine; + } + + static WixDocumentLineSegment ConvertRegionToSingleLineSegment(IDocument document, DomRegion region) + { + IDocumentLine documentLine = document.GetLine(region.BeginLine + 1); + return new WixDocumentLineSegment(documentLine.Offset + region.BeginColumn, + region.EndColumn + 1 - region.BeginColumn); + } + + static WixDocumentLineSegment ConvertRegionToMultiLineSegment(IDocument document, DomRegion region) + { + int length = 0; + int startOffset = 0; + for (int line = region.BeginLine; line <= region.EndLine; ++line) { + IDocumentLine currentDocumentLine = document.GetLine(line + 1); + if (line == region.BeginLine) { + length += currentDocumentLine.TotalLength - region.BeginColumn; + startOffset = currentDocumentLine.Offset + region.BeginColumn; + } else if (line < region.EndLine) { + length += currentDocumentLine.TotalLength; + } else { + length += region.EndColumn + 1; + } + } + return new WixDocumentLineSegment(startOffset, length); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs new file mode 100644 index 0000000000..87fef84c63 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocumentReader.cs @@ -0,0 +1,293 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Xml; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Dom; + +namespace ICSharpCode.WixBinding +{ + public class WixDocumentReader + { + XmlTextReader reader; + + /// + /// Class used to store the line number and dialog id of the + /// dialog element start tag. + /// + class DialogStartElement + { + int line = -1; + string id = String.Empty; + + public DialogStartElement(int line, string id) + { + this.id = id; + this.line = line; + } + + public int Line { + get { return line; } + } + + public string Id { + get { return id; } + } + } + + public WixDocumentReader(TextReader textReader) + { + reader = new XmlTextReader(textReader); + } + + public ReadOnlyCollection GetDialogIds() + { + using (reader) { + List dialogIds = new List(); + object dialogElementName = reader.NameTable.Add("Dialog"); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + if (IsElementMatch(dialogElementName, reader.LocalName)) { + AddDialogId(dialogIds); + } + break; + } + } + return new ReadOnlyCollection(dialogIds); + } + } + + /// + /// Checks that the atomised element names match. + /// + bool IsElementMatch(object elementName, object currentElementName) + { + return elementName == currentElementName; + } + + /// + /// Reads the dialog id and adds it to the list of dialogs found so far. + /// + void AddDialogId(List dialogIds) + { + string id = GetIdAttributeValueFromCurrentNode(); + if (id.Length > 0) { + dialogIds.Add(id); + } + } + + string GetIdAttributeValueFromCurrentNode() + { + if (reader.MoveToAttribute("Id")) { + if (reader.Value != null) { + return reader.Value; + } + } + return String.Empty; + } + + /// + /// Gets the line and column where the specified element starts. The column + /// returned is the column containing the opening tag (<). + /// + public Location GetStartElementLocation(string elementName, string elementIdAttribute) + { + using (reader) { + object elementNameObject = reader.NameTable.Add(elementName); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + if (IsElementMatch(elementNameObject, reader.LocalName)) { + Location location = GetStartElementLocationIfMatch(elementIdAttribute); + if (!location.IsEmpty) { + return location; + } + } + break; + } + } + } + return Location.Empty; + } + + /// + /// Gets the line and column position if the element's attribute id matches the + /// element at the current reader position. + /// + Location GetStartElementLocationIfMatch(string idAttributeValue) + { + // Store the column and line position since the call to GetIdFromCurrentNode will + // move to the Id attribute. + int line = reader.LineNumber - 1; + int column = reader.LinePosition - 2; // Take off 2 to so the '<' is located. + + if (idAttributeValue == GetIdAttributeValueFromCurrentNode()) { + return new Location(column, line); + } + return Location.Empty; + } + + public Location GetEndElementLocation(string name, string id) + { + using (reader) { + bool startElementFound = false; + object elementName = reader.NameTable.Add(name); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + if (IsElementMatch(elementName, reader.LocalName)) { + Location location = GetStartElementLocationIfMatch(id); + startElementFound = !location.IsEmpty; + } + break; + case XmlNodeType.EndElement: + if (startElementFound) { + if (IsElementMatch(elementName, reader.LocalName)) { + // Take off an extra 2 from the line position so we get the + // correct column for the < tag rather than the element name. + return new Location(reader.LinePosition - 3, reader.LineNumber - 1); + } + } + break; + } + } + } + return Location.Empty; + } + + /// + /// Gets the dialog id at the specified line. + /// + /// Line numbers start from zero. + public string GetDialogId(int line) + { + // Add one to line since XmlTextReader line numbers start from one. + ++line; + + DialogStartElement dialogStartElement = null; + + using (reader) { + object dialogElementName = reader.NameTable.Add("Dialog"); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + if (IsElementMatch(dialogElementName, reader.LocalName)) { + if (line < reader.LineNumber) { + return null; + } else if (line == reader.LineNumber) { + return GetIdAttributeValueFromCurrentNode(); + } else if (reader.IsStartElement()) { + dialogStartElement = new DialogStartElement(reader.LineNumber, GetIdAttributeValueFromCurrentNode()); + } + } + break; + case XmlNodeType.EndElement: + if (IsElementMatch(dialogElementName, reader.LocalName)) { + if (line > dialogStartElement.Line && line <= reader.LineNumber) { + return dialogStartElement.Id; + } + } + break; + } + } + } + return null; + } + + /// + /// Gets the region (start line, column to end line, column) of the xml + /// element that has the specified id. This includes the start and end tags, the start column is the column + /// containing the start tag and the end column is the column containing the final + /// end tag marker. + /// + /// The name of the element. + /// The id attribute value of the element. + public DomRegion GetElementRegion(string name, string id) + { + Location startLocation = Location.Empty; + + using (reader) { + int nestedElementsCount = -1; + object elementName = reader.NameTable.Add(name); + while (reader.Read()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + if (IsElementMatch(elementName, reader.LocalName)) { + if (nestedElementsCount == -1) { + bool isEmptyElement = reader.IsEmptyElement; + startLocation = GetStartElementLocationIfMatch(id); + if (!startLocation.IsEmpty) { + nestedElementsCount = 0; + if (isEmptyElement) { + Location endLocation = GetEmptyElementEnd(); + return DomRegion.FromLocation(startLocation, endLocation); + } + } + } else if (!reader.IsEmptyElement) { + ++nestedElementsCount; + } + } + break; + case XmlNodeType.EndElement: + if (!startLocation.IsEmpty && IsElementMatch(elementName, reader.LocalName)) { + if (nestedElementsCount == 0) { + Location endLocation = GetEndElementEnd(); + return DomRegion.FromLocation(startLocation, endLocation); + } + --nestedElementsCount; + } + break; + } + } + } + return DomRegion.Empty; + } + + /// + /// Determines the end of the empty element including the final end tag marker + /// (the greater than sign). This method moves the XmlTextReader to the end + /// of the element tag. + /// + Location GetEmptyElementEnd() + { + reader.ReadStartElement(); + int line = reader.LineNumber - 1; + + // Take off two as we have moved passed the end tag + // column. + int column = reader.LinePosition - 2; + return new Location(column, line); + } + + /// + /// Determines the end of the end element including the final end tag marker + /// (the greater than sign). This method moves the XmlTextReader to the end of + /// the end tag. + /// + Location GetEndElementEnd() + { + reader.ReadEndElement(); + int line = reader.LineNumber - 1; + + // Take off two as we have moved passed the end tag column. + int column = reader.LinePosition - 2; + + // If ReadEndElement has moved to the start of another element + // take off one from the column value otherwise the column + // value includes the start tag of the next element. + if (reader.NodeType == XmlNodeType.Element) { + --column; + } + return new Location(column, line); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixElementBase.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixElementBase.cs new file mode 100644 index 0000000000..da6cdb28d8 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixElementBase.cs @@ -0,0 +1,47 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using System.Xml; + +namespace ICSharpCode.WixBinding +{ + public abstract class WixElementBase : XmlElement + { + public WixElementBase(string localName, WixDocument document) + : base(document.GetWixNamespacePrefix(), localName, WixNamespaceManager.Namespace, document) + { + } + + public string Id { + get { return GetAttribute("Id"); } + set { SetAttribute("Id", value); } + } + + public string GetXml(WixTextWriter wixWriter) + { + StringBuilder xml = new StringBuilder(); + StringWriter stringWriter = new StringWriter(xml); + using (XmlWriter xmlWriter = wixWriter.Create(stringWriter)) { + WriteTo(xmlWriter); + } + return RemoveWixNamespace(xml.ToString()); + } + + string RemoveWixNamespace(string xml) + { + string namespaceDeclaration = String.Concat(" xmlns=\"", WixNamespaceManager.Namespace, "\""); + return xml.Replace(namespaceDeclaration, String.Empty); + } + + protected WixDocument OwnerWixDocument { + get { return (WixDocument)OwnerDocument; } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs index b131b8a8d6..882cc6a9ef 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs @@ -17,28 +17,104 @@ namespace ICSharpCode.WixBinding /// /// Represents a Wix File element in a Wix XML document. /// - public class WixFileElement : XmlElement + public class WixFileElement : WixElementBase { public const string FileElementName = "File"; WixComponentElement parentComponent; public WixFileElement(WixDocument document) - : base(document.WixNamespacePrefix, FileElementName, WixNamespaceManager.Namespace, document) + : base(FileElementName, document) { } - public WixFileElement(WixDocument document, string fileName) : this(document) + public WixFileElement(WixDocument document, string fileName) + : this(document) { Init(fileName); } - public WixFileElement(WixComponentElement component, string fileName) : this((WixDocument)component.OwnerDocument) + public WixFileElement(WixComponentElement component, string fileName) + : this((WixDocument)component.OwnerDocument) { parentComponent = component; Init(fileName); } + /// + /// Initialises a new Wix File element with the specified + /// . + /// + /// + /// The element generated will have an Id, LongName and Name + /// all set and derived from the + /// + void Init(string fileName) + { + Id = GenerateUniqueId(fileName); + FileName = Path.GetFileName(fileName); + Source = OwnerWixDocument.GetRelativePath(fileName);; + } + + string GenerateUniqueId(string fileName) + { + string fileNameWithoutPath = Path.GetFileName(fileName); + return GenerateUniqueId(Path.GetDirectoryName(fileName), fileNameWithoutPath); + } + + /// + /// Generates a unique id for the entire document that this file element + /// belongs to. + /// + /// The full path of the parent directory + /// for the filename. + /// The name of the file to generate a unique + /// id for. This does not include any path. + string GenerateUniqueId(string parentDirectory, string fileName) + { + string id = GenerateId(fileName); + if (!OwnerWixDocument.FileIdExists(id)) { + return id; + } + + id = GenerateIdFromParentDirectory(parentDirectory, id); + if (!OwnerWixDocument.FileIdExists(id)) { + return id; + } + + return GenerateUniqueIdByAppendingNumberToFileNameId(id); + } + + string GenerateIdFromParentDirectory(string parentDirectory, string fileNameId) + { + string id = GenerateIdFromParentDirectory(parentDirectory); + if (!String.IsNullOrEmpty(id)) { + return String.Concat(id, ".", fileNameId); + } + return fileNameId; + } + string GenerateIdFromParentDirectory(string parentDirectory) + { + string parentDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(parentDirectory); + if (parentDirectoryName.Length > 0) { + return WixFileElement.GenerateId(parentDirectoryName); + } + return String.Empty; + } + + string GenerateUniqueIdByAppendingNumberToFileNameId(string fileNameId) + { + string id = String.Empty; + int count = 0; + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileNameId); + string extension = Path.GetExtension(fileNameId); + do { + ++count; + id = String.Concat(fileNameWithoutExtension, count, extension); + } while (OwnerWixDocument.FileIdExists(id)); + + return id; + } /// /// Generates an id from the filename. /// @@ -60,51 +136,22 @@ namespace ICSharpCode.WixBinding } /// - /// Gets the filename where the resource being added to the setup - /// package can be found. Typically this is relative to the Wix document the - /// File element is a part of. - /// - public string Source { - get { return GetAttribute("Source"); } - set { SetAttribute("Source", value); } - } - - public string Id { - get { return GetAttribute("Id"); } - set { SetAttribute("Id", value); } - } - - /// - /// Gets whether the file is the KeyPath for its parent component. - /// - public string KeyPath { - get { return GetAttribute("KeyPath"); } - set { SetAttribute("KeyPath", value); } - } - - /// - /// Gets the name of the file without any path information. - /// This is the name that will be used when installing the file. - /// - public string FileName { - get { return GetAttribute("Name"); } - set { SetAttribute("Name", value); } - } - - /// - /// Gets the full path to the file. If the parent WixDocument - /// has no filename then the relative path as stored in the - /// wix document is returned. + /// Returns a valid id character for the given position. If the + /// character is an invalid character it is replaced with an underscore. /// - public string SourceFullPath { - get { - WixDocument document = OwnerDocument as WixDocument; - if (document != null && !String.IsNullOrEmpty(document.FileName)) { - string directory = Path.GetDirectoryName(document.FileName); - return Path.GetFullPath(Path.Combine(directory, Source)); + static char GetIdCharacter(char ch, int index) + { + if (IsValidIdCharacter(ch)) { + // First char must be a letter or underscore. + if (index == 0) { + if (IsLetterOrUnderscore(ch)) { + return ch; + } + } else { + return ch; } - return Source; - } + } + return '_'; } /// @@ -133,82 +180,48 @@ namespace ICSharpCode.WixBinding /// static bool IsLetter(char ch) { - return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); + return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')); } /// - /// Returns a valid id character for the given position. If the - /// character is an invalid character it is replaced with an underscore. + /// Gets the filename where the resource being added to the setup + /// package can be found. Typically this is relative to the Wix document the + /// File element is a part of. /// - static char GetIdCharacter(char ch, int index) - { - if (IsValidIdCharacter(ch)) { - // First char must be a letter or underscore. - if (index > 0 || IsLetterOrUnderscore(ch)) { - return ch; - } - } - return '_'; + public string Source { + get { return GetAttribute("Source"); } + set { SetAttribute("Source", value); } } /// - /// Initialises a new Wix File element with the specified - /// . + /// Gets whether the file is the KeyPath for its parent component. /// - /// - /// The element generated will have an Id, LongName and Name - /// all set and derived from the - /// - void Init(string fileName) - { - WixDocument document = (WixDocument)OwnerDocument; - string baseDirectory = Path.GetDirectoryName(document.FileName); - string sourceFileName = FileUtility.GetRelativePath(baseDirectory, fileName); - - Source = sourceFileName; - FileName = Path.GetFileName(fileName); - - // Generate a unique id from the filename. - string id = FileName; - Id = GenerateUniqueId(Path.GetDirectoryName(fileName), id); + public string KeyPath { + get { return GetAttribute("KeyPath"); } + set { SetAttribute("KeyPath", value); } } /// - /// Generates a unique id for the entire document that this file element - /// belongs to. + /// Gets the name of the file without any path information. + /// This is the name that will be used when installing the file. /// - /// The full path of the parent directory - /// for the filename. - /// The name of the file to generate a unique - /// id for. This does not include any path. - string GenerateUniqueId(string parentDirectory, string fileName) + public string FileName { + get { return GetAttribute("Name"); } + set { SetAttribute("Name", value); } + } + + /// + /// Gets the full path to the file. If the parent WixDocument + /// has no filename then the relative path as stored in the + /// wix document is returned. + /// + public string GetSourceFullPath() { - string id = GenerateId(fileName); - WixDocument document = (WixDocument)OwnerDocument; - if (!document.FileIdExists(id)) { - return id; + if (!String.IsNullOrEmpty(OwnerWixDocument.FileName)) { + string directory = Path.GetDirectoryName(OwnerWixDocument.FileName); + return Path.GetFullPath(Path.Combine(directory, Source)); } - - // Add the file's parent directory to the id. - string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory); - if (parentDirectoryName.Length > 0) { - id = String.Concat(WixFileElement.GenerateId(parentDirectoryName), ".", id); - if (!document.FileIdExists(id)) { - return id; - } - fileName = id; - } - - // Add a number to the file name until we get a unique id. - int count = 0; - string idStart = Path.GetFileNameWithoutExtension(fileName); - string extension = Path.GetExtension(fileName); - do { - ++count; - id = String.Concat(idStart, count, extension); - } while (document.FileIdExists(id)); - - return id; + return Source; } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileName.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileName.cs new file mode 100644 index 0000000000..9c10127ef0 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileName.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; + +namespace ICSharpCode.WixBinding +{ + public class WixFileName + { + public const string WixSourceFileExtension = ".wxs"; + public const string WixIncludeFileExtension = ".wxi"; + + WixFileName() + { + } + + /// + /// Checks the file extension to see if the file is a Wix file. The file + /// can either be a Wix source file (.wxs) or a Wix include file (.wxi). + /// + public static bool IsWixFileName(string fileName) + { + if (String.IsNullOrEmpty(fileName)) { + return false; + } + string extension = Path.GetExtension(fileName.ToLowerInvariant()); + switch (extension) { + case WixSourceFileExtension: + return true; + case WixIncludeFileExtension: + return true; + } + return false; + } + + /// + /// Checks whether the file extension is for a Wix source file (.wxs). + /// + public static bool IsWixSourceFileName(string fileName) + { + return String.Compare(Path.GetExtension(fileName), WixSourceFileExtension, true) == 0; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs index 54c1930df7..a807c047a5 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesDiff.cs @@ -124,7 +124,7 @@ namespace ICSharpCode.WixBinding { List fileNames = new List(); foreach (WixFileElement fileElement in fileElements) { - fileNames.Add(fileElement.SourceFullPath); + fileNames.Add(fileElement.GetSourceFullPath()); } return fileNames; } diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs index 6443fd5ffc..545d601c54 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs @@ -193,7 +193,7 @@ namespace ICSharpCode.WixBinding WixDirectoryElement parentElement = (WixDirectoryElement)view.SelectedElement; // Add directory. - string directoryName = WixDirectoryElement.GetLastDirectoryName(directory); + string directoryName = WixDirectoryElement.GetLastFolderInDirectoryName(directory); WixDirectoryElement directoryElement = AddDirectory(parentElement, directoryName); AddFiles(directoryElement, directory); @@ -216,14 +216,14 @@ namespace ICSharpCode.WixBinding /// the Wix document and the files on the file system and /// shows the differences. /// - public void ShowDiff() + public void CalculateDiff() { WixPackageFilesDiff diff = new WixPackageFilesDiff(directoryReader); diff.ExcludedFileNames.Add(excludedNames); WixDirectoryElementBase directoryElement = view.SelectedElement as WixDirectoryElementBase; if (directoryElement == null) { - directoryElement = RootDirectoryElement; + directoryElement = GetRootDirectoryElement(); } // Directory element selected? @@ -314,7 +314,7 @@ namespace ICSharpCode.WixBinding WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name) { if (parentElement == null) { - parentElement = RootDirectoryElement; + parentElement = GetRootDirectoryElement(); if (parentElement == null) { parentElement = document.AddRootDirectory(); } @@ -327,13 +327,12 @@ namespace ICSharpCode.WixBinding /// Takes into account whether the WixDocument is using a /// DirectoryRef element. /// - WixDirectoryElementBase RootDirectoryElement { - get { - if (usingRootDirectoryRef) { - return document.RootDirectoryRef; - } - return document.RootDirectory; + WixDirectoryElementBase GetRootDirectoryElement() + { + if (usingRootDirectoryRef) { + return document.GetRootDirectoryRef(); } + return document.GetRootDirectory(); } /// @@ -359,12 +358,11 @@ namespace ICSharpCode.WixBinding /// /// Adds a new component element to the directory element. /// - /// The id attribute the component element will have. - WixComponentElement AddComponent(WixDirectoryElement parentElement, string id) + WixComponentElement AddComponent(WixDirectoryElement parentDirectory, string fileName) { - if (parentElement != null) { - WixComponentElement element = parentElement.AddComponent(id); - return element; + if (parentDirectory != null) { + WixComponentElement component = parentDirectory.AddComponent(fileName); + return component; } return null; } @@ -382,15 +380,15 @@ namespace ICSharpCode.WixBinding /// FindRootDirectoryResult FindRootDirectory(WixDocument currentDocument) { - if (currentDocument.IsProductDocument) { - WixDirectoryElement rootDirectory = currentDocument.RootDirectory; + if (currentDocument.HasProduct) { + WixDirectoryElement rootDirectory = currentDocument.GetRootDirectory(); if (rootDirectory != null) { view.AddDirectories(rootDirectory.GetDirectories()); } document = currentDocument; return FindRootDirectoryResult.RootDirectoryFound; } else { - WixDirectoryRefElement rootDirectoryRef = currentDocument.RootDirectoryRef; + WixDirectoryRefElement rootDirectoryRef = currentDocument.GetRootDirectoryRef(); if (rootDirectoryRef != null) { view.AddDirectories(rootDirectoryRef.GetDirectories()); document = currentDocument; @@ -421,8 +419,7 @@ namespace ICSharpCode.WixBinding /// WixComponentElement AddFileWithParentComponent(WixDirectoryElement directoryElement, string fileName) { - string id = WixComponentElement.GenerateIdFromFileName(document, fileName); - WixComponentElement component = AddComponent(directoryElement, id); + WixComponentElement component = AddComponent(directoryElement, fileName); AddFile(component, fileName, true); return component; } @@ -440,7 +437,7 @@ namespace ICSharpCode.WixBinding void AddDirectoryContents(WixDirectoryElement directoryElement, string directory) { foreach (string subDirectory in DirectoryReader.GetDirectories(directory)) { - string subDirectoryName = WixDirectoryElement.GetLastDirectoryName(subDirectory); + string subDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(subDirectory); if (!excludedNames.IsExcluded(subDirectoryName)) { WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName); AddFiles(subDirectoryElement, subDirectory); diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs index 7790220592..21d7fced40 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPropertyParser.cs @@ -10,21 +10,6 @@ using System.Text; namespace ICSharpCode.WixBinding { - /// - /// Interface that allows a class to convert a Wix property name into a value. - /// - public interface IWixPropertyValueProvider - { - /// - /// Gets the property value for the specified name. Wix property names are - /// case sensitive. - /// - /// - /// The original null if the name cannot be found. - /// - string GetValue(string name); - } - /// /// Parses a string of Wix property values (e.g. "$(var.DATAPATH)") it also /// handles MSBuild property values (e.g. "$(SharpDevelopBinPath)"). @@ -42,9 +27,6 @@ namespace ICSharpCode.WixBinding { } - /// - /// Expands the Wix property values using the IWixPropertyValueProvider - /// public static string Parse(string input, IWixPropertyValueProvider valueProvider) { StringBuilder output = new StringBuilder(); diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixTextWriter.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixTextWriter.cs new file mode 100644 index 0000000000..ca57c35e4d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixTextWriter.cs @@ -0,0 +1,58 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Xml; +using ICSharpCode.SharpDevelop.Editor; + +namespace ICSharpCode.WixBinding +{ + public class WixTextWriter + { + ITextEditorOptions textEditorOptions; + + public WixTextWriter(ITextEditorOptions textEditorOptions) + { + this.textEditorOptions = textEditorOptions; + } + + public XmlWriterSettings CreateXmlWriterSettings() + { + XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); + xmlWriterSettings.CloseOutput = true; + xmlWriterSettings.Indent = true; + xmlWriterSettings.NewLineChars = "\r\n"; + xmlWriterSettings.OmitXmlDeclaration = true; + + if (textEditorOptions.ConvertTabsToSpaces) { + string space = " "; + xmlWriterSettings.IndentChars = space.PadRight(textEditorOptions.IndentationSize); + } else { + xmlWriterSettings.IndentChars = "\t"; + } + return xmlWriterSettings; + } + + public XmlWriter Create(TextWriter textWriter) + { + XmlWriterSettings settings = CreateXmlWriterSettings(); + return XmlTextWriter.Create(textWriter, settings); + } + + public XmlWriter Create(string fileName) + { + XmlWriterSettings settings = CreateXmlWriterSettings(); + return Create(fileName, settings); + } + + protected virtual XmlWriter Create(string fileName, XmlWriterSettings settings) + { + return XmlTextWriter.Create(fileName, settings); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin index 14505c1a10..d9f29f187c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin @@ -217,7 +217,7 @@ class = "ICSharpCode.WixBinding.AddDirectoryCommand"/> + class = "ICSharpCode.WixBinding.AddFilesCommand"/> @@ -227,7 +227,7 @@ + class = "ICSharpCode.WixBinding.AddFilesCommand"/> diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj index 8d31f52176..5f49921a05 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -36,19 +37,45 @@ ..\..\..\..\..\AddIns\AddIns\BackendBindings\WixBinding\ + + 3.0 + + + 3.0 + + + 4.0 + + + 3.0 + - + + + + + + + + + + + + + + + @@ -96,6 +123,7 @@ + @@ -123,7 +151,6 @@ - @@ -167,6 +194,11 @@ Always + + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} + ICSharpCode.AvalonEdit + False + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop @@ -188,6 +220,11 @@ ICSharpCode.TextEditor False + + {0162E499-42D0-409B-AA25-EED21F75336B} + AvalonEdit.AddIn + False + {7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57} FormsDesigner diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs index efb43ab87f..fe8f392ecc 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapFromProjectTestFixture.cs @@ -49,7 +49,7 @@ namespace WixBinding.Tests.Document doc.FileName = docFileName; doc.LoadXml(GetMainWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog", this); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", this); using (Form dialog = wixDialog.CreateDialog(this)) { PictureBox pictureBox = (PictureBox)dialog.Controls[0]; hasImage = (pictureBox.Image != null); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs index e8d5b63016..bacf66f8fe 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/BitmapTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); WixDocument doc = new WixDocument(project, this); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { PictureBox pictureBox = (PictureBox)dialog.Controls[0]; hasImage = (pictureBox.Image != null); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs index 2f1151acdd..e6c4832a7c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonFontTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Button button = (Button)dialog.Controls[0]; fontName = button.Font.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs index b9873b97e5..eeb68d9aa3 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonTextTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Button nextButton = (Button)dialog.Controls[0]; nextButtonText = nextButton.Text; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs index cdd8c05dd2..0058ffae57 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ButtonsTestFixture.cs @@ -38,7 +38,7 @@ namespace WixBinding.Tests.DialogLoading doc.LoadXml(GetWixXml()); controlsAddedCount = 0; CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { foreach (Control control in dialog.Controls) { ++controlsAddedCount; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs index 794031d8d4..6ffcb6b3f6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/CheckBoxTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { CheckBox checkBox = (CheckBox)dialog.Controls[0]; name = checkBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs index c172d95f68..5fcf33bc69 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ComboBoxTestFixture.cs @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ComboBox comboBox = (ComboBox)dialog.Controls[0]; name = comboBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs index d16297593d..fd4a7e75d7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DefaultUIFontTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Button button = (Button)dialog.Controls[0]; fontName = button.Font.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs index 00f960a5c4..009bff25e9 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogMinimizeBoxTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogLoading { @@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form simpleDialog = wixDialog.CreateDialog()) { minimizeBox = simpleDialog.MinimizeBox; } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs index 01eafbfc10..bc78a9d2c1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DialogTitleTestFixture.cs @@ -11,6 +11,7 @@ using System; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogLoading { @@ -28,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { dialogTitle = dialog.Text; } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs index f90814036e..6843656936 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DirectoryListTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = (ListBox)dialog.Controls[0]; name = listBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs index a909cfcacb..bf9530d9e0 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/DisabledButtonTestFixture.cs @@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Button backButton = (Button)dialog.Controls[0]; disabled = !backButton.Enabled; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs index 638a9f12ef..d6d5e36167 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/GroupBoxTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { GroupBox groupBox = (GroupBox)dialog.Controls[0]; name = groupBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs index e204aab64e..050df6fdc1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidLocationTests.cs @@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading [TestFixtureSetUp] public void SetupFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); } [Test] @@ -47,7 +46,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); @@ -73,7 +72,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs index 9400f7a9c4..e816f51f58 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/InvalidSizeTests.cs @@ -28,8 +28,7 @@ namespace WixBinding.Tests.DialogLoading [TestFixtureSetUp] public void SetupFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); } [Test] @@ -45,7 +44,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); @@ -69,7 +68,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); @@ -93,7 +92,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); @@ -117,7 +116,7 @@ namespace WixBinding.Tests.DialogLoading "\t\r\n" + ""; doc.LoadXml(xml); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(); Assert.Fail("Expected an exception before this line."); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs index f53b1c14df..6a9e0b16c7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelFontFromPropertyTestFixture.cs @@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Label titleLabel = (Label)dialog.Controls[0]; titleLabelFontName = titleLabel.Font.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs index 6f19ef016b..4d44902095 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LabelTestFixture.cs @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Label label = (Label)dialog.Controls[0]; labelName = label.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs index 932d9b8d47..31e1cceaaf 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/LineTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Label line = (Label)dialog.Controls[0]; lineName = line.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs index 2824689820..08be3bf7cb 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListBoxTestFixture.cs @@ -35,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = (ListBox)dialog.Controls[0]; name = listBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs index 6ad93a71e0..ff643e2660 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ListViewTestFixture.cs @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListView listView = (ListView)dialog.Controls[0]; name = listView.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs index 0573dbe4d7..a049c78091 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MaskedEditTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { MaskedTextBox textBox = (MaskedTextBox)dialog.Controls[0]; name = textBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs index fff523ac72..6445143659 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingBitmapBinaryTestFixture.cs @@ -36,7 +36,7 @@ namespace WixBinding.Tests.DialogLoading WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); WixDocument doc = new WixDocument(project, this); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { // Should be the last control added to the dialog appears behind all // the other controls. This is what happens when you call SendToBack diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs index 951e6a5c4f..7f7d00607e 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/MissingRadioButtonGroupTestFixture.cs @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogLoading doc.LoadXml(GetWixXml()); controlsAddedCount = 0; CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { foreach (Control control in dialog.Controls) { ++controlsAddedCount; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs index cf1ab2c622..052ef108f3 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/NullComponentCreatorTestFixture.cs @@ -29,7 +29,7 @@ namespace WixBinding.Tests.DialogLoading WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); WixDocument doc = new WixDocument(project); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); try { wixDialog.CreateDialog(null); Assert.Fail("Expected an ArgumentException"); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs index eb42c6ba8e..aa39944421 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/PathEditTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { TextBox textBox = (TextBox)dialog.Controls[0]; name = textBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs index 9a8daeadcd..a145c910f9 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ProgressBarTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ProgressBar progressBar = (ProgressBar)dialog.Controls[0]; name = progressBar.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs index d17032798c..d594a4689c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/RadioButtonTestFixture.cs @@ -41,7 +41,7 @@ namespace WixBinding.Tests.DialogLoading doc.LoadXml(GetWixXml()); controlsAddedCount = 0; CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { foreach (Control control in dialog.Controls) { ++controlsAddedCount; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs index 73d1fa37db..bd62b243db 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/ScrollableTextTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { RichTextBox textBox = (RichTextBox)dialog.Controls[0]; name = textBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs index fd3e28cc46..9ebfae2567 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SelectionTreeTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { TreeView treeView = (TreeView)dialog.Controls[0]; name = treeView.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs index 2cde6d3bf7..062b7e9b90 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogLoading { @@ -34,7 +35,7 @@ namespace WixBinding.Tests.DialogLoading { doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form simpleDialog = wixDialog.CreateDialog()) { dialogName = simpleDialog.Name; borderStyle = simpleDialog.FormBorderStyle; @@ -85,7 +86,7 @@ namespace WixBinding.Tests.DialogLoading [Test] public void DialogIdWithSingleQuote() { - Assert.IsNull(doc.GetDialog("Test'Id")); + Assert.IsNull(doc.CreateWixDialog("Test'Id", new MockTextFileReader())); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs index d22773de0d..e704c100a4 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/SimpleDialogUsingObjectCreatorTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogLoading WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { formComponent = CreatedComponents[0]; formName = dialog.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs index 813b8de4bf..6ab04db571 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextBoxTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { TextBox textBox = (TextBox)dialog.Controls[0]; name = textBox.Name; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs index ff02bc97f3..faa4d7182c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TextStyleNameWithSpecialXmlCharsTestFixture.cs @@ -24,7 +24,7 @@ namespace WixBinding.Tests.DialogLoading { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs index d546ab6f0c..6c29075030 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogLoading/TransparentLabelsTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogLoading CreatedComponents.Clear(); WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Label titleLabel = (Label)dialog.Controls[0]; titleLabelColor = titleLabel.BackColor; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs index 886f6cda91..2be2b33944 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/AddAcceptAndCancelButtonTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { Button nextButton = (Button)dialog.Controls[0]; dialog.AcceptButton = nextButton; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs index fcf3b12cbe..8e9fcbdba4 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonAddedTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { Button nextButton = new Button(); nextButton.Left = 200; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs index e8b1714f88..2528d3323a 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonChangedTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -31,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { Button nextButton = (Button)dialog.Controls[0]; nextButton.Left = 200; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs index 345770a054..288176ce42 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonRemovedTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { Button nextButton = (Button)dialog.Controls[0]; dialog.Controls.Remove(nextButton); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs index 2182ec0e0a..a933b04e9f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ButtonTextRemovedTestFixture.cs @@ -5,12 +5,14 @@ // $Revision$ // -using ICSharpCode.WixBinding; -using NUnit.Framework; using System; using System.Windows.Forms; using System.Xml; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + namespace WixBinding.Tests.DialogXmlGeneration { /// @@ -29,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { Button nextButton = (Button)dialog.Controls[0]; nextButton.Text = String.Empty; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs index dca3af0df2..c91162559d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxItemAddedTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ComboBox comboBox = (ComboBox)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs index 91bf977be8..fc6c8cdb0c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ComboBoxPropertyWithSpecialXmlCharsTestFixture.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs index f8fa5a162f..0170d2a80c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/DialogXmlWritingTestFixture.cs @@ -5,24 +5,25 @@ // $Revision$ // -using ICSharpCode.WixBinding; -using NUnit.Framework; using System; using System.Xml; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { [TestFixture] public class DialogXmlWritingTestFixture { - XmlElement dialogElement; + WixDialogElement dialogElement; [TestFixtureSetUp] public void SetUpFixture() { - XmlDocument doc = new XmlDocument(); + WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - dialogElement = (XmlElement)doc.SelectSingleNode("//w:Dialog", new WixNamespaceManager(doc.NameTable)); + dialogElement = (WixDialogElement)doc.SelectSingleNode("//w:Dialog", new WixNamespaceManager(doc.NameTable)); dialogElement.SetAttribute("Id", "id"); dialogElement.SetAttribute("Title", "title"); XmlElement controlElement = doc.CreateElement("Control", WixNamespaceManager.Namespace); @@ -30,28 +31,43 @@ namespace WixBinding.Tests.DialogXmlGeneration } [Test] - public void Tabs() + public void WixDocumentGetXmlWithTabs() { - string outputXml = WixDocument.GetXml(dialogElement, "\r\n", false, 4); - string expectedXml = "\r\n" + + MockTextEditorOptions options = new MockTextEditorOptions(); + options.ConvertTabsToSpaces = false; + options.IndentationSize = 4; + + WixTextWriter wixWriter = new WixTextWriter(options); + + string outputXml = dialogElement.GetXml(wixWriter); + string expectedXml = + "\r\n" + "\t\r\n" + ""; Assert.AreEqual(expectedXml, outputXml); } [Test] - public void Spaces() + public void WixDocumentGetXmlWithSpaces() { - string outputXml = WixDocument.GetXml(dialogElement, "\n", true, 4); - string expectedXml = "\n" + - " \n" + + MockTextEditorOptions options = new MockTextEditorOptions(); + options.ConvertTabsToSpaces = true; + options.IndentationSize = 4; + + WixTextWriter wixWriter = new WixTextWriter(options); + + string outputXml = dialogElement.GetXml(wixWriter); + string expectedXml = + "\r\n" + + " \r\n" + ""; Assert.AreEqual(expectedXml, outputXml); } string GetWixXml() { - return "\r\n" + + return + "\r\n" + "\t\r\n" + "\t\t\r\n" + "\t\t\t\r\n" + diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs index b7e3013c99..58316fe7ed 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/GroupBoxContainingControlsTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -35,7 +36,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { GroupBox groupBox = new GroupBox(); groupBox.Name = "NewGroupBox"; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs index bfd9863623..22c34f5343 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxAddedTestFixture.cs @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = new ListBox(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs index 3228b2f652..f79d312aac 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemAddedTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = (ListBox)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs index 589188a8d1..53d14142ad 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxItemRemovedTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = (ListBox)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs index 7c573b0851..13f7a06f7b 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxPropertyWithSpecialXmlCharsTestFixture.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs index 1fbe1f7427..dc236a8b82 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListBoxUpdatedTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListBox listBox = (ListBox)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs index 4f3dabed24..33faaf6e39 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewAddedTestFixture.cs @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListView listView = new ListView(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs index 0e195b9002..65c1604f6d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemAddedTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListView listView = (ListView)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs index d0df812620..a4088d1a1c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewItemRemovedTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { ListView listView = (ListView)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs index 4ff4b9a009..5b64735c16 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/ListViewPropertyWithSpecialXmlCharsTestFixture.cs @@ -25,8 +25,8 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); - using (Form dialog = wixDialog.CreateDialog(this)) { + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); + using (Form dialog = wixDialog.CreateDialog(this)) { XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog); } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/MinimizeBoxChangedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/MinimizeBoxChangedTestFixture.cs index ebed176a10..67972d4ac1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/MinimizeBoxChangedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/MinimizeBoxChangedTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -30,7 +31,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { dialog.MinimizeBox = true; dialogElement = wixDialog.UpdateDialogElement(dialog); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/NonRadioButtonAddedToGroupTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/NonRadioButtonAddedToGroupTestFixture.cs index 9d123f1b5e..f2877886c1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/NonRadioButtonAddedToGroupTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/NonRadioButtonAddedToGroupTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { RadioButtonGroupBox radioButtonGroup = (RadioButtonGroupBox)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonAddedTestFixture.cs index dfa643bfc1..80bc1076b5 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonAddedTestFixture.cs @@ -30,7 +30,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Panel radioButtonGroup = (Panel)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupAddedTestFixture.cs index fe70c862ad..b237fd6126 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupAddedTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { RadioButtonGroupBox radioButtonGroup = new RadioButtonGroupBox(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupChangedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupChangedTestFixture.cs index f37f27b930..0a365dbf06 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupChangedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupChangedTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Panel radioButtonGroup = (Panel)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs index cbe78521ad..ee2654adf1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonGroupPropertyWithSpecialXmlCharTestFixture.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { XmlElement dialogElement = wixDialog.UpdateDialogElement(dialog); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonRemovedTestFixture.cs index 6bd43bcc09..740777074c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/RadioButtonRemovedTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); CreatedComponents.Clear(); - WixDialog wixDialog = doc.GetDialog("AcceptLicenseDialog"); + WixDialog wixDialog = doc.CreateWixDialog("AcceptLicenseDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog(this)) { Panel radioButtonGroup = (Panel)dialog.Controls[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/SimpleDialogTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/SimpleDialogTestFixture.cs index 4f8be9123a..53c51fc457 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/SimpleDialogTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DialogXmlGeneration/SimpleDialogTestFixture.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using WixBinding; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.DialogXmlGeneration { @@ -29,7 +30,7 @@ namespace WixBinding.Tests.DialogXmlGeneration WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDialog wixDialog = doc.GetDialog("WelcomeDialog"); + WixDialog wixDialog = doc.CreateWixDialog("WelcomeDialog", new MockTextFileReader()); using (Form dialog = wixDialog.CreateDialog()) { dialog.Text = "New dialog title"; dialog.ClientSize = new Size(200, 100); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/ExcludedFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/ExcludedFilesTestFixture.cs index 0884607a03..25f3362a2e 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/ExcludedFilesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/ExcludedFilesTestFixture.cs @@ -29,7 +29,7 @@ namespace WixBinding.Tests.Diff doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); diff.ExcludedFileNames.Add("*.pdb"); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/MissingDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/MissingDirectoryTestFixture.cs index 8c01fe5ab2..b2322eeee0 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/MissingDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/MissingDirectoryTestFixture.cs @@ -31,7 +31,7 @@ namespace WixBinding.Tests.Diff doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); diff.ExcludedFileNames.Add(".svn"); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/NoDifferentFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/NoDifferentFilesTestFixture.cs index 60b9d9f2cc..3c4804e224 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/NoDifferentFilesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/NoDifferentFilesTestFixture.cs @@ -29,7 +29,7 @@ namespace WixBinding.Tests.Diff doc.FileName = @"C:\Projects\Setup\Setup.wxs"; doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneMissingFileTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneMissingFileTestFixture.cs index 5132669214..8acfd85829 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneMissingFileTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneMissingFileTestFixture.cs @@ -24,7 +24,7 @@ namespace WixBinding.Tests.Diff doc.FileName = @"C:\Projects\Setup\Setup.wxs"; doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneNewFileTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneNewFileTestFixture.cs index 71fe442c20..51f06dd344 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneNewFileTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/OneNewFileTestFixture.cs @@ -24,7 +24,7 @@ namespace WixBinding.Tests.Diff doc.FileName = @"C:\Projects\Setup\Setup.wxs"; doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Diff/SameFileReferencedTwiceTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Diff/SameFileReferencedTwiceTestFixture.cs index b091e72786..6fa4ef3a52 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Diff/SameFileReferencedTwiceTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Diff/SameFileReferencedTwiceTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.Diff doc.FileName = @"C:\Projects\Setup\Setup.wxs"; doc.LoadXml(GetWixXml()); WixPackageFilesDiff diff = new WixPackageFilesDiff(this); - diffResults = diff.Compare(doc.RootDirectory); + diffResults = diff.Compare(doc.GetRootDirectory()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs index fbc43443ec..ca1ca61ec1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs @@ -48,7 +48,7 @@ namespace WixBinding.Tests.DirectoryImport editor.AddDirectory(directory); WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable); - appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild; + appDirectoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild; myAppExeFileComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component", nsManager); myAppExeFileElement = (WixFileElement)myAppExeFileComponentElement.LastChild; docsDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='docs']", nsManager); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithInvalidIdCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithInvalidIdCharsTestFixture.cs index f07ecb1d1c..6b3c2fa38f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithInvalidIdCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithInvalidIdCharsTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.DirectoryImport public void AddDirectoryWithHyphen() { string directoryName = "Test-directory"; - WixDirectoryElement element = document.RootDirectory.AddDirectory(directoryName); + WixDirectoryElement element = document.GetRootDirectory().AddDirectory(directoryName); Assert.AreEqual("Test_directory", element.Id); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs index ef3e5d5cb5..fc6cd6583c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryWithSpecialXmlCharsTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.DirectoryImport public void AddDirectoryWithSingleQuoteChar() { string directoryName = "Test'directory"; - WixDirectoryElement element = document.RootDirectory.AddDirectory(directoryName); + WixDirectoryElement element = document.GetRootDirectory().AddDirectory(directoryName); Assert.AreEqual(directoryName, element.DirectoryName); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs index 962134e237..628bee5960 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs @@ -34,7 +34,7 @@ namespace WixBinding.Tests.DirectoryImport public void SetUpFixture() { base.InitFixture(); - WixDirectoryElement programFilesFolderElement = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild; + WixDirectoryElement programFilesFolderElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild; view.SelectedElement = programFilesFolderElement; editor.AddDirectory(directory); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs index 60b2cf3906..3ae1e05555 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs @@ -43,7 +43,7 @@ namespace WixBinding.Tests.DirectoryImport editor.AddDirectory(directory); nsManager = new WixNamespaceManager(editor.Document.NameTable); - appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager); + appDirectoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().SelectSingleNode("w:Directory[@Name='MyApp']", nsManager); readmeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='readme.txt']", nsManager); licenseComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='license.txt']", nsManager); exeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager); @@ -76,7 +76,7 @@ namespace WixBinding.Tests.DirectoryImport view.SelectedElement = null; editor.AddDirectory(directory2); - WixDirectoryElement directoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='a-app']", nsManager); + WixDirectoryElement directoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().SelectSingleNode("w:Directory[@Name='a-app']", nsManager); WixComponentElement exeComponentElement = (WixComponentElement)directoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager); Assert.AreEqual("A_appMyAppExe", exeComponentElement.Id); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs index 6e2c4c87a3..97baf29e4a 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs @@ -45,7 +45,7 @@ namespace WixBinding.Tests.DirectoryImport editor.AddDirectory(directory); WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable); - appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild; + appDirectoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild; docsDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='docs']", nsManager); srcDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='src']", nsManager); readmeFileElement = (WixFileElement)docsDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildComponentsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildComponentsTestFixture.cs index bd376c29f4..40f52236a1 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildComponentsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildComponentsTestFixture.cs @@ -27,7 +27,7 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - WixDirectoryElement rootDirectory = doc.RootDirectory; + WixDirectoryElement rootDirectory = doc.GetRootDirectory(); WixDirectoryElement[] rootChildDirectories = rootDirectory.GetDirectories(); WixDirectoryElement programFilesDirectory = rootChildDirectories[0]; WixDirectoryElement[] programFilesChildDirectories = programFilesDirectory.GetDirectories(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildDirectoriesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildDirectoriesTestFixture.cs index 308242957b..6da37e121f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildDirectoriesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildDirectoriesTestFixture.cs @@ -5,12 +5,15 @@ // $Revision$ // -using ICSharpCode.WixBinding; -using NUnit.Framework; using System; using System.IO; +using System.Resources; using System.Xml; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + namespace WixBinding.Tests.Document { /// @@ -30,9 +33,11 @@ namespace WixBinding.Tests.Document [TestFixtureSetUp] public void SetUpFixture() { + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); + WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - rootDirectory = doc.RootDirectory; + rootDirectory = doc.GetRootDirectory(); rootChildDirectories = rootDirectory.GetDirectories(); programFilesDirectory = rootChildDirectories[0]; programFilesChildDirectories = programFilesDirectory.GetDirectories(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildFilesTestFixture.cs index 0027411603..7ca9c7b5b2 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildFilesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/ChildFilesTestFixture.cs @@ -26,7 +26,7 @@ namespace WixBinding.Tests.Document doc = new WixDocument(); doc.FileName = @"C:\Projects\Setup\Setup.wxs"; doc.LoadXml(GetWixXml()); - WixDirectoryElement rootDirectory = doc.RootDirectory; + WixDirectoryElement rootDirectory = doc.GetRootDirectory(); WixDirectoryElement[] rootChildDirectories = rootDirectory.GetDirectories(); WixDirectoryElement programFilesDirectory = rootChildDirectories[0]; WixDirectoryElement[] programFilesChildDirectories = programFilesDirectory.GetDirectories(); @@ -48,13 +48,13 @@ namespace WixBinding.Tests.Document [Test] public void FirstFileElementFileName() { - Assert.AreEqual(@"C:\Projects\doc\license.rtf", files[0].SourceFullPath); + Assert.AreEqual(@"C:\Projects\doc\license.rtf", files[0].GetSourceFullPath()); } [Test] public void SecondFileElementFileName() { - Assert.AreEqual(@"C:\Projects\Setup\bin\myapp.exe", files[1].SourceFullPath); + Assert.AreEqual(@"C:\Projects\Setup\bin\myapp.exe", files[1].GetSourceFullPath()); } /// @@ -65,8 +65,8 @@ namespace WixBinding.Tests.Document public void RelativeFileNameUsed() { doc.FileName = String.Empty; - Assert.AreEqual(@"..\doc\license.rtf", files[0].SourceFullPath); - Assert.AreEqual(@"bin\myapp.exe", files[1].SourceFullPath); + Assert.AreEqual(@"..\doc\license.rtf", files[0].GetSourceFullPath()); + Assert.AreEqual(@"bin\myapp.exe", files[1].GetSourceFullPath()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/DirectoryNameTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/DirectoryNameTests.cs index 6a755b1e31..bd125b8478 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/DirectoryNameTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/DirectoryNameTests.cs @@ -5,11 +5,13 @@ // $Revision$ // +using System; +using System.Resources; + using ICSharpCode.Core; using ICSharpCode.WixBinding; using NUnit.Framework; -using System; -using System.Resources; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.Document { @@ -19,8 +21,7 @@ namespace WixBinding.Tests.Document [TestFixtureSetUp] public void SetupFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GenerateComponentIdFromDirectoryWithDotsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GenerateComponentIdFromDirectoryWithDotsTestFixture.cs index 28e9a9d52c..032f2da77c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GenerateComponentIdFromDirectoryWithDotsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GenerateComponentIdFromDirectoryWithDotsTestFixture.cs @@ -32,7 +32,9 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - id = WixComponentElement.GenerateIdFromFileName(doc, @"C:\Projects\My.Project\MyApp.exe"); + WixComponentElement wixComponent = new WixComponentElement(doc); + wixComponent.GenerateUniqueIdFromFileName(@"C:\Projects\My.Project\MyApp.exe"); + id = wixComponent.Id; } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameFromVariablesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameFromVariablesTestFixture.cs index a18bba3b09..fab3ce16b5 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameFromVariablesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameFromVariablesTestFixture.cs @@ -21,8 +21,8 @@ namespace WixBinding.Tests.Document { WixDocument document; - [TestFixtureSetUp] - public void SetUpFixture() + [SetUp] + public void Init() { WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); project.SetProperty("DefineConstants", @"DATADIR=Bitmaps;"); @@ -39,7 +39,8 @@ namespace WixBinding.Tests.Document string GetWixXml() { - return "\r\n" + + return + "\r\n" + "\t\r\n" + "\t\t\r\n" + diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs index fcc8156952..fc5eb537a6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetBinaryFileNameTestFixture.cs @@ -54,12 +54,11 @@ namespace WixBinding.Tests.Document } [Test] - [ExpectedException(typeof(ArgumentException))] - public void PassingFileLoaderIntoWixDocument() + public void CreatingWixDocumentWithNullFileLoaderThrowsArgumentNullException() { IFileLoader fileLoader = null; WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); - WixDocument doc = new WixDocument(project, fileLoader); + Assert.Throws(delegate { WixDocument doc = new WixDocument(project, fileLoader); }); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs index 60855247f7..e3b6c8a087 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogElementRegionTests.cs @@ -33,7 +33,9 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Dialog", "WelcomeDialog"); + StringReader reader = new StringReader(xml); + WixDocumentReader wixReader = new WixDocumentReader(reader); + DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion expectedRegion = new DomRegion(3, 3, 4, 11); Assert.AreEqual(expectedRegion, region); } @@ -48,7 +50,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Dialog", "WelcomeDialog"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion expectedRegion = new DomRegion(3, 0, 3, 35); Assert.AreEqual(expectedRegion, region); } @@ -63,7 +66,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Dialog", "WelcomeDialog"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion expectedRegion = new DomRegion(3, 0, 3, 27); Assert.AreEqual(expectedRegion, region); } @@ -78,7 +82,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Dialog", "WelcomeDialog"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion expectedRegion = new DomRegion(3, 0, 3, 35); Assert.AreEqual(expectedRegion, region); } @@ -96,7 +101,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Dialog", "WelcomeDialog"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Dialog", "WelcomeDialog"); DomRegion expectedRegion = new DomRegion(5, 3, 6, 11); Assert.AreEqual(expectedRegion, region); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs index 27407911d8..df93b71c41 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDialogIdAtLineTestFixture.cs @@ -23,47 +23,49 @@ namespace WixBinding.Tests.Document { StringReader reader; string expectedDialogId = "WelcomeDialog"; + WixDocumentReader wixReader; [SetUp] public void SetUpFixture() { reader = new StringReader(GetWixXml()); + wixReader = new WixDocumentReader(reader); } [Test] public void OnDialogStartTagLine() { - Assert.AreEqual(expectedDialogId, WixDocument.GetDialogId(reader, 8)); + Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(8)); } [Test] public void StartOfDocument() { - Assert.IsNull(WixDocument.GetDialogId(reader, 0)); + Assert.IsNull(wixReader.GetDialogId(0)); } [Test] public void LineBeforeDialogStartTag() { - Assert.IsNull(WixDocument.GetDialogId(reader, 7)); + Assert.IsNull(wixReader.GetDialogId(7)); } [Test] public void FirstLineAfterDialogStartTag() { - Assert.AreEqual(expectedDialogId, WixDocument.GetDialogId(reader, 9)); + Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(9)); } [Test] public void DialogEndTagLine() { - Assert.AreEqual(expectedDialogId, WixDocument.GetDialogId(reader, 15)); + Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(15)); } [Test] public void FirstLineAfterDialogEndTag() { - Assert.IsNull(WixDocument.GetDialogId(reader, 16)); + Assert.IsNull(wixReader.GetDialogId(16)); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs index 9fb8343f67..5bcb285ee6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetDirectoryElementRegionTests.cs @@ -31,7 +31,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Directory", "TARGETDIR"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion expectedRegion = new DomRegion(2, 2, 3, 13); Assert.AreEqual(expectedRegion, region); } @@ -47,7 +48,8 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Directory", "TARGETDIR"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion expectedRegion = new DomRegion(2, 2, 5, 13); Assert.AreEqual(expectedRegion, region); } @@ -62,10 +64,10 @@ namespace WixBinding.Tests.Document "\t\t\r\n" + "\t\r\n" + ""; - DomRegion region = WixDocument.GetElementRegion(new StringReader(xml), "Directory", "TARGETDIR"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + DomRegion region = wixReader.GetElementRegion("Directory", "TARGETDIR"); DomRegion expectedRegion = new DomRegion(2, 2, 4, 13); Assert.AreEqual(expectedRegion, region); } - } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs index 432115493d..edcc8af4cf 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetEmptyElementDialogIdAtLineTestFixture.cs @@ -23,35 +23,37 @@ namespace WixBinding.Tests.Document { StringReader reader; string expectedDialogId = "WelcomeDialog"; + WixDocumentReader wixReader; [SetUp] public void SetUpFixture() { reader = new StringReader(GetWixXml()); + wixReader = new WixDocumentReader(reader); } [Test] public void OnDialogStartTagLine() { - Assert.AreEqual(expectedDialogId, WixDocument.GetDialogId(reader, 8)); + Assert.AreEqual(expectedDialogId, wixReader.GetDialogId(8)); } [Test] public void StartOfDocument() { - Assert.IsNull(WixDocument.GetDialogId(reader, 0)); + Assert.IsNull(wixReader.GetDialogId(0)); } [Test] public void LineBeforeDialogStartTag() { - Assert.IsNull(WixDocument.GetDialogId(reader, 7)); + Assert.IsNull(wixReader.GetDialogId(7)); } [Test] public void LineAfterDialogStartTag() { - Assert.IsNull(WixDocument.GetDialogId(reader, 9)); + Assert.IsNull(wixReader.GetDialogId(9)); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetMissingDialogFromWixDocumentTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetMissingDialogFromWixDocumentTestFixture.cs index 26652fcc25..8bcfd1174c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetMissingDialogFromWixDocumentTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetMissingDialogFromWixDocumentTestFixture.cs @@ -9,6 +9,7 @@ using ICSharpCode.WixBinding; using NUnit.Framework; using System; using System.Xml; +using WixBinding.Tests.Utils; namespace WixBinding.Tests.Document { @@ -27,7 +28,7 @@ namespace WixBinding.Tests.Document { doc = new WixDocument(); doc.LoadXml(GetWixXml()); - dialog = doc.GetDialog("MissingDialog"); + dialog = doc.CreateWixDialog("MissingDialog", new MockTextFileReader()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs index 86da801d7a..4a6f41af2d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetProductEndElementLocationTests.cs @@ -33,7 +33,8 @@ namespace WixBinding.Tests.Document "\t Id='????????-????-????-????-????????????'>\r\n" + "\t\r\n" + ""; - Location location = WixDocument.GetEndElementLocation(new StringReader(xml), "Product", "????????-????-????-????-????????????"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????"); Location expectedLocation = new Location(1, 6); Assert.AreEqual(expectedLocation, location); } @@ -51,7 +52,8 @@ namespace WixBinding.Tests.Document "\t Manufacturer='#develop' \r\n" + "\t Id='????????-????-????-????-????????????'/>\r\n" + ""; - Location location = WixDocument.GetEndElementLocation(new StringReader(xml), "Product", "????????-????-????-????-????????????"); + WixDocumentReader wixReader = new WixDocumentReader(new StringReader(xml)); + Location location = wixReader.GetEndElementLocation("Product", "????????-????-????-????-????????????"); Location expectedLocation = Location.Empty; Assert.AreEqual(expectedLocation, location); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs index b0ce78c5be..557c2161d7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetTwoDialogIdsFromWixDocumentTestFixture.cs @@ -35,15 +35,18 @@ namespace WixBinding.Tests.Document public void SetUpFixture() { StringReader reader = new StringReader(GetWixXml()); - dialogIds = WixDocument.GetDialogIds(reader); + WixDocumentReader wixReader = new WixDocumentReader(reader); + dialogIds = wixReader.GetDialogIds(); welcomeDialogId = dialogIds[0]; progressDialogId = dialogIds[1]; reader = new StringReader(GetWixXml()); - welcomeDialogLocation = WixDocument.GetStartElementLocation(reader, "Dialog", welcomeDialogId); + wixReader = new WixDocumentReader(reader); + welcomeDialogLocation = wixReader.GetStartElementLocation("Dialog", welcomeDialogId); reader = new StringReader(GetWixXml()); - missingDialogLocation = WixDocument.GetStartElementLocation(reader, "Dialog", "missingDialogId"); + wixReader = new WixDocumentReader(reader); + missingDialogLocation = wixReader.GetStartElementLocation("Dialog", "missingDialogId"); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetValueWithNoProjectTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetValueWithNoProjectTestFixture.cs index 42c9dd4951..87125aefd0 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/GetValueWithNoProjectTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/GetValueWithNoProjectTestFixture.cs @@ -18,7 +18,8 @@ namespace WixBinding.Tests.Document public void NullReturned() { WixDocument doc = new WixDocument(); - Assert.IsNull(doc.GetValue("test")); + IWixPropertyValueProvider provider = (IWixPropertyValueProvider)doc; + Assert.IsNull(provider.GetValue("test")); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/NoProductDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/NoProductDirectoryTestFixture.cs index 9a0598a00c..7eccb1998d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/NoProductDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/NoProductDirectoryTestFixture.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - Assert.IsNull(doc.RootDirectory); + Assert.IsNull(doc.GetRootDirectory()); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/NoRootDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/NoRootDirectoryTestFixture.cs index 9093ccac14..656c2ecedb 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/NoRootDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/NoRootDirectoryTestFixture.cs @@ -24,7 +24,7 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - Assert.IsNull(doc.RootDirectory); + Assert.IsNull(doc.GetRootDirectory()); } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/NonRootDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/NonRootDirectoryTestFixture.cs index a5d41cb82a..bbfabf9058 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/NonRootDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/NonRootDirectoryTestFixture.cs @@ -27,7 +27,7 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - directory = doc.RootDirectory; + directory = doc.GetRootDirectory(); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs index 72ffcb2219..98a0989ea3 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/RegionToOffsetTests.cs @@ -6,7 +6,8 @@ // using ICSharpCode.SharpDevelop.Dom; -using ICSharpCode.TextEditor.Document; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.WixBinding; using NUnit.Framework; using System; @@ -17,14 +18,20 @@ namespace WixBinding.Tests.Document [TestFixture] public class RegionToOffsetTests { + AvalonEditDocumentAdapter document; + + [SetUp] + public void Init() + { + document = new AvalonEditDocumentAdapter(); + } + [Test] - public void SingleLine() + public void SingleLineRegionConvertedToSegment() { DomRegion region = new DomRegion(0, 0, 0, 5); - DocumentFactory factory = new DocumentFactory(); - IDocument document = factory.CreateDocument(); - document.TextContent = "1234567890"; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); + document.Text = "1234567890"; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(0, 6); @@ -32,13 +39,11 @@ namespace WixBinding.Tests.Document } [Test] - public void TwoLines() + public void TwoLineRegionConvertedToSegment() { DomRegion region = new DomRegion(0, 1, 1, 0); - DocumentFactory factory = new DocumentFactory(); - IDocument document = factory.CreateDocument(); - document.TextContent = "1234567890\r\n1234567890"; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); + document.Text = "1234567890\r\n1234567890"; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(1, 12); @@ -46,13 +51,11 @@ namespace WixBinding.Tests.Document } [Test] - public void ThreeLines() + public void ThreeLineRegionConvertedToSegment() { DomRegion region = new DomRegion(0, 2, 2, 1); - DocumentFactory factory = new DocumentFactory(); - IDocument document = factory.CreateDocument(); - document.TextContent = "1234567890\r\n1234567890\r\n1234567890"; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); + document.Text = "1234567890\r\n1234567890\r\n1234567890"; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 24); @@ -60,13 +63,11 @@ namespace WixBinding.Tests.Document } [Test] - public void ThreeLinesWithoutCarriageReturn() + public void ThreeLineRegionWithoutCarriageReturnConvertedToSegment() { DomRegion region = new DomRegion(0, 2, 2, 1); - DocumentFactory factory = new DocumentFactory(); - IDocument document = factory.CreateDocument(); - document.TextContent = "1234567890\n1234567890\n1234567890"; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); + document.Text = "1234567890\n1234567890\n1234567890"; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22); @@ -74,13 +75,11 @@ namespace WixBinding.Tests.Document } [Test] - public void BeginLineOnSecondLine() + public void RegionWithBeginLineOnSecondLineConvertedToSegment() { DomRegion region = new DomRegion(1, 0, 2, 0); - DocumentFactory factory = new DocumentFactory(); - IDocument document = factory.CreateDocument(); - document.TextContent = "1234567890\r\n1234567890\r\n1234567890"; - ISegment segment = WixDocument.ConvertRegionToSegment(document, region); + document.Text = "1234567890\r\n1234567890\r\n1234567890"; + WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(12, 13); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryRefTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryRefTestFixture.cs index bca506a060..e710f900ea 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryRefTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryRefTestFixture.cs @@ -22,7 +22,7 @@ namespace WixBinding.Tests.PackageFiles { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - directoryRef = doc.RootDirectoryRef; + directoryRef = doc.GetRootDirectoryRef(); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryTestFixture.cs index 66f1ecd458..ebc275b858 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/RootDirectoryTestFixture.cs @@ -26,7 +26,7 @@ namespace WixBinding.Tests.Document { WixDocument doc = new WixDocument(); doc.LoadXml(GetWixXml()); - directory = doc.RootDirectory; + directory = doc.GetRootDirectory(); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentLineSegmentEqualsTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentLineSegmentEqualsTests.cs new file mode 100644 index 0000000000..c6c282801b --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentLineSegmentEqualsTests.cs @@ -0,0 +1,48 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; + +namespace WixBinding.Tests.Document +{ + [TestFixture] + public class WixDocumentLineSegmentEqualsTests + { + [Test] + public void SegmentsWithSameOffsetAndLengthAreEqual() + { + WixDocumentLineSegment lhs = new WixDocumentLineSegment(4, 5); + WixDocumentLineSegment rhs = new WixDocumentLineSegment(4, 5); + Assert.IsTrue(lhs.Equals(rhs)); + } + + [Test] + public void SegmentsWithSameOffsetAndDifferentLengthAreNotEqual() + { + WixDocumentLineSegment lhs = new WixDocumentLineSegment(4, 10); + WixDocumentLineSegment rhs = new WixDocumentLineSegment(4, 5); + Assert.IsFalse(lhs.Equals(rhs)); + } + + [Test] + public void SegmentsWithSameLengthAndDifferentOffsetAreNotEqual() + { + WixDocumentLineSegment lhs = new WixDocumentLineSegment(3, 5); + WixDocumentLineSegment rhs = new WixDocumentLineSegment(4, 5); + Assert.IsFalse(lhs.Equals(rhs)); + } + + [Test] + public void NullSegmentIsNotEqualToSegment() + { + WixDocumentLineSegment lhs = new WixDocumentLineSegment(1, 4); + Assert.IsFalse(lhs.Equals(null)); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentSaveTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentSaveTests.cs new file mode 100644 index 0000000000..3f684a761c --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentSaveTests.cs @@ -0,0 +1,101 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using System.Xml; + +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Document +{ + [TestFixture] + public class WixDocumentSaveTests + { + WixDocument document; + StringBuilder xmlBuilder; + XmlWriter xmlWriter; + + [SetUp] + public void Init() + { + WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); + document = new WixDocument(project, new DefaultFileLoader()); + string xml = ""; + document.LoadXml(xml); + + MockTextEditorOptions options = new MockTextEditorOptions(); + options.ConvertTabsToSpaces = false; + options.IndentationSize = 1; + + WixTextWriter wixWriter = new WixTextWriter(options); + xmlBuilder = new StringBuilder(); + xmlWriter = wixWriter.Create(new StringWriter(xmlBuilder)); + document.Save(xmlWriter); + } + + [Test] + public void WixDocumentSaveCreatesExpectedXml() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, xmlBuilder.ToString()); + } + + [Test] + public void XmlWriterSettingsIndentIsTrue() + { + Assert.IsTrue(xmlWriter.Settings.Indent); + } + + [Test] + public void XmlWriterSettingsCloseOutputIsTrue() + { + Assert.IsTrue(xmlWriter.Settings.CloseOutput); + } + + [Test] + public void XmlWriterSettingsOmitXmlDeclarationIsTrue() + { + Assert.IsTrue(xmlWriter.Settings.OmitXmlDeclaration); + } + + [Test] + public void XmlWriterSettingsNewLineCharsAreCarriageReturnAndLineFeed() + { + Assert.AreEqual("\r\n", xmlWriter.Settings.NewLineChars); + } + + [Test] + public void XmlWriterSettingsIndentCharsIsTab() + { + Assert.AreEqual("\t", xmlWriter.Settings.IndentChars); + } + + [Test] + public void XmlWriterSettingsIndentCharsIsTabTakenFromSaveMethod() + { + int indentLength = 3; + string indent = " ".PadRight(indentLength); + + MockTextEditorOptions options = new MockTextEditorOptions(); + options.ConvertTabsToSpaces = true; + options.IndentationSize = indentLength; + + WixTextWriter wixWriter = new WixTextWriter(options); + xmlWriter = wixWriter.Create(new StringWriter(new StringBuilder())); + + Assert.AreEqual(indent, xmlWriter.Settings.IndentChars); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentWithNamespacePrefixTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentWithNamespacePrefixTestFixture.cs index 677e5a4c82..d3185968de 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentWithNamespacePrefixTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixDocumentWithNamespacePrefixTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.Document public void SetUpFixture() { doc = new WixDocument(); - prefixBeforeLoad = doc.WixNamespacePrefix; + prefixBeforeLoad = doc.GetWixNamespacePrefix(); doc.LoadXml(GetWixXml()); directory = doc.CreateWixElement("Directory"); directory.OwnerDocument.DocumentElement.AppendChild(directory); @@ -61,7 +61,7 @@ namespace WixBinding.Tests.Document [Test] public void WixNamespacePrefix() { - Assert.AreEqual("w", doc.WixNamespacePrefix); + Assert.AreEqual("w", doc.GetWixNamespacePrefix()); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixFileExtensionTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixFileExtensionTests.cs index 51bfa55a80..4701c1dc40 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Document/WixFileExtensionTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/WixFileExtensionTests.cs @@ -12,38 +12,58 @@ using System; namespace WixBinding.Tests.Document { /// - /// Tests that the WixDocument.IsWixFileName method correctly detects + /// Tests that the WixFileName.IsWixFileName method correctly detects /// Wix document file extensions. /// [TestFixture] public class WixFileExtensionTests { [Test] - public void WxsFile() + public void IsWixFileNameReturnsTrueIfFileHasWxsFileExtension() { - Assert.IsTrue(WixDocument.IsWixFileName("foo.wxs")); - Assert.IsTrue(WixDocument.IsWixSourceFileName("foo.wxs")); + Assert.IsTrue(WixFileName.IsWixFileName("foo.wxs")); } [Test] - public void WxsFileUppercase() + public void IsWixSourceFileNameReturnsTrueIfFileHasWxsFileExtension() { - Assert.IsTrue(WixDocument.IsWixFileName(@"src\FOO.WXS")); - Assert.IsTrue(WixDocument.IsWixSourceFileName(@"src\FOO.WXS")); + Assert.IsTrue(WixFileName.IsWixSourceFileName("foo.wxs")); } [Test] - public void WxiFile() + public void IsWixSFileNameReturnsTrueIfWxsFileExtensionIsUppercase() { - Assert.IsTrue(WixDocument.IsWixFileName("foo.wxi")); - Assert.IsFalse(WixDocument.IsWixSourceFileName("foo.wxi")); + Assert.IsTrue(WixFileName.IsWixFileName(@"src\FOO.WXS")); } [Test] - public void NullFileName() + public void IsWixSourceFileNameReturnsTrueIfWxsFileExtensionIsUppercase() { - Assert.IsFalse(WixDocument.IsWixFileName(null)); - Assert.IsFalse(WixDocument.IsWixSourceFileName(null)); + Assert.IsTrue(WixFileName.IsWixSourceFileName(@"src\FOO.WXS")); + } + + [Test] + public void IsWixFileNameReturnsTrueIfFileHasWxiFileExtension() + { + Assert.IsTrue(WixFileName.IsWixFileName("foo.wxi")); + } + + [Test] + public void IsWixFileNameReturnsFalseIfFileHasWxiFileExtension() + { + Assert.IsFalse(WixFileName.IsWixSourceFileName("foo.wxi")); + } + + [Test] + public void IsWixFileNameReturnsFalseIfFileNameIsNull() + { + Assert.IsFalse(WixFileName.IsWixFileName(null)); + } + + [Test] + public void IsWixSourceFileNameReturnsFalseIfFileNameIsNull() + { + Assert.IsFalse(WixFileName.IsWixSourceFileName(null)); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/AddWixProjectNodeTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/AddWixProjectNodeTestFixture.cs index 18da7a54d3..9445a91330 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/AddWixProjectNodeTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/AddWixProjectNodeTestFixture.cs @@ -34,8 +34,7 @@ namespace WixBinding.Tests.Gui [TestFixtureSetUp] public void SetUpFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); wixProject = WixBindingTestsHelper.CreateEmptyWixProject(); parentNode = new TreeNode(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/CanAttachToFileNameTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/CanAttachToFileNameTests.cs index 06ccc9d4f1..4ebcc1caeb 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/CanAttachToFileNameTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/CanAttachToFileNameTests.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.Gui public void WixFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetName("Setup.wxs"); + view.SetFileName("Setup.wxs"); Assert.IsTrue(binding.CanAttachTo(view)); } @@ -40,7 +40,7 @@ namespace WixBinding.Tests.Gui public void WixIncludeFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetName("Setup.wxi"); + view.SetFileName("Setup.wxi"); Assert.IsTrue(binding.CanAttachTo(view)); } @@ -48,7 +48,7 @@ namespace WixBinding.Tests.Gui public void WixFileNameUppercase() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetName("SETUP.WXS"); + view.SetFileName("SETUP.WXS"); Assert.IsTrue(binding.CanAttachTo(view)); } @@ -56,7 +56,7 @@ namespace WixBinding.Tests.Gui public void NonWixFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetName("Setup.txt"); + view.SetFileName("Setup.txt"); Assert.IsFalse(binding.CanAttachTo(view)); } @@ -64,7 +64,7 @@ namespace WixBinding.Tests.Gui public void NonTextEditorProviderView() { MockViewContent view = new MockViewContent(); - view.SetName("Setup.wxs"); + view.SetFileName("Setup.wxs"); Assert.IsFalse(binding.CanAttachTo(view)); } @@ -72,7 +72,7 @@ namespace WixBinding.Tests.Gui public void UntitledWixFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetUntitledName("Setup.wxs"); + view.SetUntitledFileName("Setup.wxs"); Assert.IsTrue(binding.CanAttachTo(view)); } @@ -80,7 +80,7 @@ namespace WixBinding.Tests.Gui public void UntitledNonWixFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetUntitledName("Setup.txt"); + view.SetUntitledFileName("Setup.txt"); Assert.IsFalse(binding.CanAttachTo(view)); } @@ -88,7 +88,7 @@ namespace WixBinding.Tests.Gui public void NullUntitledFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetUntitledName(null); + view.SetUntitledFileName(null); Assert.IsFalse(binding.CanAttachTo(view)); } @@ -96,7 +96,7 @@ namespace WixBinding.Tests.Gui public void NullFileName() { MockTextEditorViewContent view = new MockTextEditorViewContent(); - view.SetName(null); + view.SetFileName(null); Assert.IsFalse(binding.CanAttachTo(view)); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/DialogDesignerGetSourceFilesTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/DialogDesignerGetSourceFilesTests.cs new file mode 100644 index 0000000000..8cd2a077ec --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/DialogDesignerGetSourceFilesTests.cs @@ -0,0 +1,61 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.FormsDesigner; +using ICSharpCode.SharpDevelop; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class DialogDesignerGetSourceFilesTests + { + WixDialogDesignerGenerator dialogDesigner; + OpenedFile designerOpenedFile; + List files; + MockTextEditorViewContent primaryView; + + [SetUp] + public void Init() + { + primaryView = new MockTextEditorViewContent(); + primaryView.SetFileName(@"d:\projects\test\dialog.wxs"); + + dialogDesigner = new WixDialogDesignerGenerator(); + MockOpenedFile openedFile = new MockOpenedFile("dialog.designer.wxs", false); + dialogDesigner.Attach(new FormsDesignerViewContent(primaryView, openedFile)); + + files = new List(); + IEnumerable sourceFiles = dialogDesigner.GetSourceFiles(out designerOpenedFile); + if (sourceFiles != null) { + files.AddRange(sourceFiles); + } + } + + [Test] + public void DesignerOpenFileIsFormsDesignerViewPrimaryFile() + { + Assert.AreSame(primaryView.PrimaryFile, designerOpenedFile); + } + + [Test] + public void OneSourceFileReturnedFromGetSourceFiles() + { + Assert.AreEqual(1, files.Count); + } + + [Test] + public void GetSourceFilesContainsFormsDesignerPrimaryFile() + { + Assert.AreSame(primaryView.PrimaryFile, files[0]); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/FlushLoaderTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/FlushLoaderTestFixture.cs index 35e4338809..542479dc5e 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/FlushLoaderTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/FlushLoaderTestFixture.cs @@ -72,9 +72,7 @@ namespace WixBinding.Tests.Gui } string IWixDialogDesigner.DialogId { - get { - return "WelcomeDialog"; - } + get { return "WelcomeDialog"; } } string IWixDialogDesigner.GetDocumentXml() @@ -83,20 +81,17 @@ namespace WixBinding.Tests.Gui } public string DocumentFileName { - get { - return String.Empty; - } + get { return String.Empty; } } public WixProject Project { - get { - return WixBindingTestsHelper.CreateEmptyWixProject(); - } + get { return WixBindingTestsHelper.CreateEmptyWixProject(); } } string GetWixXml() { - return "\r\n" + + return + "\r\n" + "\t\r\n" + "\t\t\r\n" + "\t\t\t\r\n" + diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/GetWixDesignerFromViewTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/GetWixDesignerFromViewTests.cs index 520d4b7fb5..d6798319b3 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/GetWixDesignerFromViewTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/GetWixDesignerFromViewTests.cs @@ -22,7 +22,7 @@ namespace WixBinding.Tests.Gui [Test] public void WixDesignerAttached() { - MockViewContent view = new MockViewContent(); + MockTextEditorViewContent view = new MockTextEditorViewContent(); using (WixDialogDesigner designerAdded = new WixDialogDesigner(view)) { view.SecondaryViewContents.Add(designerAdded); Assert.IsNotNull(WixDialogDesigner.GetDesigner(view)); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/LoaderProviderTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/LoaderProviderTests.cs index b832dabad0..b664f8a63d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/LoaderProviderTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/LoaderProviderTests.cs @@ -42,21 +42,15 @@ namespace WixBinding.Tests.Gui } string IWixDialogDesigner.DialogId { - get { - return "WelcomeDialog"; - } + get { return "WelcomeDialog"; } } string IWixDialogDesigner.DocumentFileName { - get { - return String.Empty; - } + get { return String.Empty; } } WixProject IWixDialogDesigner.Project { - get { - return WixBindingTestsHelper.CreateEmptyWixProject(); - } + get { return WixBindingTestsHelper.CreateEmptyWixProject(); } } string IWixDialogDesigner.GetDocumentXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/MissingDialogIdDesignerLoaderTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/MissingDialogIdDesignerLoaderTestFixture.cs index 5f2470ae1e..d08ab408d6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/MissingDialogIdDesignerLoaderTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/MissingDialogIdDesignerLoaderTestFixture.cs @@ -28,9 +28,9 @@ namespace WixBinding.Tests.Gui [TestFixtureSetUp] public void SetupFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); } + [Test] [ExpectedException(typeof(FormsDesignerLoadException), ExpectedMessage = "Unable to find dialog with an id of 'MissingDialog'.")] public void LoadMissingDialog() @@ -41,9 +41,7 @@ namespace WixBinding.Tests.Gui } string IWixDialogDesigner.DialogId { - get { - return "MissingDialog"; - } + get { return "MissingDialog"; } } string IWixDialogDesigner.GetDocumentXml() @@ -52,15 +50,11 @@ namespace WixBinding.Tests.Gui } public string DocumentFileName { - get { - return String.Empty; - } + get { return String.Empty; } } public WixProject Project { - get { - return WixBindingTestsHelper.CreateEmptyWixProject(); - } + get { return WixBindingTestsHelper.CreateEmptyWixProject(); } } string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/NoDialogIdSpecifiedForDesignerLoaderTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/NoDialogIdSpecifiedForDesignerLoaderTestFixture.cs index ff7ae45eed..257695afd4 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/NoDialogIdSpecifiedForDesignerLoaderTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/NoDialogIdSpecifiedForDesignerLoaderTestFixture.cs @@ -25,8 +25,7 @@ namespace WixBinding.Tests.Gui [TestFixtureSetUp] public void SetupFixture() { - ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", GetType().Assembly); - ResourceService.RegisterNeutralStrings(rm); + WixBindingTestsHelper.RegisterResourceStringsWithSharpDevelopResourceManager(); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowExistingPackageFilesViewTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowExistingPackageFilesViewTestFixture.cs new file mode 100644 index 0000000000..cb9f503fcf --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowExistingPackageFilesViewTestFixture.cs @@ -0,0 +1,73 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class ShowExistingPackageFilesViewTestFixture + { + MockWorkbench workbench; + MockPackageFilesViewFactory factory; + WixProject project; + PackageFilesView existingView; + MockWixPackageFilesControl packageFilesControl; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + + CreatePackageFilesViewWithDifferentWixProject(); + CreatePackageFilesViewWithProjectToBeUsedWithViewSetupFilesCommandRunMethod(); + + factory = new MockPackageFilesViewFactory(); + ViewSetupFilesCommand viewCommand = new ViewSetupFilesCommand(factory, workbench); + viewCommand.Run(project); + } + + void CreatePackageFilesViewWithDifferentWixProject() + { + WixProject differentProject = WixBindingTestsHelper.CreateEmptyWixProject(); + PackageFilesView viewWithDifferentProject = new PackageFilesView(differentProject, workbench, new MockWixPackageFilesControl()); + + workbench.ShowView(viewWithDifferentProject); + + CreateWorkbenchWindowForPackageFilesView(viewWithDifferentProject); + } + + void CreatePackageFilesViewWithProjectToBeUsedWithViewSetupFilesCommandRunMethod() + { + project = WixBindingTestsHelper.CreateEmptyWixProject(); + packageFilesControl = new MockWixPackageFilesControl(); + existingView = new PackageFilesView(project, workbench, packageFilesControl); + + workbench.ShowView(existingView); + + CreateWorkbenchWindowForPackageFilesView(existingView); + } + + void CreateWorkbenchWindowForPackageFilesView(PackageFilesView view) + { + MockWorkbenchWindow window = new MockWorkbenchWindow(); + IViewContent viewContent = (IViewContent)view; + viewContent.WorkbenchWindow = window; + } + + [Test] + public void ExistingPackageFilesViewWorkbenchWindowIsSelected() + { + MockWorkbenchWindow window = existingView.WorkbenchWindow as MockWorkbenchWindow; + Assert.IsTrue(window.SelectWindowMethodCalled); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowSetupFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowSetupFilesTestFixture.cs new file mode 100644 index 0000000000..31d306c95e --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/ShowSetupFilesTestFixture.cs @@ -0,0 +1,57 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class ShowSetupFilesTestFixture + { + MockWorkbench workbench; + MockPackageFilesViewFactory factory; + WixProject project; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + factory = new MockPackageFilesViewFactory(); + project = WixBindingTestsHelper.CreateEmptyWixProject(); + + ViewSetupFilesCommand viewCommand = new ViewSetupFilesCommand(factory, workbench); + viewCommand.Run(project); + } + + [Test] + public void NewPackageFilesViewObjectCreated() + { + Assert.IsNotNull(factory.PackageFilesViewCreated); + } + + [Test] + public void WorkbenchPassedToPackageFilesViewFactory() + { + Assert.AreSame(workbench, factory.CreateMethodWorkbenchParameter); + } + + [Test] + public void PackageFilesViewShowFilesMethodCalled() + { + Assert.AreSame(project, factory.PackageFilesControlCreated.ShowFilesMethodProjectParameter); + } + + [Test] + public void PackageFilesViewDisplayedInWorkbench() + { + Assert.IsTrue(workbench.ViewContentCollection.Contains(factory.PackageFilesViewCreated)); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs new file mode 100644 index 0000000000..4615eb7534 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs @@ -0,0 +1,106 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class WixDocumentEditorInsertTextTestFixture + { + IDocument document; + MockTextEditor textEditor; + string originalXml; + + [SetUp] + public void Init() + { + originalXml = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + textEditor = new MockTextEditor(); + textEditor.OptionsConvertTabsToSpaces = false; + textEditor.OptionsIndentationSize = 4; + textEditor.OptionsIndentationString = "\t"; + + textEditor.Document.Text = originalXml; + + // Insert new xml as child element of . + // Insert position is just before the start of end element. + WixDocumentEditor editor = new WixDocumentEditor(textEditor); + + string xmlToInsert = + "\r\n" + + "\r\n"; + + int line = 2; + int column = 1; + editor.InsertIndented(line, column, xmlToInsert); + + document = textEditor.Document; + } + + [Test] + public void ExpectedDocumentXmlAfterInsert() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, document.Text, document.Text); + } + + [Test] + public void LocationJumpedToAfterInsert() + { + int column = 1; + int line = 3; + Location expectedLocation = new Location(column, line); + Assert.AreEqual(expectedLocation, textEditor.LocationJumpedTo); + } + + [Test] + public void TextInsertedIsSelected() + { + string expectedText = + "\t\r\n" + + "\t\t\r\n" + + "\t"; + + Assert.AreEqual(expectedText, textEditor.SelectedText); + } + + [Test] + public void CursorAtEndOfSelectedText() + { + int col = 2; + int line = 5; + Location expectedLocation = new Location(col, line); + Assert.AreEqual(expectedLocation, textEditor.Caret.Position); + } + + [Test] + public void InsertCanBeUndoneInOneStep() + { + textEditor.Undo(); + + Assert.AreEqual(originalXml, document.Text, document.Text); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture.cs new file mode 100644 index 0000000000..150295ae16 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture.cs @@ -0,0 +1,80 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class WixDocumentEditorInsertUsesTextEditorPropertiesTestFixture + { + IDocument document; + MockTextEditor textEditor; + string originalXml; + + [SetUp] + public void Init() + { + originalXml = + "\r\n" + + " \r\n" + + " \r\n" + + ""; + + textEditor = new MockTextEditor(); + textEditor.OptionsConvertTabsToSpaces = true; + textEditor.OptionsIndentationSize = 4; + textEditor.OptionsIndentationString = " "; + + textEditor.Document.Text = originalXml; + + // Insert new xml as child element of . + // Insert position is just before the start of end element. + WixDocumentEditor editor = new WixDocumentEditor(textEditor); + + string xmlToInsert = + "\r\n" + + "\r\n"; + + int line = 2; + int column = 4; + editor.InsertIndented(line, column, xmlToInsert); + + document = textEditor.Document; + } + + [Test] + public void ExpectedDocumentXmlAfterInsert() + { + string expectedXml = + "\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + ""; + + Assert.AreEqual(expectedXml, document.Text, document.Text); + } + + [Test] + public void TextInsertedIsSelected() + { + string expectedText = + " \r\n" + + " \r\n" + + " "; + + Assert.AreEqual(expectedText, textEditor.SelectedText); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceElementTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceElementTestFixture.cs new file mode 100644 index 0000000000..dbecf594a5 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceElementTestFixture.cs @@ -0,0 +1,85 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class WixDocumentEditorReplaceElementTestFixture + { + MockTextEditor textEditor; + DomRegion replacementRegion; + WixDocumentEditor wixDocumentEditor; + + [SetUp] + public void Init() + { + textEditor = new MockTextEditor(); + textEditor.Document.Text = GetWixXml(); + + string replacementXml = + "\r\n" + + ""; + + wixDocumentEditor = new WixDocumentEditor(textEditor); + replacementRegion = wixDocumentEditor.ReplaceElement("TARGETDIR", "Directory", replacementXml); + } + + string GetWixXml() + { + return + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\r\n" + + ""; + } + + [Test] + public void XmlIsUpdatedInTextEditor() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, textEditor.Document.Text); + } + + [Test] + public void ReplacementRegionIsNotEmpty() + { + Assert.IsFalse(replacementRegion.IsEmpty); + } + + [Test] + public void ReplacingUnknownElementReturnsEmptyRegion() + { + DomRegion region = wixDocumentEditor.ReplaceElement("TARGETDIR", "unknown-element", ""); + Assert.IsTrue(region.IsEmpty); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs new file mode 100644 index 0000000000..d9a937398d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs @@ -0,0 +1,124 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class WixDocumentEditorReplaceTextTestFixture + { + IDocument document; + MockTextEditor textEditor; + string originalXml; + string initialDocumentRegionText; + + [SetUp] + public void Init() + { + originalXml = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + textEditor = new MockTextEditor(); + textEditor.OptionsConvertTabsToSpaces = false; + textEditor.OptionsIndentationSize = 4; + textEditor.OptionsIndentationString = "\t"; + + document = textEditor.Document; + + textEditor.Document.Text = originalXml; + + // Replace the element + WixDocumentEditor editor = new WixDocumentEditor(textEditor); + + string xmlToInsert = + "\r\n" + + ""; + + int line = 1; + int column = 1; + int endLine = 2; + + // End column is the column containing the '>' of the element. + int endColumn = 8; + + DomRegion region = new DomRegion(line, column, endLine, endColumn); + + WixDocumentLineSegment lineSegment = WixDocumentLineSegment.ConvertRegionToSegment(textEditor.Document, region); + initialDocumentRegionText = textEditor.Document.GetText(lineSegment.Offset, lineSegment.Length); + + editor.Replace(region, xmlToInsert); + } + + [Test] + public void ExpectedDocumentXmlAfterReplace() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, document.Text, document.Text); + } + + [Test] + public void LocationJumpedToAfterInsert() + { + int column = 1; + int line = 2; + Location expectedLocation = new Location(column, line); + Assert.AreEqual(expectedLocation, textEditor.LocationJumpedTo); + } + + [Test] + public void TextInsertedIsSelected() + { + string expectedText = + "\r\n" + + "\t"; + + Assert.AreEqual(expectedText, textEditor.SelectedText); + } + + [Test] + public void CursorAtEndOfSelectedText() + { + int col = 14; + int line = 3; + Location expectedLocation = new Location(col, line); + Assert.AreEqual(expectedLocation, textEditor.Caret.Position); + } + + [Test] + public void InsertCanBeUndoneInOneStep() + { + textEditor.Undo(); + + Assert.AreEqual(originalXml, document.Text, document.Text); + } + + [Test] + public void InitialDocumentTextRegionCoversInnerChildXmlElement() + { + string expectedText = + "\r\n" + + "\t"; + + Assert.AreEqual(expectedText, initialDocumentRegionText); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentWindowIsActiveTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentWindowIsActiveTests.cs new file mode 100644 index 0000000000..bd04c01d13 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentWindowIsActiveTests.cs @@ -0,0 +1,56 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Gui +{ + [TestFixture] + public class WixDocumentWindowIsActiveTests + { + WixDocumentWindow window; + MockWorkbench workbench; + WixDocument document; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + window = new WixDocumentWindow(workbench); + + document = new WixDocument(); + document.FileName = @"d:\Projects\Test\Files.wxs"; + + MockViewContent view = new MockViewContent(); + view.SetFileName(@"d:\projects\test\files.wxs"); + workbench.ActiveViewContent = view; + } + + [Test] + public void WixDocumentWindowIsActiveReturnsTrue() + { + Assert.IsTrue(window.IsActive(document)); + } + + [Test] + public void WixDocumentWindowIsActiveReturnsFalseWhenWorkbenchViewContentIsNull() + { + workbench.ActiveViewContent = null; + Assert.IsFalse(window.IsActive(document)); + } + + [Test] + public void WixDocumentWindowIsActiveReturnsFalseWhenWixDocumentParameterUsedIsNull() + { + Assert.IsFalse(window.IsActive(null)); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActivePackageFilesViewTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActivePackageFilesViewTests.cs new file mode 100644 index 0000000000..0149f00f04 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActivePackageFilesViewTests.cs @@ -0,0 +1,45 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class ActivePackageFilesViewTests + { + ActivePackageFilesView activePackageFilesView; + MockWorkbench workbench; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + activePackageFilesView = new ActivePackageFilesView(workbench); + } + + [Test] + public void GetActiveViewReturnsNullWhenActiveContentIsNotPackageFilesView() + { + workbench.ActiveContent = new MockViewContent(); + Assert.IsNull(activePackageFilesView.GetActiveView()); + } + + [Test] + public void GetActiveViewReturnsPackageFilesViewWhenActiveContentIsPackageFilesView() + { + WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); + using (PackageFilesView packageFilesView = new PackageFilesView(project, workbench)) { + workbench.ActiveContent = packageFilesView; + Assert.AreSame(packageFilesView, activePackageFilesView.GetActiveView()); + } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesAreModifiedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesAreModifiedTestFixture.cs new file mode 100644 index 0000000000..38da74e2eb --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesAreModifiedTestFixture.cs @@ -0,0 +1,90 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class ActiveViewChangedWhenPackageFilesAreModifiedTestFixture : ActiveViewChangedWhenPackageFilesOpenTestFixtureBase + { + MockTextEditor textEditor; + + protected override void AfterInit() + { + document.LoadXml(GetWixXml()); + + textEditor = new MockTextEditor(); + textEditor.Document.Text = GetWixXml(); + viewWithOpenWixDocument.TextEditor = textEditor; + + AddNewChildElementsToDirectory(); + packageFilesControl.IsDirty = true; + + // User switches to text editor with WiX document that we are currently showing + // in the PackageFilesView. + workbench.ActiveViewContent = viewWithOpenWixDocument; + workbench.RaiseActiveViewContentChangedEvent(); + } + + string GetWixXml() + { + return + "\r\n" + + "\t \r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + + void AddNewChildElementsToDirectory() + { + WixDirectoryRefElement dirRef = document.GetRootDirectoryRef(); + WixDirectoryElement programFilesDir = dirRef.FirstChild as WixDirectoryElement; + + WixDirectoryElement sharpDevelopDir = programFilesDir.AddDirectory("SharpDevelop"); + sharpDevelopDir.Id = "SharpDevelopFolder"; + + WixComponentElement component = sharpDevelopDir.AddComponent("SharpDevelopExe"); + component.Guid = "guid"; + WixFileElement file = component.AddFile("SharpDevelop.exe"); + file.Source = @"..\..\bin\SharpDevelop.exe"; + } + + [Test] + public void GetExpectedWixXml() + { + string expectedXml = + "\r\n" + + "\t \r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, textEditor.Document.Text, textEditor.Document.Text); + } + + [Test] + public void PackageFilesViewIsNotDirtyAfterSwitchingToWixDocumentOpenInTextEditor() + { + Assert.IsFalse(packageFilesView.IsDirty); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesOpenTestFixtureBase.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesOpenTestFixtureBase.cs new file mode 100644 index 0000000000..2d48d155ee --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesOpenTestFixtureBase.cs @@ -0,0 +1,54 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + public abstract class ActiveViewChangedWhenPackageFilesOpenTestFixtureBase + { + protected MockWorkbench workbench; + protected MockWixPackageFilesControl packageFilesControl; + protected PackageFilesView packageFilesView; + protected WixDocument document; + protected WixProject project; + protected MockTextEditorViewContent viewWithOpenWixDocument; + + [SetUp] + public void Init() + { + viewWithOpenWixDocument = new MockTextEditorViewContent(); + viewWithOpenWixDocument.SetFileName(@"d:\projects\test\a.wxs"); + + workbench = new MockWorkbench(); + workbench.ViewContentCollection.Add(viewWithOpenWixDocument); + + document = new WixDocument(); + document.FileName = @"d:\projects\test\a.wxs"; + + packageFilesControl = new MockWixPackageFilesControl(); + packageFilesControl.Document = document; + + project = WixBindingTestsHelper.CreateEmptyWixProject(); + packageFilesView = new PackageFilesView(project, workbench, packageFilesControl); + + AfterInit(); + } + + protected abstract void AfterInit(); + + [TearDown] + public void TearDown() + { + packageFilesView.Dispose(); + } + + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesViewOpenTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesViewOpenTestFixture.cs new file mode 100644 index 0000000000..065ad09e01 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ActiveViewChangedWhenPackageFilesViewOpenTestFixture.cs @@ -0,0 +1,58 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class ActiveViewChangedWhenPackageFilesViewOpenTestFixture : ActiveViewChangedWhenPackageFilesOpenTestFixtureBase + { + protected override void AfterInit() + { + // User switches to text editor with WiX document that we are currently showing + // in the PackageFilesView. + workbench.ActiveViewContent = viewWithOpenWixDocument; + workbench.RaiseActiveViewContentChangedEvent(); + } + + [Test] + public void CheckThatWixDocumentWindowIsActiveReturnsTrueForWixDocumentUsedWhenSettingUpTest() + { + WixDocumentWindow window = new WixDocumentWindow(workbench); + Assert.IsTrue(window.IsActive(document)); + } + + [Test] + public void PackageFilesControlShowFilesMethodCalledWhenUserSwitchesBackToPackageFilesViewWindow() + { + workbench.ActiveViewContent = packageFilesView; + workbench.RaiseActiveViewContentChangedEvent(); + + Assert.AreEqual(project, packageFilesControl.ShowFilesMethodProjectParameter); + } + + [Test] + public void PackageFilesControlsShowFilesNotInitiallyCalled() + { + Assert.IsNull(packageFilesControl.ShowFilesMethodProjectParameter); + } + + [Test] + public void PackageFilesControlShowFilesMethodIsNotCalledAfterPackageFilesViewIsDisposed() + { + workbench.ActiveViewContent = packageFilesView; + packageFilesView.Dispose(); + workbench.RaiseActiveViewContentChangedEvent(); + + Assert.IsNull(packageFilesControl.ShowFilesMethodProjectParameter); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddComponentTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddComponentTestFixture.cs index 830e2a3bfb..b5aa6b7676 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddComponentTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddComponentTestFixture.cs @@ -27,7 +27,7 @@ namespace WixBinding.Tests.PackageFiles public void SetUpFixture() { base.InitFixture(); - XmlElement programFilesElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0]; + XmlElement programFilesElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0]; XmlElement installDirElement = (XmlElement)programFilesElement.ChildNodes[0]; view.SelectedElement = installDirElement; editor.AddElement("Component"); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs index ce25817e57..b1dbd32a01 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs @@ -32,14 +32,14 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); editor.AddElement("Directory"); - directoryElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0]; + directoryElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0]; firstSelectedElement = view.SelectedElement; editor.AddElement("Directory"); childDirectoryElement = (XmlElement)directoryElement.ChildNodes[0]; secondSelectedElement = view.SelectedElement; view.SelectedElement = null; editor.AddElement("Directory"); - secondDirectoryElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[1]; + secondDirectoryElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[1]; } [Test] @@ -91,13 +91,13 @@ namespace WixBinding.Tests.PackageFiles [Test] public void RootDirectoryId() { - Assert.AreEqual("TARGETDIR", editor.Document.RootDirectory.GetAttribute("Id")); + Assert.AreEqual("TARGETDIR", editor.Document.GetRootDirectory().GetAttribute("Id")); } [Test] public void RootDirectorySourceName() { - Assert.AreEqual("SourceDir", editor.Document.RootDirectory.GetAttribute("SourceName")); + Assert.AreEqual("SourceDir", editor.Document.GetRootDirectory().GetAttribute("SourceName")); } [Test] diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryToDirectoryRefTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryToDirectoryRefTestFixture.cs index 329a59883d..90c269caa9 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryToDirectoryRefTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryToDirectoryRefTestFixture.cs @@ -30,7 +30,7 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); editor.AddElement("Directory"); - directoryElement = (XmlElement)editor.Document.RootDirectoryRef.ChildNodes[0]; + directoryElement = (XmlElement)editor.Document.GetRootDirectoryRef().ChildNodes[0]; firstSelectedElement = view.SelectedElement; editor.AddElement("Directory"); childDirectoryElement = (XmlElement)directoryElement.ChildNodes[0]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs index 19898fe2d4..0d70c29333 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs @@ -33,7 +33,7 @@ namespace WixBinding.Tests.PackageFiles public void Init() { base.InitFixture(); - componentElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0].ChildNodes[0]; + componentElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0].ChildNodes[0].ChildNodes[0]; view.SelectedElement = componentElement; editor.SelectedElementChanged(); exeFileName = Path.Combine(project.Directory, @"bin\TestApplication.exe"); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs index 65d9e16cd0..920df1ba18 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesToDirectoryTestFixture.cs @@ -35,7 +35,7 @@ namespace WixBinding.Tests.PackageFiles public void Init() { base.InitFixture(); - installDirElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0]; + installDirElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0].ChildNodes[0]; view.SelectedElement = installDirElement; editor.SelectedElementChanged(); exeFileName = Path.Combine(project.Directory, @"bin\TestApplication.exe"); @@ -97,14 +97,16 @@ namespace WixBinding.Tests.PackageFiles [Test] public void ExeFileComponentId() { - string expectedId = WixComponentElement.GenerateIdFromFileName("TestApplication.exe"); + WixComponentElement component = new WixComponentElement(new WixDocument()); + string expectedId = component.GenerateIdFromFileName("TestApplication.exe"); Assert.AreEqual(expectedId, exeFileComponentElement.GetAttribute("Id")); } [Test] public void ReadmeFileComponentId() { - string expectedId = WixComponentElement.GenerateIdFromFileName("readme.rtf"); + WixComponentElement component = new WixComponentElement(new WixDocument()); + string expectedId = component.GenerateIdFromFileName("readme.rtf"); Assert.AreEqual(expectedId, readmeFileComponentElement.GetAttribute("Id")); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddNewRootDirectoryWithFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddNewRootDirectoryWithFilesTestFixture.cs new file mode 100644 index 0000000000..c34154dcde --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddNewRootDirectoryWithFilesTestFixture.cs @@ -0,0 +1,80 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class AddNewRootDirectoryWithFilesTestFixture : UpdateRootDirectoryWithNewFilesTestFixtureBase + { + protected override string GetWixXml() + { + return + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + + protected override void AddNewChildElementsToDirectory() + { + WixDirectoryElement dir = document.AddRootDirectory(); + WixDirectoryElement programFilesDir = dir.AddDirectory("ProgramFilesFolder"); + programFilesDir.SourceName = "PFiles"; + programFilesDir.RemoveAttribute("Name"); + + WixDirectoryElement sharpDevelopDir = programFilesDir.AddDirectory("SharpDevelop"); + sharpDevelopDir.Id = "SharpDevelopFolder"; + + WixComponentElement component = sharpDevelopDir.AddComponent("SharpDevelopExe"); + component.Guid = "guid"; + WixFileElement file = component.AddFile("SharpDevelop.exe"); + file.Source = @"..\..\bin\SharpDevelop.exe"; + } + + [Test] + public void GetExpectedWixXml() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, textEditor.Document.Text, textEditor.Document.Text); + } + + [Test] + public void PackageFilesViewIsDirtyIsFalse() + { + Assert.IsFalse(packageFilesView.IsDirty); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AllowedChildElementsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AllowedChildElementsTestFixture.cs index cdc56feab9..9448b2cf27 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AllowedChildElementsTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AllowedChildElementsTestFixture.cs @@ -32,7 +32,7 @@ namespace WixBinding.Tests.PackageFiles base.InitFixture(); childElementAllowedWhenNoItemSelected = new string[view.AllowedChildElements.Count]; view.AllowedChildElements.CopyTo(childElementAllowedWhenNoItemSelected, 0); - WixDirectoryElement rootDir = editor.Document.RootDirectory; + WixDirectoryElement rootDir = editor.Document.GetRootDirectory(); XmlElement directoryElement = (XmlElement)rootDir.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AttributeValueChangedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AttributeValueChangedTestFixture.cs index 621345726d..86d326c121 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AttributeValueChangedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AttributeValueChangedTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); - XmlElement rootDirectoryElement = editor.Document.RootDirectory; + XmlElement rootDirectoryElement = editor.Document.GetRootDirectory(); XmlElement directoryElement = (XmlElement)rootDirectoryElement.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs index 9aec79227a..f31aa8da80 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs @@ -29,7 +29,7 @@ namespace WixBinding.Tests.PackageFiles public void Init() { base.InitFixture(); - componentElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0].ChildNodes[0]; + componentElement = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0].ChildNodes[0].ChildNodes[0]; view.SelectedElement = componentElement; editor.SelectedElementChanged(); string exeFileName = Path.Combine(project.Directory, @"bin\TestApplication.exe"); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementDeselectedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementDeselectedTestFixture.cs index 8ea7c2aa1b..c8b726d11f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementDeselectedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementDeselectedTestFixture.cs @@ -26,7 +26,7 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); - XmlElement rootDirectoryElement = editor.Document.RootDirectory; + XmlElement rootDirectoryElement = editor.Document.GetRootDirectory(); XmlElement directoryElement = (XmlElement)rootDirectoryElement.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementSelectedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementSelectedTestFixture.cs index dbac347edf..907b7046ca 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementSelectedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ElementSelectedTestFixture.cs @@ -27,7 +27,7 @@ namespace WixBinding.Tests.PackageFiles public void SetUpFixture() { base.InitFixture(); - XmlElement rootDirectoryElement = editor.Document.RootDirectory; + XmlElement rootDirectoryElement = editor.Document.GetRootDirectory(); XmlElement directoryElement = (XmlElement)rootDirectoryElement.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/EmptyAttributesRemovedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/EmptyAttributesRemovedTestFixture.cs index 67723049db..358b30923d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/EmptyAttributesRemovedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/EmptyAttributesRemovedTestFixture.cs @@ -27,7 +27,7 @@ namespace WixBinding.Tests.PackageFiles public void SetUpFixture() { base.InitFixture(); - XmlElement rootDirectoryElement = editor.Document.RootDirectory; + XmlElement rootDirectoryElement = editor.Document.GetRootDirectory(); directoryElement = (XmlElement)rootDirectoryElement.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs index 2573060f7d..67153470be 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs @@ -14,52 +14,60 @@ namespace WixBinding.Tests.PackageFiles [TestFixture] public class GenerateComponentIdTests { + WixComponentElement component; + + [SetUp] + public void Init() + { + component = new WixComponentElement(new WixDocument()); + } + [Test] public void SimpleFileName() { string fileName = "myapp.exe"; - Assert.AreEqual("MyappExe", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("MyappExe", component.GenerateIdFromFileName(fileName)); } [Test] public void NoExtension() { string fileName = "myapp"; - Assert.AreEqual("Myapp", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("Myapp", component.GenerateIdFromFileName(fileName)); } [Test] public void OnlyExtension() { string fileName = ".bat"; - Assert.AreEqual("Bat", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("Bat", component.GenerateIdFromFileName(fileName)); } [Test] public void SingleCharacterFileName() { string fileName = "a.bat"; - Assert.AreEqual("ABat", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("ABat", component.GenerateIdFromFileName(fileName)); } [Test] public void EmptyString() { - Assert.AreEqual(String.Empty, WixComponentElement.GenerateIdFromFileName(String.Empty)); + Assert.AreEqual(String.Empty, component.GenerateIdFromFileName(String.Empty)); } [Test] public void Hyphen() { string fileName = "a-b.txt"; - Assert.AreEqual("A_bTxt", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("A_bTxt", component.GenerateIdFromFileName(fileName)); } [Test] public void DotsInFileName() { string fileName = "a.b.txt"; - Assert.AreEqual("AbTxt", WixComponentElement.GenerateIdFromFileName(fileName)); + Assert.AreEqual("AbTxt", component.GenerateIdFromFileName(fileName)); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoDiffShownTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoDiffShownTestFixture.cs index 430f528665..a19f21df8c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoDiffShownTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoDiffShownTestFixture.cs @@ -26,7 +26,7 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); directories = new List(); - editor.ShowDiff(); + editor.CalculateDiff(); Assert.IsTrue(view.IsNoDifferencesFoundMessageDisplayed); Assert.AreEqual(1, directories.Count); Assert.AreEqual(@"C:\Projects\Test\bin", directories[0]); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoRootDirectoryInWixProductFileTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoRootDirectoryInWixProductFileTestFixture.cs index 9c5f69bfa0..12f0f195c7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoRootDirectoryInWixProductFileTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/NoRootDirectoryInWixProductFileTestFixture.cs @@ -42,7 +42,7 @@ namespace WixBinding.Tests.PackageFiles [Test] public void ShowDiff() { - editor.ShowDiff(); + editor.CalculateDiff(); Assert.IsTrue(view.IsNoDifferencesFoundMessageDisplayed); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OneNewFileDiffTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OneNewFileDiffTestFixture.cs index aa267f91dd..d07865a665 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OneNewFileDiffTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OneNewFileDiffTestFixture.cs @@ -23,7 +23,7 @@ namespace WixBinding.Tests.PackageFiles { base.InitFixture(); editor.ExcludedItems.AddRange(new string[] {"*.pdb"}); - WixDirectoryElement programFilesDirectory = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild; + WixDirectoryElement programFilesDirectory = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild; installDirectory = (WixDirectoryElement)programFilesDirectory.FirstChild; binDirectory = (WixDirectoryElement)installDirectory.LastChild; } @@ -32,7 +32,7 @@ namespace WixBinding.Tests.PackageFiles public void InstallDirectorySelected() { view.SelectedElement = installDirectory; - editor.ShowDiff(); + editor.CalculateDiff(); Assert.AreEqual(1, view.DiffResults.Length); Assert.AreEqual(@"C:\Projects\Test\doc\files\newfile.txt", view.DiffResults[0].FileName); Assert.AreEqual(WixPackageFilesDiffResultType.NewFile, view.DiffResults[0].DiffType); @@ -43,7 +43,7 @@ namespace WixBinding.Tests.PackageFiles public void BinDirectorySelected() { view.SelectedElement = binDirectory; - editor.ShowDiff(); + editor.CalculateDiff(); Assert.IsTrue(view.IsNoDifferencesFoundMessageDisplayed); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OpenTextEditorsTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OpenTextEditorsTestFixture.cs new file mode 100644 index 0000000000..ba022f0343 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/OpenTextEditorsTestFixture.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class OpenTextEditorsTestFixture + { + OpenTextEditors openEditors; + MockTextEditor existingTextEditor; + MockWorkbench workbench; + WixDocument document; + + [SetUp] + public void Init() + { + existingTextEditor = new MockTextEditor(); + MockTextEditorViewContent viewContent = new MockTextEditorViewContent(); + viewContent.TextEditor = existingTextEditor; + viewContent.SetFileName(@"d:\projects\test\file.wxs"); + + workbench = new MockWorkbench(); + workbench.ViewContentCollection.Add(new MockViewContent()); + workbench.ViewContentCollection.Add(viewContent); + + document = new WixDocument(); + document.FileName = @"d:\Projects\Test\File.wxs"; + + openEditors = new OpenTextEditors(workbench); + } + + [Test] + public void CanFindTextEditorForWixDocumentCurrentlyOpenInWorkbench() + { + Assert.AreSame(existingTextEditor, openEditors.FindTextEditorForDocument(document)); + } + + [Test] + public void CannotFindTextEditorForUnknownWixDocumentFileName() + { + WixDocument unknownDocument = new WixDocument(); + unknownDocument.FileName = @"d:\unknown-file.wxs"; + Assert.IsNull(openEditors.FindTextEditorForDocument(unknownDocument)); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewIsActiveTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewIsActiveTests.cs new file mode 100644 index 0000000000..cf1dbf6da4 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewIsActiveTests.cs @@ -0,0 +1,45 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class PackageFilesViewIsActiveTests + { + MockWorkbench workbench; + PackageFilesView packageFilesView; + WixProject project; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + project = WixBindingTestsHelper.CreateEmptyWixProject(); + packageFilesView = new PackageFilesView(project, workbench); + + workbench.ActiveViewContent = packageFilesView; + } + + [Test] + public void PackageFilesViewIsActive() + { + Assert.IsTrue(packageFilesView.IsActiveWindow); + } + + [Test] + public void PackageFilesViewIsNotActiveWhenWorkbenchActiveViewContentIsAnotherView() + { + workbench.ActiveViewContent = new PackageFilesView(project, workbench); + Assert.IsFalse(packageFilesView.IsActiveWindow); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewTestFixture.cs new file mode 100644 index 0000000000..8f2787650e --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesViewTestFixture.cs @@ -0,0 +1,246 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows.Forms; +using System.Xml; + +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class PackageFilesViewTestFixture + { + PackageFilesView packageFilesView; + WixProject project; + MockWorkbench mockWorkbench; + MockWixPackageFilesControl mockPackageFilesControl; + WixDocument document; + MockXmlTextWriter xmlTextWriter; + MockTextEditorOptions textEditorOptions; + + [SetUp] + public void Init() + { + project = WixBindingTestsHelper.CreateEmptyWixProject(); + mockWorkbench = new MockWorkbench(); + mockPackageFilesControl = new MockWixPackageFilesControl(); + textEditorOptions = new MockTextEditorOptions(); + textEditorOptions.ConvertTabsToSpaces = false; + + xmlTextWriter = new MockXmlTextWriter(textEditorOptions); + packageFilesView = new PackageFilesView(project, mockWorkbench, mockPackageFilesControl, xmlTextWriter); + + mockWorkbench.ActiveContent = packageFilesView; + + document = new WixDocument(project, new DefaultFileLoader()); + } + + [TearDown] + public void TearDown() + { + packageFilesView.Dispose(); + } + + [Test] + public void WixProjectPassedToPackageFilesViewConstructorSoPackageFilesViewIsForProjectReturnsTrue() + { + Assert.IsTrue(packageFilesView.IsForProject(project)); + } + + [Test] + public void PackageFilesViewTitleNameIsSet() + { + Assert.AreEqual("${res:ICSharpCode.WixBinding.PackageFilesView.Title}", packageFilesView.TitleName); + } + + [Test] + public void PackageFilesViewControlIsWixPackageFilesControl() + { + Assert.AreSame(mockPackageFilesControl, packageFilesView.Control); + } + + [Test] + public void DisposingPackageFilesViewDisposesWixPackageFilesControl() + { + packageFilesView.Dispose(); + + Assert.IsTrue(mockPackageFilesControl.IsDisposed); + } + + [Test] + public void RaisingDirtyChangedEventOnWixPackageFilesControlFiresPackageFilesViewIsDirtyChangedEvent() + { + bool dirtyChangedEventFired = false; + packageFilesView.IsDirtyChanged += delegate (object source, EventArgs e) + { dirtyChangedEventFired = true; }; + + mockPackageFilesControl.RaiseDirtyChangedEvent(); + + Assert.IsTrue(dirtyChangedEventFired); + } + + [Test] + public void PackageFilesViewIsDirtyReturnsWixPackageFilesControlIsDirtyValue() + { + mockPackageFilesControl.IsDirty = true; + + Assert.IsTrue(packageFilesView.IsDirty); + } + + [Test] + public void PackageFilesViewIsDirtyIsInitiallyFalse() + { + Assert.IsFalse(packageFilesView.IsDirty); + } + + [Test] + public void SaveMethodCallsWixPackageFilesControlSaveMethod() + { + packageFilesView.Save(); + + Assert.IsTrue(mockPackageFilesControl.SaveMethodCalled); + } + + [Test] + public void AddElementCallsWixPackageFilesAddElementMethod() + { + DerivedAddElementCommand command = new DerivedAddElementCommand("name", mockWorkbench); + command.CallOnClick(); + Assert.AreEqual("name", mockPackageFilesControl.AddElementNameParameter); + } + + [Test] + public void AddElementCommandDoesNotThrowNullReferenceExceptionWhenWhenNoActivePackageFilesView() + { + mockWorkbench.ActiveContent = null; + DerivedAddElementCommand command = new DerivedAddElementCommand("name", mockWorkbench); + + Assert.DoesNotThrow(delegate { command.CallOnClick(); }); + } + + [Test] + public void RemoveSelectedElementCallsWixPackageFilesRemoveSelectedElementMethod() + { + RemoveElementCommand command = new RemoveElementCommand(mockWorkbench); + command.Run(); + Assert.IsTrue(mockPackageFilesControl.RemoveSelectedElementMethodCalled); + } + + [Test] + public void AddFilesCallsWixPackageFilesAddFilesMethod() + { + AddFilesCommand command = new AddFilesCommand(mockWorkbench); + command.Run(); + Assert.IsTrue(mockPackageFilesControl.AddFilesMethodCalled); + } + + [Test] + public void AddDirectoryCallsWixPackageFilesAddDirectoryMethod() + { + AddDirectoryCommand command = new AddDirectoryCommand(mockWorkbench); + command.Run(); + Assert.IsTrue(mockPackageFilesControl.AddDirectoryMethodCalled); + } + + [Test] + public void CalculateDiffCallsWixPackageFilesShowDiffMethod() + { + ShowDiffCommand command = new ShowDiffCommand(mockWorkbench); + command.Run(); + Assert.IsTrue(mockPackageFilesControl.CalculateDiffMethodCalled); + } + + [Test] + public void ShowDiffCommandDoesNotThrowNullReferenceExceptionWhenNoActivePackageFilesView() + { + mockWorkbench.ActiveContent = null; + ShowDiffCommand command = new ShowDiffCommand(mockWorkbench); + Assert.DoesNotThrow(delegate { command.Run(); }); + } + + [Test] + public void HideDiffSetsWixPackageFilesIsDiffVisibleToFalse() + { + mockPackageFilesControl.IsDiffVisible = true; + + HideDiffCommand command = new HideDiffCommand(mockWorkbench); + command.Run(); + + Assert.IsFalse(mockPackageFilesControl.IsDiffVisible); + } + + [Test] + public void ShowFilesMethodProjectParameterIsProjectPassedToPackageFilesViewOnCreation() + { + packageFilesView.ShowFiles(); + Assert.AreSame(project, mockPackageFilesControl.ShowFilesMethodProjectParameter); + } + + [Test] + public void ShowFilesMethodWixDocumentWriterParameterIsPackageFilesViewObject() + { + packageFilesView.ShowFiles(); + Assert.AreSame(packageFilesView, mockPackageFilesControl.ShowFilesMethodDocumentWriterParameter); + } + + [Test] + public void ShowFilesMethodTextFileReaderParameterIsNotNull() + { + packageFilesView.ShowFiles(); + Assert.IsNotNull(mockPackageFilesControl.ShowFilesMethodFileReaderParameter); + } + + [Test] + public void WriteWixDocumentSetsPackageFilesControlIsDirtyToFalse() + { + mockPackageFilesControl.IsDirty = true; + packageFilesView.Write(document); + Assert.IsFalse(mockPackageFilesControl.IsDirty); + } + + [Test] + public void WriteWixDocumentSavesDocumentToDiskUsingTextEditorProperties() + { + packageFilesView.Write(document); + + XmlWriterSettings expectedSettings = new XmlWriterSettings(); + expectedSettings.CloseOutput = true; + expectedSettings.Indent = true; + expectedSettings.IndentChars = "\t"; + expectedSettings.NewLineChars = "\r\n"; + expectedSettings.OmitXmlDeclaration = true; + + XmlWriterSettingsComparison comparison = new XmlWriterSettingsComparison(); + Assert.IsTrue(comparison.AreEqual(expectedSettings, xmlTextWriter.XmlWriterSettingsPassedToCreateMethod), + comparison.ToString()); + } + + [Test] + public void WriteWixDocumentSavesDocumentToDiskUsingTextEditorPropertiesWhenConvertTabsToSpacesIsTrue() + { + textEditorOptions.ConvertTabsToSpaces = true; + textEditorOptions.IndentationSize = 4; + + packageFilesView.Write(document); + + XmlWriterSettings expectedSettings = new XmlWriterSettings(); + expectedSettings.CloseOutput = true; + expectedSettings.Indent = true; + expectedSettings.IndentChars = " "; + expectedSettings.NewLineChars = "\r\n"; + expectedSettings.OmitXmlDeclaration = true; + + XmlWriterSettingsComparison comparison = new XmlWriterSettingsComparison(); + Assert.IsTrue(comparison.AreEqual(expectedSettings, xmlTextWriter.XmlWriterSettingsPassedToCreateMethod), + comparison.ToString()); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveDirectoryTestFixture.cs index 68ce672bb7..61efab6702 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveDirectoryTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveDirectoryTestFixture.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.PackageFiles public void SetUpFixture() { base.InitFixture(); - XmlElement progFilesDir = (XmlElement)editor.Document.RootDirectory.ChildNodes[0]; + XmlElement progFilesDir = (XmlElement)editor.Document.GetRootDirectory().ChildNodes[0]; installDir = (XmlElement)progFilesDir.ChildNodes[0]; view.SelectedElement = installDir; editor.RemoveElement(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveWhenNothingSelectedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveWhenNothingSelectedTestFixture.cs index e97dd66798..670b3c6a93 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveWhenNothingSelectedTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/RemoveWhenNothingSelectedTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.PackageFiles [Test] public void DirStillExists() { - Assert.IsNotNull(editor.Document.RootDirectory.ChildNodes[0]); + Assert.IsNotNull(editor.Document.GetRootDirectory().ChildNodes[0]); } protected override string GetWixXml() diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/SaveChangesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/SaveChangesTestFixture.cs index 56dd5b3590..aa4f5a0350 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/SaveChangesTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/SaveChangesTestFixture.cs @@ -28,7 +28,7 @@ namespace WixBinding.Tests.PackageFiles public void SetUpFixture() { base.InitFixture(); - XmlElement rootDirectoryElement = editor.Document.RootDirectory; + XmlElement rootDirectoryElement = editor.Document.GetRootDirectory(); XmlElement directoryElement = (XmlElement)rootDirectoryElement.ChildNodes[0]; view.SelectedElement = directoryElement; editor.SelectedElementChanged(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryRefWithNewFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryRefWithNewFilesTestFixture.cs new file mode 100644 index 0000000000..5fb716ad3d --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryRefWithNewFilesTestFixture.cs @@ -0,0 +1,71 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class UpdateRootDirectoryRefWithNewFilesTestFixture : UpdateRootDirectoryWithNewFilesTestFixtureBase + { + protected override string GetWixXml() + { + return + "\r\n" + + "\t \r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + + protected override void AddNewChildElementsToDirectory() + { + WixDirectoryRefElement dirRef = document.GetRootDirectoryRef(); + WixDirectoryElement programFilesDir = dirRef.FirstChild as WixDirectoryElement; + + WixDirectoryElement sharpDevelopDir = programFilesDir.AddDirectory("SharpDevelop"); + sharpDevelopDir.Id = "SharpDevelopFolder"; + + WixComponentElement component = sharpDevelopDir.AddComponent("SharpDevelopExe"); + component.Guid = "guid"; + WixFileElement file = component.AddFile("SharpDevelop.exe"); + file.Source = @"..\..\bin\SharpDevelop.exe"; + } + + [Test] + public void GetExpectedWixXml() + { + string expectedXml = + "\r\n" + + "\t \r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, textEditor.Document.Text, textEditor.Document.Text); + } + + [Test] + public void PackageFilesViewIsDirtyIsFalse() + { + Assert.IsFalse(packageFilesView.IsDirty); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixture.cs new file mode 100644 index 0000000000..39e9e49712 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixture.cs @@ -0,0 +1,82 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + [TestFixture] + public class UpdateRootDirectoryWithNewFilesTestFixture : UpdateRootDirectoryWithNewFilesTestFixtureBase + { + protected override string GetWixXml() + { + return + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + } + + protected override void AddNewChildElementsToDirectory() + { + WixDirectoryElement dir = document.GetRootDirectory(); + WixDirectoryElement programFilesDir = dir.AddDirectory("ProgramFilesFolder"); + programFilesDir.SourceName = "PFiles"; + programFilesDir.RemoveAttribute("Name"); + + WixDirectoryElement sharpDevelopDir = programFilesDir.AddDirectory("SharpDevelop"); + sharpDevelopDir.Id = "SharpDevelopFolder"; + + WixComponentElement component = sharpDevelopDir.AddComponent("SharpDevelopExe"); + component.Guid = "guid"; + WixFileElement file = component.AddFile("SharpDevelop.exe"); + file.Source = @"..\..\bin\SharpDevelop.exe"; + } + + [Test] + public void GetExpectedWixXml() + { + string expectedXml = + "\r\n" + + "\t\r\n" + + "\t\t\r\n" + + "\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\t\t\r\n" + + "\t\t\t\t\t\r\n" + + "\t\t\t\t\r\n" + + "\t\t\t\r\n" + + "\t\t\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, textEditor.Document.Text, textEditor.Document.Text); + } + + [Test] + public void PackageFilesViewIsDirtyIsFalse() + { + Assert.IsFalse(packageFilesView.IsDirty); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixtureBase.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixtureBase.cs new file mode 100644 index 0000000000..18b78d87f5 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/UpdateRootDirectoryWithNewFilesTestFixtureBase.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.PackageFiles +{ + public abstract class UpdateRootDirectoryWithNewFilesTestFixtureBase + { + protected MockTextEditor textEditor; + protected MockWorkbench workbench; + protected WixDocument document; + protected PackageFilesView packageFilesView; + + [SetUp] + public void Init() + { + textEditor = new MockTextEditor(); + MockTextEditorViewContent viewContent = new MockTextEditorViewContent(); + viewContent.TextEditor = textEditor; + viewContent.SetFileName(@"d:\projects\test\file.wxs"); + + workbench = new MockWorkbench(); + workbench.ViewContentCollection.Add(viewContent); + + MockTextEditorOptions textEditorOptions = new MockTextEditorOptions(); + MockXmlTextWriter xmlTextWriter = new MockXmlTextWriter(textEditorOptions); + WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); + document = new WixDocument(project, new DefaultFileLoader()); + document.LoadXml(GetWixXml()); + document.FileName = @"d:\projects\test\File.wxs"; + textEditor.Document.Text = GetWixXml(); + + MockWixPackageFilesControl packageFilesControl = new MockWixPackageFilesControl(); + packageFilesView = new PackageFilesView(project, workbench, packageFilesControl, xmlTextWriter); + + packageFilesControl.IsDirty = true; + AddNewChildElementsToDirectory(); + packageFilesView.Write(document); + } + + protected abstract string GetWixXml(); + + protected abstract void AddNewChildElementsToDirectory(); + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs index 2499248ac6..62c8a1b9a8 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs @@ -30,7 +30,7 @@ namespace WixBinding.Tests.PackageFiles doc = new WixDocument(); doc.FileName = @"C:\Projects\Setup\Files.wxs"; doc.LoadXml(GetWixXml()); - XmlElement productElement = doc.Product; + XmlElement productElement = doc.GetProduct(); WixXmlAttributeCollection attributes = wixSchema.GetAttributes(productElement); productIdAttribute = attributes["Id"]; productUpgradeCodeAttribute = attributes["UpgradeCode"]; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs index 611c1fcc2b..fe238cd8cc 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs @@ -146,7 +146,8 @@ namespace WixBinding.Tests.Project [Test] public void UnknownProperty() { - Assert.IsNull(project.GetValue("UnknownMSBuildProperty")); + IWixPropertyValueProvider provider = (IWixPropertyValueProvider)project; + Assert.IsNull(provider.GetValue("UnknownMSBuildProperty")); } [Test] @@ -160,10 +161,11 @@ namespace WixBinding.Tests.Project /// ProjectPropertyElement GetMSBuildProperty(string name) { - foreach (ProjectPropertyGroupElement g in project.MSBuildProjectFile.PropertyGroups) { - foreach (ProjectPropertyElement element in g.Properties) { - if (element.Name == name) + foreach (ProjectPropertyGroupElement propertyGroup in project.MSBuildProjectFile.PropertyGroups) { + foreach (ProjectPropertyElement element in propertyGroup.Properties) { + if (element.Name == name) { return element; + } } } return null; diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Project/GetPreprocessorVariableValueTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Project/GetPreprocessorVariableValueTests.cs index b6161b6bc2..9d28ebef23 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Project/GetPreprocessorVariableValueTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Project/GetPreprocessorVariableValueTests.cs @@ -24,7 +24,7 @@ namespace WixBinding.Tests.Project public void MissingVariableName() { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); - Assert.AreEqual(String.Empty, p.GetVariable("Missing")); + Assert.AreEqual(String.Empty, p.GetPreprocessorVariableValue("Missing")); } [Test] @@ -32,7 +32,7 @@ namespace WixBinding.Tests.Project { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); p.SetProperty("DefineConstants", "DATADIR=Bitmaps"); - Assert.AreEqual("Bitmaps", p.GetVariable("DATADIR")); + Assert.AreEqual("Bitmaps", p.GetPreprocessorVariableValue("DATADIR")); } [Test] @@ -40,7 +40,7 @@ namespace WixBinding.Tests.Project { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); p.SetProperty("DefineConstants", "TEST=test;DATADIR=Bitmaps"); - Assert.AreEqual("Bitmaps", p.GetVariable("DATADIR")); + Assert.AreEqual("Bitmaps", p.GetPreprocessorVariableValue("DATADIR")); } [Test] @@ -48,7 +48,7 @@ namespace WixBinding.Tests.Project { WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); p.SetProperty("DefineConstants", " DATADIR = Bitmaps "); - Assert.AreEqual("Bitmaps", p.GetVariable("DATADIR")); + Assert.AreEqual("Bitmaps", p.GetPreprocessorVariableValue("DATADIR")); } /// @@ -61,7 +61,7 @@ namespace WixBinding.Tests.Project MSBuildEngine.MSBuildProperties.Add("MyAppBinPath", @"C:\Program Files\MyApp\bin"); WixProject p = WixBindingTestsHelper.CreateEmptyWixProject(); p.SetProperty("DefineConstants", @" DATADIR = $(MyAppBinPath)\Bitmaps "); - string variableValue = p.GetVariable("DATADIR"); + string variableValue = p.GetPreprocessorVariableValue("DATADIR"); MSBuildEngine.MSBuildProperties.Remove("MyAppBinPath"); Assert.AreEqual(@"C:\Program Files\MyApp\bin\Bitmaps", variableValue); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Project/WixInstallerPathTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Project/WixInstallerPathTests.cs index ecf73b0dea..04dce03517 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Project/WixInstallerPathTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Project/WixInstallerPathTests.cs @@ -25,7 +25,7 @@ namespace WixBinding.Tests.Project { WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); - Assert.AreEqual(@"C:\Projects\Test\bin\Debug\Test.msi", project.InstallerFullPath); + Assert.AreEqual(@"C:\Projects\Test\bin\Debug\Test.msi", project.GetInstallerFullPath()); } [Test] @@ -34,7 +34,7 @@ namespace WixBinding.Tests.Project WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); project.SetProperty("OutputName", "ChangedName"); - Assert.AreEqual(@"C:\Projects\Test\bin\Debug\ChangedName.msi", project.InstallerFullPath); + Assert.AreEqual(@"C:\Projects\Test\bin\Debug\ChangedName.msi", project.GetInstallerFullPath()); } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/DerivedAddElementCommand.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/DerivedAddElementCommand.cs new file mode 100644 index 0000000000..4445181068 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/DerivedAddElementCommand.cs @@ -0,0 +1,26 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class DerivedAddElementCommand : AddElementCommand + { + public DerivedAddElementCommand(string name, IWorkbench workbench) + : base(name, workbench) + { + } + + public void CallOnClick() + { + base.OnClick(new EventArgs()); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/DialogLoadingTestFixtureBase.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/DialogLoadingTestFixtureBase.cs index 7fa4d998d8..6858dbf25f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/DialogLoadingTestFixtureBase.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/DialogLoadingTestFixtureBase.cs @@ -38,7 +38,7 @@ namespace WixBinding.Tests.Utils return (IComponent)instance; } - public Bitmap GetBitmap(string fileName) + public Bitmap LoadBitmap(string fileName) { bitmapFileNamesRequested.Add(fileName); return new Bitmap(10, 10); @@ -48,18 +48,14 @@ namespace WixBinding.Tests.Utils /// Gets a list of the bitmap filenames requested through the GetBitmapFromFileName /// method. protected List BitmapFileNamesRequested { - get { - return bitmapFileNamesRequested; - } + get { return bitmapFileNamesRequested; } } /// /// Gets a list of the components created via the IComponentCreator.Create /// method. protected List CreatedComponents { - get { - return createdComponents; - } + get { return createdComponents; } } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockCaret.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockCaret.cs new file mode 100644 index 0000000000..5b2d8bc58b --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockCaret.cs @@ -0,0 +1,63 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Editor; + +namespace WixBinding.Tests.Utils +{ + public class MockCaret : ITextEditorCaret + { + Location position = Location.Empty; + + public MockCaret() + { + } + + public event EventHandler PositionChanged; + + protected virtual void OnPositionChanged(EventArgs e) + { + if (PositionChanged != null) { + PositionChanged(this, e); + } + } + + public int Offset { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public int Line { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public int Column { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public Location Position { + get { return position; } + set { position = value; } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockFormsDesignerView.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockFormsDesignerView.cs new file mode 100644 index 0000000000..891d69ae6a --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockFormsDesignerView.cs @@ -0,0 +1,18 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockFormsDesignerView : IFormsDesignerView + { + public OpenedFile PrimaryFile { get; set; } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockOpenedFile.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockOpenedFile.cs new file mode 100644 index 0000000000..fbea39fffd --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockOpenedFile.cs @@ -0,0 +1,41 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Gui; + +namespace WixBinding.Tests.Utils +{ + public class MockOpenedFile : OpenedFile + { + public MockOpenedFile(string fileName, bool isUntitled) + { + base.FileName = FileName.Create(fileName); + base.IsUntitled = isUntitled; + } + + public override IList RegisteredViewContents { + get { + throw new NotImplementedException(); + } + } + + public override void RegisterView(IViewContent view) + { + } + + public override void UnregisterView(IViewContent view) + { + } + + public override event EventHandler FileClosed { add {} remove {} } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockPackageFilesViewFactory.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockPackageFilesViewFactory.cs new file mode 100644 index 0000000000..aca7f80509 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockPackageFilesViewFactory.cs @@ -0,0 +1,51 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockPackageFilesViewFactory : IPackageFilesViewFactory + { + PackageFilesView packageFilesViewCreated; + WixProject createMethodProjectParameter; + IWorkbench createMethodWorkbenchParameter; + MockWixPackageFilesControl packageFilesControl; + + public MockPackageFilesViewFactory() + { + } + + public PackageFilesView Create(WixProject project, IWorkbench workbench) + { + createMethodProjectParameter = project; + createMethodWorkbenchParameter = workbench; + packageFilesControl = new MockWixPackageFilesControl(); + + packageFilesViewCreated = new PackageFilesView(project, workbench, packageFilesControl); + return packageFilesViewCreated; + } + + public PackageFilesView PackageFilesViewCreated { + get { return packageFilesViewCreated; } + } + + public WixProject CreateMethodProjectParameter { + get { return createMethodProjectParameter; } + } + + public IWorkbench CreateMethodWorkbenchParameter { + get { return createMethodWorkbenchParameter; } + } + + public MockWixPackageFilesControl PackageFilesControlCreated { + get { return packageFilesControl; } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs new file mode 100644 index 0000000000..d748351672 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs @@ -0,0 +1,174 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Windows.Input; +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.AvalonEdit.Editing; +using ICSharpCode.Core; +using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; +using ICSharpCode.SharpDevelop.Editor.CodeCompletion; + +namespace WixBinding.Tests.Utils +{ + public class MockTextEditor : ITextEditor + { + TextDocument textDocument = new TextDocument(); + AvalonEditDocumentAdapter documentAdapter; + MockCaret caret = new MockCaret(); + Location locationJumpedTo = Location.Empty; + SimpleSelection selection = new SimpleSelection(-1, -1); + MockTextEditorOptions options = new MockTextEditorOptions(); + + public MockTextEditor() + { + documentAdapter = new AvalonEditDocumentAdapter(textDocument, null); + } + + public event EventHandler SelectionChanged; + + protected virtual void OnSelectionChanged(EventArgs e) + { + if (SelectionChanged != null) { + SelectionChanged(this, e); + } + } + + public event KeyEventHandler KeyPress; + + protected virtual void OnKeyPress() + { + if (KeyPress != null) { + // do nothing. + } + } + + public ITextEditor PrimaryView { + get { + throw new NotImplementedException(); + } + } + + public IDocument Document { + get { return documentAdapter; } + } + + public ITextEditorCaret Caret { + get { return caret; } + } + + public ITextEditorOptions Options { + get { return options; } + } + + public bool OptionsConvertTabsToSpaces { + get { return options.ConvertTabsToSpaces; } + set { options.ConvertTabsToSpaces = value; } + } + + public string OptionsIndentationString { + get { return options.IndentationString; } + set { options.IndentationString = value; } + } + + public int OptionsIndentationSize { + get { return options.IndentationSize; } + set { options.IndentationSize = value; } + } + + public ILanguageBinding Language { + get { + throw new NotImplementedException(); + } + } + + public int SelectionStart { + get { + throw new NotImplementedException(); + } + } + + public int SelectionLength { + get { + throw new NotImplementedException(); + } + } + + public string SelectedText { + get { + if (selection.IsEmpty) { + return String.Empty; + } + return documentAdapter.GetText(selection.StartOffset, selection.Length); + } + set { + throw new NotImplementedException(); + } + } + + public FileName FileName { + get { + throw new NotImplementedException(); + } + } + + public ICompletionListWindow ActiveCompletionWindow { + get { + throw new NotImplementedException(); + } + } + + public IInsightWindow ActiveInsightWindow { + get { + throw new NotImplementedException(); + } + } + + public void Select(int selectionStart, int selectionLength) + { + selection = new SimpleSelection(selectionStart, selectionLength + selectionStart); + } + + public void JumpTo(int line, int column) + { + locationJumpedTo = new Location(column, line); + } + + public Location LocationJumpedTo { + get { return locationJumpedTo; } + } + + public ICompletionListWindow ShowCompletionWindow(ICompletionItemList data) + { + throw new NotImplementedException(); + } + + public IInsightWindow ShowInsightWindow(IEnumerable items) + { + throw new NotImplementedException(); + } + + public IEnumerable GetSnippets() + { + throw new NotImplementedException(); + } + + public object GetService(Type serviceType) + { + throw new NotImplementedException(); + } + + public void Undo() + { + textDocument.UndoStack.Undo(); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorOptions.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorOptions.cs new file mode 100644 index 0000000000..dccb8efd52 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorOptions.cs @@ -0,0 +1,50 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Editor; + +namespace WixBinding.Tests.Utils +{ + public class MockTextEditorOptions : ITextEditorOptions + { + string indentationString = "\t"; + int indentationSize = 4; + bool convertTabsToSpaces; + + public MockTextEditorOptions() + { + } + + public string IndentationString { + get { return indentationString; } + set { indentationString = value; } + } + + public bool AutoInsertBlockEnd { + get { + throw new NotImplementedException(); + } + } + + public bool ConvertTabsToSpaces { + get { return convertTabsToSpaces; } + set { convertTabsToSpaces = value; } + } + + public int IndentationSize { + get { return indentationSize; } + set { indentationSize = value; } + } + + public int VerticalRulerColumn { + get { + throw new NotImplementedException(); + } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorViewContent.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorViewContent.cs index 1b02365d8c..09c47d5f96 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorViewContent.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditorViewContent.cs @@ -14,29 +14,19 @@ using ICSharpCode.TextEditor; namespace WixBinding.Tests.Utils { /// - /// Mock IViewContent class that implements the ITextEditorControlProvider interface. + /// Mock IViewContent class that implements the ITextEditorProvider interface. /// - public class MockTextEditorViewContent : MockViewContent, ITextEditorControlProvider + public class MockTextEditorViewContent : MockViewContent, ITextEditorProvider { public MockTextEditorViewContent() { } - - #region ITextEditorControlProvider - - public TextEditorControl TextEditorControl { - get { throw new NotImplementedException(); } - } - public ITextEditor TextEditor { - get { throw new NotImplementedException(); } - } + public ITextEditor TextEditor { get; set; } public IDocument GetDocumentForFile(OpenedFile file) { return null; } - - #endregion } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextFileReader.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextFileReader.cs new file mode 100644 index 0000000000..130177349b --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextFileReader.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.IO; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockTextFileReader : ITextFileReader + { + public TextReader Create(string fileName) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs index 07100c2437..32b47e58a7 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockViewContent.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Windows.Forms; using ICSharpCode.Core; @@ -25,44 +26,19 @@ namespace WixBinding.Tests.Utils public MockViewContent() { - SetName("dummy.name"); + SetFileName("dummy.name"); } - public void SetName(string fileName) + public void SetFileName(string fileName) { primaryFile = new MockOpenedFile(fileName, false); } - public void SetUntitledName(string fileName) + public void SetUntitledFileName(string fileName) { primaryFile = new MockOpenedFile(fileName, true); } - class MockOpenedFile : OpenedFile - { - public MockOpenedFile(string fileName, bool isUntitled) - { - base.FileName = FileName.Create(fileName); - base.IsUntitled = isUntitled; - } - - public override IList RegisteredViewContents { - get { - throw new NotImplementedException(); - } - } - - public override void RegisterView(IViewContent view) - { - } - - public override void UnregisterView(IViewContent view) - { - } - - public override event EventHandler FileClosed { add {} remove {} } - } - #pragma warning disable 67 public event EventHandler TabPageTextChanged; public event EventHandler Disposed; @@ -72,7 +48,7 @@ namespace WixBinding.Tests.Utils public IList Files { get { - return new OpenedFile[] { primaryFile }; + throw new NotImplementedException(); } } @@ -94,12 +70,12 @@ namespace WixBinding.Tests.Utils } } - public void Save(OpenedFile file, System.IO.Stream stream) + public void Save(OpenedFile file, Stream stream) { throw new NotImplementedException(); } - public void Load(OpenedFile file, System.IO.Stream stream) + public void Load(OpenedFile file, Stream stream) { throw new NotImplementedException(); } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixDocumentWriter.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixDocumentWriter.cs new file mode 100644 index 0000000000..edd46e29e1 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixDocumentWriter.cs @@ -0,0 +1,24 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockWixDocumentWriter : IWixDocumentWriter + { + public MockWixDocumentWriter() + { + } + + public void Write(WixDocument document) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesControl.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesControl.cs new file mode 100644 index 0000000000..12bc40f869 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesControl.cs @@ -0,0 +1,125 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockWixPackageFilesControl : IWixPackageFilesControl + { + bool disposed; + bool saveMethodCalled; + string addElementNameParameter; + bool removeSelectedElementMethodCalled; + bool addFilesMethodCalled; + bool addDirectoryMethodCalled; + bool calculateDiffMethodCalled; + WixProject showFilesProjectParameter; + ITextFileReader showFilesFileReaderParameter; + IWixDocumentWriter showFilesDocumentWriterParameter; + + public MockWixPackageFilesControl() + { + } + + public void Dispose() + { + disposed = true; + } + + public bool IsDisposed { + get { return disposed; } + } + + public event EventHandler DirtyChanged; + + public void RaiseDirtyChangedEvent() + { + DirtyChanged(this, new EventArgs()); + } + + public bool IsDirty { get; set; } + + public bool SaveMethodCalled { + get { return saveMethodCalled; } + } + + public void Save() + { + saveMethodCalled = true; + } + + public string AddElementNameParameter { + get { return addElementNameParameter; } + } + + public void AddElement(string name) + { + addElementNameParameter = name; + } + + public bool RemoveSelectedElementMethodCalled { + get { return removeSelectedElementMethodCalled; } + } + + public void RemoveSelectedElement() + { + removeSelectedElementMethodCalled = true; + } + + public bool AddFilesMethodCalled { + get { return addFilesMethodCalled; } + } + + public void AddFiles() + { + addFilesMethodCalled = true; + } + + public bool AddDirectoryMethodCalled { + get { return addDirectoryMethodCalled; } + } + + public void AddDirectory() + { + addDirectoryMethodCalled = true; + } + + public bool CalculateDiffMethodCalled { + get { return calculateDiffMethodCalled; } + } + + public void CalculateDiff() + { + calculateDiffMethodCalled = true; + } + + public bool IsDiffVisible { get; set; } + + public void ShowFiles(WixProject project, ITextFileReader fileReader, IWixDocumentWriter documentWriter) + { + showFilesProjectParameter = project; + showFilesFileReaderParameter = fileReader; + showFilesDocumentWriterParameter = documentWriter; + } + + public WixProject ShowFilesMethodProjectParameter { + get { return showFilesProjectParameter; } + } + + public ITextFileReader ShowFilesMethodFileReaderParameter { + get { return showFilesFileReaderParameter; } + } + + public IWixDocumentWriter ShowFilesMethodDocumentWriterParameter { + get { return showFilesDocumentWriterParameter; } + } + + public WixDocument Document { get; set; } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesView.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesView.cs index 2e403bd3ef..ea8a4b8257 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesView.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWixPackageFilesView.cs @@ -60,12 +60,8 @@ namespace WixBinding.Tests.Utils } public WixDirectoryElement RootDirectory { - get { - return rootDirectory; - } - set { - rootDirectory = value; - } + get { return rootDirectory; } + set { rootDirectory = value; } } public void AddDirectories(WixDirectoryElement[] directories) @@ -76,9 +72,7 @@ namespace WixBinding.Tests.Utils } public List DirectoriesAdded { - get { - return directoriesAdded; - } + get { return directoriesAdded; } } public XmlElement SelectedElement { @@ -86,9 +80,7 @@ namespace WixBinding.Tests.Utils selectedItemAccessed = true; return selectedItem; } - set { - selectedItem = value; - } + set { selectedItem = value; } } public void RemoveElement(XmlElement element) @@ -97,24 +89,16 @@ namespace WixBinding.Tests.Utils } public WixXmlAttributeCollection Attributes { - get { - return attributes; - } + get { return attributes; } } public bool IsDirty { - get { - return isDirty; - } - set { - isDirty = value; - } + get { return isDirty; } + set { isDirty = value; } } public StringCollection AllowedChildElements { - get { - return allowedElements; - } + get { return allowedElements; } } public void AddElement(XmlElement element) @@ -142,9 +126,7 @@ namespace WixBinding.Tests.Utils /// view. /// public bool IsNoSourceFileFoundMessageDisplayed { - get { - return noSourceFileFoundMessageDisplayed; - } + get { return noSourceFileFoundMessageDisplayed; } } /// @@ -152,69 +134,49 @@ namespace WixBinding.Tests.Utils /// view. /// public bool IsSourceFilesContainErrorsMessageDisplayed { - get { - return sourceFilesContainErrorsMessageDisplayed; - } + get { return sourceFilesContainErrorsMessageDisplayed; } } /// /// Gets the project name that was passed to ShowNoSourceFileFoundMessage. /// public string NoSourceFileFoundProjectName { - get { - return projectName; - } + get { return projectName; } } /// /// Returns whether the view's SelectedItem was accessed. /// public bool SelectedElementAccessed { - get { - return selectedItemAccessed; - } + get { return selectedItemAccessed; } } public XmlElement ElementRemoved { - get { - return elementRemoved; - } + get { return elementRemoved; } } public XmlElement[] ElementsAdded { - get { - return elementsAdded.ToArray(); - } + get { return elementsAdded.ToArray(); } } public bool IsAttributesChangedCalled { - get { - return attributesChangedCalled; - } + get { return attributesChangedCalled; } } public bool IsClearDirectoriesCalled { - get { - return clearDirectoriesCalled; - } + get { return clearDirectoriesCalled; } } public bool IsNoDifferencesFoundMessageDisplayed { - get { - return noDifferencesFoundMessageDisplayed; - } + get { return noDifferencesFoundMessageDisplayed; } } public bool IsNoRootDirectoryFoundMessageDisplayed { - get { - return noRootDirectoryFoundMessageDisplayed; - } + get { return noRootDirectoryFoundMessageDisplayed; } } public WixPackageFilesDiffResult[] DiffResults { - get { - return diffResults; - } + get { return diffResults; } } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbench.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbench.cs new file mode 100644 index 0000000000..7d9395ccc8 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbench.cs @@ -0,0 +1,191 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Forms; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Gui; + +namespace WixBinding.Tests.Utils +{ + public class MockWorkbench : IWorkbench + { + List viewContents = new List(); + + public MockWorkbench() + { + } + + public IWin32Window MainWin32Window { + get { + throw new NotImplementedException(); + } + } + + public ISynchronizeInvoke SynchronizingObject { + get { + throw new NotImplementedException(); + } + } + + public Window MainWindow { + get { + throw new NotImplementedException(); + } + } + + public string Title { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public ICollection ViewContentCollection { + get { return viewContents; } + } + + public ICollection PrimaryViewContents { + get { + throw new NotImplementedException(); + } + } + + public IList WorkbenchWindowCollection { + get { + throw new NotImplementedException(); + } + } + + public IList PadContentCollection { + get { + throw new NotImplementedException(); + } + } + + public IWorkbenchWindow ActiveWorkbenchWindow { + get { + throw new NotImplementedException(); + } + } + + public IViewContent ActiveViewContent { get; set; } + + public object ActiveContent { get; set; } + + public IWorkbenchLayout WorkbenchLayout { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public bool IsActiveWindow { + get { + throw new NotImplementedException(); + } + } + + public void Initialize() + { + throw new NotImplementedException(); + } + + public void ShowView(IViewContent content) + { + ShowView(content, true); + } + + public void ShowView(IViewContent content, bool switchToOpenedView) + { + viewContents.Add(content); + } + + public void ShowPad(PadDescriptor content) + { + throw new NotImplementedException(); + } + + public void UnloadPad(PadDescriptor content) + { + throw new NotImplementedException(); + } + + public PadDescriptor GetPad(Type type) + { + throw new NotImplementedException(); + } + + public void CloseAllViews() + { + throw new NotImplementedException(); + } + + public Properties CreateMemento() + { + throw new NotImplementedException(); + } + + public void SetMemento(Properties memento) + { + throw new NotImplementedException(); + } + + public event EventHandler ActiveWorkbenchWindowChanged; + + protected virtual void OnActiveWorkbenchWindowChanged(EventArgs e) + { + if (ActiveWorkbenchWindowChanged != null) { + ActiveWorkbenchWindowChanged(this, e); + } + } + + public event EventHandler ActiveViewContentChanged; + + public void RaiseActiveViewContentChangedEvent() + { + if (ActiveViewContentChanged != null) { + ActiveViewContentChanged(this, new EventArgs()); + } + } + + public event EventHandler ActiveContentChanged; + + protected virtual void OnActiveContentChanged(EventArgs e) + { + if (ActiveContentChanged != null) { + ActiveContentChanged(this, e); + } + } + + public event ViewContentEventHandler ViewOpened; + + protected virtual void OnViewOpened(ViewContentEventArgs e) + { + if (ViewOpened != null) { + ViewOpened(this, e); + } + } + + public event ViewContentEventHandler ViewClosed; + + protected virtual void OnViewClosed(ViewContentEventArgs e) + { + if (ViewClosed != null) { + ViewClosed(this, e); + } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs new file mode 100644 index 0000000000..3ca745594c --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs @@ -0,0 +1,94 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Gui; + +namespace WixBinding.Tests.Utils +{ + public class MockWorkbenchWindow : IWorkbenchWindow + { + bool selectWindowMethodCalled; + + public MockWorkbenchWindow() + { + } + + public string Title { + get { + throw new NotImplementedException(); + } + } + + public bool IsDisposed { + get { + throw new NotImplementedException(); + } + } + + public IViewContent ActiveViewContent { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public System.Windows.Media.Imaging.BitmapSource Icon { + get { + throw new NotImplementedException(); + } + set { + throw new NotImplementedException(); + } + } + + public System.Collections.Generic.IList ViewContents { + get { + throw new NotImplementedException(); + } + } + + public void SwitchView(int viewNumber) + { + throw new NotImplementedException(); + } + + public bool CloseWindow(bool force) + { + throw new NotImplementedException(); + } + + public void SelectWindow() + { + selectWindowMethodCalled = true; + } + + public bool SelectWindowMethodCalled { + get { return selectWindowMethodCalled; } + } + + public event EventHandler ActiveViewContentChanged; + + protected virtual void OnActiveViewContentChanged(EventArgs e) + { + if (ActiveViewContentChanged != null) { + ActiveViewContentChanged(this, e); + } + } + + public event EventHandler TitleChanged; + + protected virtual void OnTitleChanged(EventArgs e) + { + if (TitleChanged != null) { + TitleChanged(this, e); + } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockXmlTextWriter.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockXmlTextWriter.cs new file mode 100644 index 0000000000..0cdfecff8f --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockXmlTextWriter.cs @@ -0,0 +1,43 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Text; +using System.Xml; + +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.WixBinding; + +namespace WixBinding.Tests.Utils +{ + public class MockXmlTextWriter : WixTextWriter + { + StringBuilder xml = new StringBuilder(); + XmlWriterSettings settings; + + public MockXmlTextWriter(ITextEditorOptions options) + : base(options) + { + } + + protected override XmlWriter Create(string fileName, XmlWriterSettings settings) + { + this.settings = settings; + + return XmlTextWriter.Create(xml, settings); + } + + public string GetXmlWritten() + { + return xml.ToString(); + } + + public XmlWriterSettings XmlWriterSettingsPassedToCreateMethod { + get { return settings; } + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockFormsDesignerViewTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockFormsDesignerViewTests.cs new file mode 100644 index 0000000000..91d50e806f --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockFormsDesignerViewTests.cs @@ -0,0 +1,34 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockFormsDesignerViewTests + { + MockFormsDesignerView view; + + [SetUp] + public void Init() + { + view = new MockFormsDesignerView(); + } + + [Test] + public void CanRetrievePrimaryOpenedFile() + { + MockOpenedFile file = new MockOpenedFile(@"d:\a.txt", false); + view.PrimaryFile = file; + Assert.AreSame(file, view.PrimaryFile); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockPackageFilesViewFactoryTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockPackageFilesViewFactoryTests.cs new file mode 100644 index 0000000000..dd23970e95 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockPackageFilesViewFactoryTests.cs @@ -0,0 +1,64 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockPackageFilesViewFactoryTests + { + PackageFilesView view; + MockPackageFilesViewFactory factory; + WixProject project; + MockWorkbench workbench; + + [SetUp] + public void Init() + { + project = WixBindingTestsHelper.CreateEmptyWixProject(); + factory = new MockPackageFilesViewFactory(); + workbench = new MockWorkbench(); + + view = factory.Create(project, workbench); + } + + [Test] + public void ViewCreatedIsSaved() + { + Assert.AreSame(view, factory.PackageFilesViewCreated); + } + + [Test] + public void ViewCreatedIsNotNull() + { + Assert.IsNotNull(view); + } + + [Test] + public void ProjectParameterUsedInCreateMethodCallIsSaved() + { + Assert.AreSame(project, factory.CreateMethodProjectParameter); + } + + [Test] + public void WorkbenchParameterUsedInCreateMethodCallIsSaved() + { + Assert.AreSame(workbench, factory.CreateMethodWorkbenchParameter); + } + + [Test] + public void PackageFilesCreatedWithMockWixPackageFilesControl() + { + view.AddFiles(); + Assert.IsTrue(factory.PackageFilesControlCreated.AddFilesMethodCalled); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs new file mode 100644 index 0000000000..e2f65e51be --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs @@ -0,0 +1,120 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.NRefactory; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockTextEditorTests + { + MockTextEditor textEditor; + + [SetUp] + public void Init() + { + textEditor = new MockTextEditor(); + } + + [Test] + public void LocationJumpedToIsSaved() + { + int line = 1; + int col = 2; + + textEditor.JumpTo(line, col); + + Location expectedLocation = new Location(col, line); + + Assert.AreEqual(expectedLocation, textEditor.LocationJumpedTo); + } + + [Test] + public void TextCanBeSelectedInTextEditor() + { + int offset = 1; + int length = 2; + textEditor.Document.Text = "test"; + textEditor.Select(offset, length); + + Assert.AreEqual("es", textEditor.SelectedText); + } + + [Test] + public void NoTextSelectedWhenTextEditorFirstCreated() + { + Assert.AreEqual(String.Empty, textEditor.SelectedText); + } + + [Test] + public void CursorPositionInTextEditorIsSaved() + { + int col = 2; + int line = 1; + textEditor.Document.Text = "abc\r\ndef\r\nghi"; + textEditor.Caret.Position = new Location(col, line); + + Location expectedLocation = new Location(col, line); + Assert.AreEqual(expectedLocation, textEditor.Caret.Position); + } + + [Test] + public void TextEditorOptionsIndentationStringIsSaved() + { + textEditor.OptionsIndentationString = " "; + Assert.AreEqual(" ", textEditor.Options.IndentationString); + } + + [Test] + public void TextEditorOptionsIndentationSizeIsSaved() + { + textEditor.OptionsIndentationSize = 2; + Assert.AreEqual(2, textEditor.Options.IndentationSize); + } + + [Test] + public void TextEditorOptionsConvertTabsToSpacesIsSaved() + { + textEditor.OptionsConvertTabsToSpaces = true; + Assert.IsTrue(textEditor.Options.ConvertTabsToSpaces); + } + + [Test] + public void DefaultTextEditorOptionsIndentationStringIsSingleTabCharacter() + { + Assert.AreEqual("\t", textEditor.Options.IndentationString); + } + + [Test] + public void DefaultTextEditorOptionsIndentationSizeIsFour() + { + Assert.AreEqual(4, textEditor.Options.IndentationSize); + } + + [Test] + public void DefaultTextEditorOptionsConvertTabsToSpacesIsFalse() + { + Assert.IsFalse(textEditor.Options.ConvertTabsToSpaces); + } + + [Test] + public void TextCanBeReplacedInTextEditorDocument() + { + textEditor.Document.Text = "abc-def-ghi"; + + int offset = 4; + int lengthOfTextToReplace = 3; + string newText = "replaced"; + textEditor.Document.Replace(offset, lengthOfTextToReplace, newText); + + Assert.AreEqual("abc-replaced-ghi", textEditor.Document.Text); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorViewContentTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorViewContentTests.cs new file mode 100644 index 0000000000..b5a42091d5 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorViewContentTests.cs @@ -0,0 +1,34 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockTextEditorViewContentTests + { + MockTextEditorViewContent view; + + [SetUp] + public void Init() + { + view = new MockTextEditorViewContent(); + } + + [Test] + public void TextEditorSetCanBeRetrieved() + { + MockTextEditor editor = new MockTextEditor(); + view.TextEditor = editor; + Assert.AreSame(editor, view.TextEditor); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockViewContentTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockViewContentTests.cs new file mode 100644 index 0000000000..346e805c48 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockViewContentTests.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using System; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockViewContentTests + { + MockViewContent view; + + [SetUp] + public void Init() + { + view = new MockViewContent(); + } + + [Test] + public void SetFileNameMethodCreatesNewPrimaryFile() + { + string fileName = @"d:\projects\a.txt"; + view.SetFileName(fileName); + Assert.AreEqual(fileName, view.PrimaryFile.FileName.ToString()); + } + + [Test] + public void SetFileNameMethodCreatesNewPrimaryFileName() + { + string fileName = @"d:\projects\a.txt"; + view.SetFileName(fileName); + Assert.AreEqual(fileName, view.PrimaryFileName.ToString()); + } + + [Test] + public void SetFileNameMethodCreatesNewPrimaryFileThatIsNotUntitled() + { + view.SetFileName(@"d:\test.txt"); + Assert.IsFalse(view.PrimaryFile.IsUntitled); + } + + [Test] + public void SetUntitledFileNameMethodCreatesNewPrimaryFile() + { + string fileName = @"d:\projects\a.txt"; + view.SetUntitledFileName(fileName); + Assert.AreEqual(fileName, view.PrimaryFile.FileName.ToString()); + } + + [Test] + public void SetUntitledFileNameMethodCreatesNewPrimaryFileName() + { + string fileName = @"d:\projects\a.txt"; + view.SetUntitledFileName(fileName); + Assert.AreEqual(fileName, view.PrimaryFileName.ToString()); + } + + [Test] + public void SetUntitledFileNameMethodCreatesNewPrimaryFileThatIsUntitled() + { + view.SetUntitledFileName(@"d:\test.txt"); + Assert.IsTrue(view.PrimaryFile.IsUntitled); + } + + [Test] + public void DefaultPrimaryFileNameIsDummyName() + { + Assert.AreEqual("dummy.name", view.PrimaryFile.FileName.ToString()); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWixPackageFilesControlTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWixPackageFilesControlTests.cs new file mode 100644 index 0000000000..9e87097574 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWixPackageFilesControlTests.cs @@ -0,0 +1,182 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockWixPackageFilesControlTests + { + MockWixPackageFilesControl control; + + [SetUp] + public void Init() + { + control = new MockWixPackageFilesControl(); + } + + [Test] + public void CallingDisposeSetsIsDisposedToTrue() + { + control.Dispose(); + Assert.IsTrue(control.IsDisposed); + } + + [Test] + public void InitialValueOfIsDisposedIsFalse() + { + Assert.IsFalse(control.IsDisposed); + } + + [Test] + public void RaiseDirtyChangedMethodFiresDirtyChangedEvent() + { + bool dirtyChangedEventFired = false; + control.DirtyChanged += delegate (object source, EventArgs e) + { dirtyChangedEventFired = true; }; + + control.RaiseDirtyChangedEvent(); + + Assert.IsTrue(dirtyChangedEventFired); + } + + [Test] + public void IsDirtyPropertyCanBeSetAndRetrieved() + { + control.IsDirty = true; + Assert.IsTrue(control.IsDirty); + } + + [Test] + public void IsDirtyIsInitiallyFalse() + { + Assert.IsFalse(control.IsDirty); + } + + [Test] + public void SaveMethodBeingCalledIsRecorded() + { + control.Save(); + Assert.IsTrue(control.SaveMethodCalled); + } + + [Test] + public void SaveMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(control.SaveMethodCalled); + } + + [Test] + public void AddElementMethodRecordsNameParameter() + { + control.AddElement("name"); + Assert.AreEqual("name", control.AddElementNameParameter); + } + + [Test] + public void RemoveSelectedElementMethodBeingCalledIsRecorded() + { + control.RemoveSelectedElement(); + Assert.IsTrue(control.RemoveSelectedElementMethodCalled); + } + + [Test] + public void RemoveSelectedElementMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(control.RemoveSelectedElementMethodCalled); + } + + + [Test] + public void AddFilesMethodBeingCalledIsRecorded() + { + control.AddFiles(); + Assert.IsTrue(control.AddFilesMethodCalled); + } + + [Test] + public void AddFilesMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(control.AddFilesMethodCalled); + } + + [Test] + public void AddDirectoyMethodBeingCalledIsRecorded() + { + control.AddDirectory(); + Assert.IsTrue(control.AddDirectoryMethodCalled); + } + + [Test] + public void AddDirectoryMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(control.AddDirectoryMethodCalled); + } + + [Test] + public void CalculateDiffMethodBeingCalledIsRecorded() + { + control.CalculateDiff(); + Assert.IsTrue(control.CalculateDiffMethodCalled); + } + + [Test] + public void CalculateDiffMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(control.CalculateDiffMethodCalled); + } + + [Test] + public void CanSetIsDiffVisibleToTrue() + { + control.IsDiffVisible = true; + Assert.IsTrue(control.IsDiffVisible); + } + + [Test] + public void CanSetIsDiffVisibleToFalse() + { + control.IsDiffVisible = false; + Assert.IsFalse(control.IsDiffVisible); + } + + [Test] + public void ShowFilesMethodProjectParameterSaved() + { + WixProject project = WixBindingTestsHelper.CreateEmptyWixProject(); + control.ShowFiles(project, null, null); + Assert.AreSame(project, control.ShowFilesMethodProjectParameter); + } + + [Test] + public void ShowFilesMethodFileReaderParameterSaved() + { + WorkbenchTextFileReader fileReader = new WorkbenchTextFileReader(); + control.ShowFiles(null, fileReader, null); + Assert.AreSame(fileReader, control.ShowFilesMethodFileReaderParameter); + } + + [Test] + public void ShowFilesMethodDocumentWriterParameterSaved() + { + MockWixDocumentWriter writer = new MockWixDocumentWriter(); + control.ShowFiles(null, null, writer); + Assert.AreSame(writer, control.ShowFilesMethodDocumentWriterParameter); + } + + [Test] + public void WixDocumentCanBeRetrieved() + { + WixDocument doc = new WixDocument(); + control.Document = doc; + Assert.AreSame(doc, control.Document); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchTests.cs new file mode 100644 index 0000000000..aeaea9ad17 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchTests.cs @@ -0,0 +1,67 @@ +// +// +// +// +// $Revision$ +// + +using System; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockWorkbenchTests + { + MockWorkbench workbench; + + [SetUp] + public void Init() + { + workbench = new MockWorkbench(); + } + + [Test] + public void ViewPassedToShowViewMethodIsAddedToViewContentsCollection() + { + MockViewContent view = new MockViewContent(); + workbench.ShowView(view); + Assert.IsTrue(workbench.ViewContentCollection.Contains(view)); + } + + [Test] + public void ActiveContentIsSaved() + { + MockViewContent view = new MockViewContent(); + workbench.ActiveContent = view; + Assert.AreSame(view, workbench.ActiveContent); + } + + [Test] + public void ActiveViewContentIsSaved() + { + MockViewContent view = new MockViewContent(); + workbench.ActiveViewContent = view; + Assert.AreSame(view, workbench.ActiveViewContent); + } + + [Test] + public void RaiseActiveViewContentChangedMethodFiresActiveViewContentChangedEvent() + { + bool eventFired = false; + workbench.ActiveViewContentChanged += delegate (object source, EventArgs e) + { eventFired = true; }; + + workbench.RaiseActiveViewContentChangedEvent(); + + Assert.IsTrue(eventFired); + } + + [Test] + public void RaiseActiveViewContentChangedMethodDoesNotThrowNullReferenceExceptionWhenNoEventHandlersConfigured() + { + Assert.DoesNotThrow(delegate { workbench.RaiseActiveViewContentChangedEvent(); }); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchWindowTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchWindowTests.cs new file mode 100644 index 0000000000..897f6847da --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockWorkbenchWindowTests.cs @@ -0,0 +1,39 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockWorkbenchWindowTests + { + MockWorkbenchWindow workbenchWindow; + + [SetUp] + public void Init() + { + workbenchWindow = new MockWorkbenchWindow(); + } + + [Test] + public void WorkbenchWindowSelectWindowMethodCalledIsInitiallyFalse() + { + Assert.IsFalse(workbenchWindow.SelectWindowMethodCalled); + } + + [Test] + public void WorkbenchWindowSelectMethodBeingCalledIsSaved() + { + workbenchWindow.SelectWindow(); + Assert.IsTrue(workbenchWindow.SelectWindowMethodCalled); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockXmlTextWriterTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockXmlTextWriterTests.cs new file mode 100644 index 0000000000..c1bbbf54a9 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockXmlTextWriterTests.cs @@ -0,0 +1,64 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Xml; +using NUnit.Framework; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockXmlTextWriterTests + { + MockXmlTextWriter mockXmlTextWriter; + MockTextEditorOptions options; + + [SetUp] + public void Init() + { + options = new MockTextEditorOptions(); + options.ConvertTabsToSpaces = false; + options.IndentationSize = 4; + mockXmlTextWriter = new MockXmlTextWriter(options); + } + + [Test] + public void TextWrittenToWriterUsesXmlWriterSettings() + { + using (XmlWriter writer = mockXmlTextWriter.Create("test.xml")) { + writer.WriteStartElement("root"); + writer.WriteStartElement("child"); + writer.WriteEndElement(); + writer.WriteEndElement(); + } + + string expectedXml = + "\r\n" + + "\t\r\n" + + ""; + + Assert.AreEqual(expectedXml, mockXmlTextWriter.GetXmlWritten()); + } + + [Test] + public void XmlWriterSettingsUsedInCreateMethodIsReturned() + { + mockXmlTextWriter.Create("test.xml"); + + XmlWriterSettings expectedSettings = new XmlWriterSettings(); + expectedSettings.IndentChars = "\t"; + expectedSettings.Indent = true; + expectedSettings.NewLineChars = "\r\n"; + expectedSettings.OmitXmlDeclaration = true; + expectedSettings.CloseOutput = true; + + XmlWriterSettingsComparison comparison = new XmlWriterSettingsComparison(); + Assert.IsTrue(comparison.AreEqual(expectedSettings, mockXmlTextWriter.XmlWriterSettingsPassedToCreateMethod), + comparison.ToString()); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/WixBindingTestsHelperTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/WixBindingTestsHelperTests.cs new file mode 100644 index 0000000000..bf9606fe98 --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/WixBindingTestsHelperTests.cs @@ -0,0 +1,52 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; + +using ICSharpCode.WixBinding; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class WixBindingTestsHelperTests + { + WixProject project; + + [SetUp] + public void Init() + { + project = WixBindingTestsHelper.CreateEmptyWixProject(); + } + + [Test] + public void CanGetEditorAttributeFromCollection() + { + BindableAttribute bindableAttribute = new BindableAttribute(false); + EditorAttribute editorAttribute = new EditorAttribute(); + + Attribute[] attributes = new Attribute[] { bindableAttribute, editorAttribute }; + AttributeCollection attributeCollection = new AttributeCollection(attributes); + + Assert.AreSame(editorAttribute, WixBindingTestsHelper.GetEditorAttribute(attributeCollection)); + } + + [Test] + public void WixProjectNameIsTest() + { + Assert.AreEqual("Test", project.Name); + } + + [Test] + public void WixProjectHasFileName() + { + Assert.AreEqual(@"C:\Projects\Test\Test.wixproj", project.FileName); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/XmlWriterSettingsComparisonTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/XmlWriterSettingsComparisonTests.cs new file mode 100644 index 0000000000..93536cfa7b --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/XmlWriterSettingsComparisonTests.cs @@ -0,0 +1,98 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Xml; +using NUnit.Framework; +using WixBinding.Tests.Utils; + +namespace WixBinding.Tests.Utils.Tests +{ + [TestFixture] + public class XmlWriterSettingsComparisonTests + { + XmlWriterSettings lhs; + XmlWriterSettings rhs; + XmlWriterSettingsComparison comparison; + + [SetUp] + public void Init() + { + lhs = new XmlWriterSettings(); + rhs = new XmlWriterSettings(); + comparison = new XmlWriterSettingsComparison(); + } + + [Test] + public void XmlWriterSettingsAreEqualByDefault() + { + Assert.IsTrue(comparison.AreEqual(lhs, rhs)); + } + + [Test] + public void AreEqualReturnsFalseWhenXmlWriterSettingsCloseOutputAreDifferent() + { + lhs.CloseOutput = true; + rhs.CloseOutput = false; + Assert.IsFalse(comparison.AreEqual(lhs, rhs)); + } + + [Test] + public void PropertyNameIsCloseOutputWhenXmlWriterSettingsCloseOutputAreDifferent() + { + AreEqualReturnsFalseWhenXmlWriterSettingsCloseOutputAreDifferent(); + Assert.AreEqual("CloseOutput", comparison.PropertyName); + } + + [Test] + public void AreEqualReturnsFalseWhenXmlWriterSettingsNewLineCharsAreDifferent() + { + lhs.NewLineChars = "a"; + rhs.NewLineChars = "b"; + Assert.IsFalse(comparison.AreEqual(lhs, rhs)); + } + + [Test] + public void PropertyNameIsNewLineCharsWhenXmlWriterSettingsNewLineCharsAreDifferent() + { + AreEqualReturnsFalseWhenXmlWriterSettingsNewLineCharsAreDifferent(); + Assert.AreEqual("NewLineChars", comparison.PropertyName); + } + + [Test] + public void ComparisonToStringHasNewLineCharsWhenXmlWriterSettingsNewLineCharsAreDifferent() + { + AreEqualReturnsFalseWhenXmlWriterSettingsNewLineCharsAreDifferent(); + Assert.AreEqual("Property NewLineChars is different.", comparison.ToString()); + } + + [Test] + public void ComparisonToStringIsEmptyStringWhenXmlWriterSettingsAreSame() + { + Assert.AreEqual(String.Empty, comparison.ToString()); + } + + [Test] + public void AreEqualReturnsFalseIfRhsIsNull() + { + Assert.IsFalse(comparison.AreEqual(lhs, null)); + } + + [Test] + public void AreEqualReturnsFalseIfLhsIsNull() + { + Assert.IsFalse(comparison.AreEqual(null, rhs)); + } + + [Test] + public void ComparisonToStringHasNullComparisionFailureWhenAreEqualRhsIsNull() + { + AreEqualReturnsFalseIfRhsIsNull(); + Assert.AreEqual("XmlWriterSetting is null.", comparison.ToString()); + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs index 28a32abd75..eabb6df72c 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs @@ -5,12 +5,15 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Internal.Templates; -using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.WixBinding; using System; using System.ComponentModel; using System.IO; +using System.Resources; + +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Internal.Templates; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.WixBinding; namespace WixBinding.Tests.Utils { @@ -87,5 +90,14 @@ namespace WixBinding.Tests.Utils folder = Path.GetFullPath(Path.Combine(folder, @"..\")); MSBuildEngine.MSBuildProperties["SharpDevelopBinPath"] = folder; } + + /// + /// Registers embedded strings with SharpDevelop's resource Manager + /// + public static void RegisterResourceStringsWithSharpDevelopResourceManager() + { + ResourceManager rm = new ResourceManager("WixBinding.Tests.Strings", typeof(WixBindingTestsHelper).Assembly); + ResourceService.RegisterNeutralStrings(rm); + } } } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/XmlWriterSettingsComparison.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/XmlWriterSettingsComparison.cs new file mode 100644 index 0000000000..9a7e2ac7cf --- /dev/null +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/XmlWriterSettingsComparison.cs @@ -0,0 +1,63 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Reflection; +using System.Xml; + +namespace WixBinding.Tests.Utils +{ + public class XmlWriterSettingsComparison + { + bool nullSettings; + + public XmlWriterSettingsComparison() + { + } + + public bool AreEqual(XmlWriterSettings lhs, XmlWriterSettings rhs) + { + if ((lhs == null) || (rhs == null)) { + nullSettings = true; + return false; + } + + foreach (PropertyInfo property in typeof(XmlWriterSettings).GetProperties()) { + object lhsValue = property.GetValue(lhs, new object[0]); + object rhsValue = property.GetValue(rhs, new object[0]); + + if (property.PropertyType == typeof(bool)) { + if ((bool)lhsValue != (bool)rhsValue) { + PropertyName = property.Name; + return false; + } + } else if (property.PropertyType == typeof(string)) { + if ((string)lhsValue != (string)rhsValue) { + PropertyName = property.Name; + return false; + } + } + } + return true; + } + + public string PropertyName { get; set; } + + public override string ToString() + { + if (nullSettings) { + return "XmlWriterSetting is null."; + } + + if (String.IsNullOrEmpty(PropertyName)) { + return String.Empty; + } + + return "Property " + PropertyName + " is different."; + } + } +} diff --git a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj index 7d7d5c75c8..cdaac744ff 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj @@ -1,4 +1,5 @@ - + + Library WixBinding.Tests @@ -35,8 +36,17 @@ + + 3.0 + + + 3.0 + + + 4.0 + @@ -46,6 +56,9 @@ False + + 3.0 + @@ -53,12 +66,33 @@ + + + + + + + + + + + + + + + + + + + + + @@ -72,6 +106,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -213,6 +271,7 @@ + @@ -243,6 +302,11 @@ + + + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} + ICSharpCode.AvalonEdit + {DCA2703D-250A-463E-A68A-07ED105AE6BD} XmlEditor diff --git a/src/AddIns/BackendBindings/WixBinding/WixBinding.sln b/src/AddIns/BackendBindings/WixBinding/WixBinding.sln index 22d22419ef..c828e06ae6 100644 --- a/src/AddIns/BackendBindings/WixBinding/WixBinding.sln +++ b/src/AddIns/BackendBindings/WixBinding/WixBinding.sln @@ -22,6 +22,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "..\..\DisplayB EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Widgets", "..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj", "{8035765F-D51F-4A0C-A746-2FD100E19419}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.AvalonEdit", "..\..\..\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvalonEdit.AddIn", "..\..\DisplayBindings\AvalonEdit.AddIn\AvalonEdit.AddIn.csproj", "{0162E499-42D0-409B-AA25-EED21F75336B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,5 +72,13 @@ Global {8035765F-D51F-4A0C-A746-2FD100E19419}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8035765F-D51F-4A0C-A746-2FD100E19419}.Release|Any CPU.Build.0 = Release|Any CPU {8035765F-D51F-4A0C-A746-2FD100E19419}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Release|Any CPU.Build.0 = Release|Any CPU + {6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0162E499-42D0-409B-AA25-EED21F75336B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0162E499-42D0-409B-AA25-EED21F75336B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.Build.0 = Release|Any CPU + {0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs index f6f0cfcc76..25580b6e40 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs @@ -155,7 +155,8 @@ namespace ICSharpCode.FormsDesigner { this.sourceCodeStorage.AddFile(mockFile, Encoding.UTF8); this.sourceCodeStorage.DesignerCodeFile = mockFile; - } + this.Files.Add(primaryViewContent.PrimaryFile); + } bool inMasterLoadOperation;