diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/IDirectoryReader.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/IDirectoryReader.cs
new file mode 100644
index 0000000000..ad3988ba41
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/IDirectoryReader.cs
@@ -0,0 +1,29 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+
+namespace ICSharpCode.WixBinding
+{
+ ///
+ /// Gets the files and directories for a specified path. This is used
+ /// to hide the file system from the WixPackageFilesEditor class when
+ /// testing.
+ ///
+ public interface IDirectoryReader
+ {
+ ///
+ /// Gets the files in the specified path.
+ ///
+ string[] GetFiles(string path);
+
+ ///
+ /// Gets the directories in the specified path.
+ ///
+ string[] GetDirectories(string path);
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs
index 8accf363ad..601e6d0e76 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs
@@ -49,7 +49,7 @@ namespace ICSharpCode.WixBinding
///
/// Converts a long filename to a short 8.3 filename.
///
- /// The long filename
+ /// The long filename.
/// The converted 8.3 filename. If the filename includes a
/// starting path then this is stripped from the returned value.
public static string Convert(string fileName, FileNameExists getFileNameExists)
@@ -127,6 +127,16 @@ namespace ICSharpCode.WixBinding
return false;
}
+ ///
+ /// Returns whether the character is considered a valid character
+ /// for the starting part of the filename (i.e. not including the extension).
+ ///
+ ///
+ /// We include the period character here to avoid ICE03 invalid filename
+ /// errors.
+ ///
+ /// http://msdn.microsoft.com/library/en-us/msi/setup/ice03.asp
+ ///
static bool IsValidShortFileNameChar(char ch)
{
switch (ch) {
@@ -136,6 +146,7 @@ namespace ICSharpCode.WixBinding
case ';':
case '=':
case ',':
+ case '.':
return false;
}
return true;
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
index d197f70731..c1a28aed4b 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
@@ -6,6 +6,7 @@
//
using System;
+using System.IO;
using System.Xml;
namespace ICSharpCode.WixBinding
@@ -37,6 +38,24 @@ namespace ICSharpCode.WixBinding
}
}
+ 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.
///
@@ -50,8 +69,77 @@ namespace ICSharpCode.WixBinding
///
public WixFileElement AddFile(string fileName)
{
- WixFileElement fileElement = new WixFileElement((WixDocument)OwnerDocument, fileName);
+ WixFileElement fileElement = new WixFileElement(this, fileName);
return (WixFileElement)AppendChild(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)
+ {
+ string id = GenerateIdFromFileName(fileName);
+ if (!document.ComponentIdExists(id)) {
+ return id;
+ }
+
+ // Add the parent folder to the id.
+ string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName));
+ parentDirectory = FirstCharacterToUpperInvariant(parentDirectory);
+ id = String.Concat(parentDirectory, id);
+ if (!document.ComponentIdExists(id)) {
+ return id;
+ }
+
+ // 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;
+ }
+
+ ///
+ /// Creates an id from the filename.
+ ///
+ ///
+ /// Takes the filename, removes all periods, and
+ /// capitalises the first character and first extension character.
+ ///
+ public static string GenerateIdFromFileName(string fileName)
+ {
+ string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);
+ string idStart = String.Empty;
+ if (fileNameNoExtension.Length > 0) {
+ idStart = FirstCharacterToUpperInvariant(fileNameNoExtension);
+ }
+
+ // Remove period from extension and uppercase first extension char.
+ string extension = Path.GetExtension(fileName);
+ string idEnd = String.Empty;
+ if (extension.Length > 1) {
+ idEnd = FirstCharacterToUpperInvariant(extension.Substring(1));
+ }
+ return String.Concat(idStart, idEnd);
+ }
+
+ ///
+ /// Upper cases first character of string.
+ ///
+ static string FirstCharacterToUpperInvariant(string s)
+ {
+ return String.Concat(s.Substring(0, 1).ToUpperInvariant(), s.Substring(1));
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
index c07548fcce..5c11ec9991 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElement.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Xml;
namespace ICSharpCode.WixBinding
@@ -29,6 +30,15 @@ namespace ICSharpCode.WixBinding
return name == DirectoryElementName;
}
+ ///
+ /// Returns the last directory specified in the path
+ ///
+ public static string GetLastDirectoryName(string path)
+ {
+ int index = path.LastIndexOf(Path.DirectorySeparatorChar);
+ return path.Substring(index + 1);
+ }
+
///
/// Creates the directory element and sets its Id and SourceName.
///
@@ -108,6 +118,17 @@ namespace ICSharpCode.WixBinding
}
}
+ ///
+ /// Checks to see if a File element exists with the specified
+ /// short filename.
+ ///
+ public bool ShortFileNameExists(string fileName)
+ {
+ string xpath = String.Concat("w:Component/w:File[@Name='", fileName, "']");
+ XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(OwnerDocument.NameTable));
+ return nodes.Count > 0;
+ }
+
///
/// Returns whether the specified name maps to a system directory.
///
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
index da0dfeef86..2bae127e10 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
@@ -574,8 +574,16 @@ namespace ICSharpCode.WixBinding
///
public WixDirectoryElement AddRootDirectory()
{
+ // Add product element if it does not exist.
+ XmlElement productElement = Product;
+ if (productElement == null) {
+ productElement = CreateWixElement("Product");
+ DocumentElement.AppendChild(productElement);
+ }
+
+ // Add root directory.
WixDirectoryElement rootDirectory = WixDirectoryElement.CreateRootDirectory(this);
- return (WixDirectoryElement)Product.AppendChild(rootDirectory);
+ return (WixDirectoryElement)productElement.AppendChild(rootDirectory);
}
///
@@ -640,6 +648,24 @@ namespace ICSharpCode.WixBinding
return base.CreateElement(prefix, localName, namespaceURI);
}
+ ///
+ /// Checks to see if a File element exists with the specified id in this
+ /// document.
+ ///
+ public bool FileIdExists(string id)
+ {
+ return ElementIdExists(WixFileElement.FileElementName, id);
+ }
+
+ ///
+ /// Checks to see if a Component element exists with the specified id in this
+ /// document.
+ ///
+ public bool ComponentIdExists(string id)
+ {
+ return ElementIdExists(WixComponentElement.ComponentElementName, id);
+ }
+
///
/// Reads the dialog id and adds it to the list of dialogs found so far.
///
@@ -761,5 +787,15 @@ namespace ICSharpCode.WixBinding
string xpath = String.Concat("//w:Dialog[@Id='", 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='", id, "']");
+ XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(NameTable));
+ return nodes.Count > 0;
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs
index c7faa71eea..7af7d36f7c 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs
@@ -19,6 +19,8 @@ namespace ICSharpCode.WixBinding
public class WixFileElement : XmlElement
{
public const string FileElementName = "File";
+
+ WixComponentElement parentComponent;
public WixFileElement(WixDocument document)
: base(document.WixNamespacePrefix, FileElementName, WixNamespaceManager.Namespace, document)
@@ -30,6 +32,12 @@ namespace ICSharpCode.WixBinding
Init(fileName);
}
+ public WixFileElement(WixComponentElement component, string fileName) : this((WixDocument)component.OwnerDocument)
+ {
+ parentComponent = component;
+ Init(fileName);
+ }
+
///
/// Generates an id from the filename.
///
@@ -50,6 +58,11 @@ namespace ICSharpCode.WixBinding
return id.ToString();
}
+ ///
+ /// Gets the filename where the resource being added to the setup
+ /// package can be found. Typically this isrelative to the Wix document the
+ /// File element is a part of.
+ ///
public string Source {
get {
return GetAttribute("Source");
@@ -60,7 +73,7 @@ namespace ICSharpCode.WixBinding
}
///
- /// Gets the short name of the file.
+ /// Gets the short name (8.3) of the file.
///
public string ShortName {
get {
@@ -80,6 +93,9 @@ namespace ICSharpCode.WixBinding
}
}
+ ///
+ /// The is the filename that will be used when installing the file.
+ ///
public string LongName {
get {
return GetAttribute("LongName");
@@ -154,17 +170,66 @@ namespace ICSharpCode.WixBinding
string idFileName = shortFileName;
if (shortFileName.Length > ShortFileName.MaximumFileNameLength) {
longFileName = shortFileName;
- shortFileName = ShortFileName.Convert(shortFileName);
+ shortFileName = ShortFileName.Convert(shortFileName, ShortFileNameExists);
idFileName = longFileName;
}
-
ShortName = shortFileName;
- Id = GenerateId(idFileName);
+ Id = GenerateUniqueId(Path.GetDirectoryName(fileName), idFileName);
if (longFileName != null) {
LongName = longFileName;
}
}
+
+ ///
+ /// 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);
+ WixDocument document = (WixDocument)OwnerDocument;
+ if (!document.FileIdExists(id)) {
+ return id;
+ }
+
+ // Add the file's parent directory to the id.
+ string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory);
+ if (parentDirectoryName.Length > 0) {
+ id = String.Concat(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;
+ }
+
+ ///
+ /// Determines if the short filename already exists in the document.
+ ///
+ bool ShortFileNameExists(string fileName)
+ {
+ if (parentComponent == null) {
+ return false;
+ }
+ WixDirectoryElement directoryElement = parentComponent.ParentNode as WixDirectoryElement;
+ return directoryElement.ShortFileNameExists(fileName);
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
index c4aff8b399..7f7ce9d8fb 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
@@ -23,10 +23,27 @@ namespace ICSharpCode.WixBinding
IWixPackageFilesView view;
ITextFileReader fileReader;
IWixDocumentWriter documentWriter;
+ IDirectoryReader directoryReader;
WixDocument document;
WixSchemaCompletionData wixSchemaCompletionData;
bool usingRootDirectoryRef;
+ ///
+ /// Gets the files and directories in the specified path.
+ ///
+ class DefaultDirectoryReader : IDirectoryReader
+ {
+ public string[] GetFiles(string path)
+ {
+ return Directory.GetFiles(path);
+ }
+
+ public string[] GetDirectories(string path)
+ {
+ return Directory.GetDirectories(path);
+ }
+ }
+
///
/// Creates a new instance of the WixPackageFilesEditor.
///
@@ -35,11 +52,23 @@ namespace ICSharpCode.WixBinding
/// workbench from the editor so the class can be easily tested.
/// The file writer hides the file system and the
/// workbench from the editor.
- public WixPackageFilesEditor(IWixPackageFilesView view, ITextFileReader fileReader, IWixDocumentWriter documentWriter)
+ /// The directory reader hides the file system
+ /// from the editor.
+ public WixPackageFilesEditor(IWixPackageFilesView view, ITextFileReader fileReader, IWixDocumentWriter documentWriter, IDirectoryReader directoryReader)
{
this.view = view;
this.fileReader = fileReader;
this.documentWriter = documentWriter;
+ this.directoryReader = directoryReader;
+ }
+
+ ///
+ /// Creates a new instance of the WixPackageFilesEditor which uses
+ /// the default directory reader which just uses the Directory class.
+ ///
+ public WixPackageFilesEditor(IWixPackageFilesView view, ITextFileReader fileReader, IWixDocumentWriter documentWriter)
+ : this(view, fileReader, documentWriter, new DefaultDirectoryReader())
+ {
}
///
@@ -130,10 +159,10 @@ namespace ICSharpCode.WixBinding
XmlElement element = null;
switch (name) {
case WixDirectoryElement.DirectoryElementName:
- element = AddDirectory(parentElement as WixDirectoryElement);
+ element = AddDirectory(parentElement as WixDirectoryElement, "NewDirectory");
break;
case WixComponentElement.ComponentElementName:
- element = AddComponent(parentElement as WixDirectoryElement);
+ element = AddComponent(parentElement as WixDirectoryElement, "NewComponent");
break;
default:
element = AddElement(parentElement, name);
@@ -170,6 +199,26 @@ namespace ICSharpCode.WixBinding
}
}
+ ///
+ /// Adds the specified directory to the selected element. This
+ /// adds all the contained files and subdirectories recursively to the
+ /// setup package.
+ ///
+ public void AddDirectory(string directory)
+ {
+ WixDirectoryElement parentElement = (WixDirectoryElement)view.SelectedElement;
+
+ // Add directory.
+ string directoryName = WixDirectoryElement.GetLastDirectoryName(directory);
+ WixDirectoryElement directoryElement = AddDirectory(parentElement, directoryName);
+ AddFiles(directoryElement, directory);
+
+ // Adds directory contents recursively.
+ AddDirectoryContents(directoryElement, directory);
+
+ AddElementToView(directoryElement);
+ }
+
///
/// Adds a single file to the selected component element.
///
@@ -177,12 +226,24 @@ namespace ICSharpCode.WixBinding
{
WixComponentElement componentElement = view.SelectedElement as WixComponentElement;
if (componentElement != null) {
- WixFileElement fileElement = componentElement.AddFile(fileName);
+ WixFileElement fileElement = AddFile(componentElement, fileName);
view.AddElement(fileElement);
view.IsDirty = true;
}
}
+ ///
+ /// Adds a file to the specified component element.
+ ///
+ WixFileElement AddFile(WixComponentElement componentElement, string fileName)
+ {
+ WixFileElement fileElement = componentElement.AddFile(fileName);
+ if (!componentElement.HasDiskId) {
+ componentElement.DiskId = "1";
+ }
+ return fileElement;
+ }
+
///
/// Updates the attribute values for the element.
///
@@ -210,7 +271,7 @@ namespace ICSharpCode.WixBinding
///
/// Adds a new directory with a autogenerated id.
///
- WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement)
+ WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name)
{
if (parentElement == null) {
if (usingRootDirectoryRef) {
@@ -222,7 +283,9 @@ namespace ICSharpCode.WixBinding
}
}
}
- return parentElement.AddDirectory("NewDirectory");
+ WixDirectoryElement directoryElement = parentElement.AddDirectory(name);
+ directoryElement.ShortName = name;
+ return directoryElement;
}
WixSchemaCompletionData WixSchemaCompletionData {
@@ -257,11 +320,11 @@ namespace ICSharpCode.WixBinding
///
/// Adds a new component element to the directory element.
///
- WixComponentElement AddComponent(WixDirectoryElement parentElement)
+ /// The id attribute the component element will have.
+ WixComponentElement AddComponent(WixDirectoryElement parentElement, string id)
{
if (parentElement != null) {
- WixComponentElement element = parentElement.AddComponent("NewComponent");
- element.Id = "NewComponent";
+ WixComponentElement element = parentElement.AddComponent(id);
return element;
}
return null;
@@ -298,5 +361,43 @@ namespace ICSharpCode.WixBinding
}
return FindRootDirectoryResult.NoMatch;
}
+
+ ///
+ /// Adds the set of files to the specified directory element. Each file
+ /// gets its own parent component element.
+ ///
+ void AddFiles(WixDirectoryElement directoryElement, string directory)
+ {
+ foreach (string fileName in DirectoryReader.GetFiles(directory)) {
+ string path = Path.Combine(directory, fileName);
+ string id = WixComponentElement.GenerateIdFromFileName(document, path);
+ WixComponentElement component = AddComponent(directoryElement, id);
+ AddFile(component, path);
+ }
+ }
+
+ IDirectoryReader DirectoryReader {
+ get {
+ return directoryReader;
+ }
+ }
+
+ ///
+ /// Adds any subdirectories and files to the directory element.
+ ///
+ /// The directory element to add
+ /// the components and subdirectories to.
+ /// The full path of the directory.
+ void AddDirectoryContents(WixDirectoryElement directoryElement, string directory)
+ {
+ foreach (string subDirectoryName in DirectoryReader.GetDirectories(directory)) {
+ string subDirectory = Path.Combine(directory, subDirectoryName);
+ WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName);
+ AddFiles(subDirectoryElement, subDirectory);
+
+ // Add the subdirectory contents.
+ AddDirectoryContents(subDirectoryElement, subDirectory);
+ }
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
index 9c28dc68ef..a401265a34 100644
--- a/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
+++ b/src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
@@ -137,6 +137,7 @@
+
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs
new file mode 100644
index 0000000000..96e03ecfe2
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs
@@ -0,0 +1,187 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.SharpDevelop.Project;
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+using System.Xml;
+using WixBinding.Tests.PackageFiles;
+using WixBinding.Tests.Utils;
+
+namespace WixBinding.Tests.DirectoryImport
+{
+ ///
+ /// Adds several directories and its contained files to the setup package.
+ /// The original package has no directories, only the root directory is
+ /// defined.
+ ///
+ [TestFixture]
+ public class AddDirectoryTestFixture : PackageFilesTestFixtureBase
+ {
+ WixDirectoryElement appDirectoryElement;
+ WixComponentElement myAppExeFileComponentElement;
+ WixFileElement myAppExeFileElement;
+ WixDirectoryElement docsDirectoryElement;
+ WixDirectoryElement srcDirectoryElement;
+ WixDirectoryElement cssDirectoryElement;
+ WixFileElement readmeFileElement;
+ string docsDirectory = @"C:\Projects\Test\MyApp\docs";
+ string cssDirectory = @"C:\Projects\Test\MyApp\docs\css";
+ string srcDirectory = @"C:\Projects\Test\MyApp\src";
+ string directory = @"C:\Projects\Test\MyApp";
+ string myAppExeFile = "MyApp.exe";
+ string[] srcFiles = new string[] {"MyProj.sln", "MyProj.csproj", "Main.cs"};
+ string[] docFiles = new string[] {"readme.txt", "license.txt"};
+
+ [TestFixtureSetUp]
+ public void SetUpFixture()
+ {
+ base.InitFixture();
+ editor.AddDirectory(directory);
+
+ WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
+ appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild;
+ myAppExeFileComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component", nsManager);
+ myAppExeFileElement = (WixFileElement)myAppExeFileComponentElement.LastChild;
+ docsDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='docs']", nsManager);
+ srcDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='src']", nsManager);
+ cssDirectoryElement = (docsDirectoryElement.GetDirectories())[0];
+ readmeFileElement = (WixFileElement)docsDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager);
+ }
+
+ [Test]
+ public void IsDirty()
+ {
+ Assert.IsTrue(view.IsDirty);
+ }
+
+ [Test]
+ public void DirectoryElementAddedToView()
+ {
+ Assert.IsInstanceOfType(typeof(WixDirectoryElement), view.ElementsAdded[0]);
+ }
+
+ [Test]
+ public void AppDirectoryName()
+ {
+ Assert.AreEqual("MyApp", appDirectoryElement.ShortName);
+ }
+
+ [Test]
+ public void AppDirectoryLongName()
+ {
+ Assert.AreEqual(String.Empty, appDirectoryElement.LongName);
+ }
+
+ [Test]
+ public void AppDirectoryId()
+ {
+ Assert.AreEqual("MyApp", appDirectoryElement.Id);
+ }
+
+ [Test]
+ public void AppDirectoryHasChildComponent()
+ {
+ Assert.IsNotNull(myAppExeFileComponentElement);
+ }
+
+ [Test]
+ public void AppExeComponentDiskId()
+ {
+ Assert.AreEqual("1", myAppExeFileComponentElement.DiskId);
+ }
+
+ [Test]
+ public void AppExeFileElementShortName()
+ {
+ Assert.AreEqual("MyApp.exe", myAppExeFileElement.ShortName);
+ }
+
+ [Test]
+ public void AppExeFileElementId()
+ {
+ Assert.AreEqual("MyApp.exe", myAppExeFileElement.Id);
+ }
+
+ [Test]
+ public void AddExeSourceFile()
+ {
+ Assert.AreEqual(@"MyApp\MyApp.exe", myAppExeFileElement.Source);
+ }
+
+ [Test]
+ public void DocDirectoryElementExists()
+ {
+ Assert.IsNotNull(docsDirectoryElement);
+ }
+
+ [Test]
+ public void SrcDirectoryElementExists()
+ {
+ Assert.IsNotNull(srcDirectoryElement);
+ }
+
+ [Test]
+ public void CssDirectoryElementExists()
+ {
+ Assert.IsNotNull(cssDirectoryElement);
+ }
+
+ [Test]
+ public void ReadmeFileElementExists()
+ {
+ Assert.IsNotNull(readmeFileElement);
+ }
+
+ [Test]
+ public void AppExeComponentId()
+ {
+ Assert.AreEqual("MyAppExe", myAppExeFileComponentElement.Id);
+ }
+
+ public override string[] GetFiles(string path)
+ {
+ if (path == docsDirectory) {
+ return docFiles;
+ } else if (path == srcDirectory) {
+ return srcFiles;
+ } else if (path == cssDirectory) {
+ return new string[0];
+ }
+ return new string[] {myAppExeFile};
+ }
+
+ public override string[] GetDirectories(string path)
+ {
+ if (path == directory) {
+ return new string[] {"docs", "src"};
+ } else if (path == docsDirectory) {
+ return new string[] {"css"};
+ }
+ return new string[0];
+ }
+
+ 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" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs
new file mode 100644
index 0000000000..3daf5ac174
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs
@@ -0,0 +1,103 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.SharpDevelop.Project;
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+using System.Xml;
+using WixBinding.Tests.PackageFiles;
+using WixBinding.Tests.Utils;
+
+namespace WixBinding.Tests.DirectoryImport
+{
+ ///
+ /// Adds a subdirectory to an existing directory in the package files editor.
+ ///
+ [TestFixture]
+ public class AddSubDirectoryTestFixture : PackageFilesTestFixtureBase
+ {
+ WixDirectoryElement appDirectoryElement;
+ WixFileElement exeFileElement;
+ WixFileElement readmeFileElement;
+ string directory = @"C:\Projects\Setup\MyApp";
+ string[] files = new string[] {"MyApp.exe", "readme.txt"};
+
+ [TestFixtureSetUp]
+ public void SetUpFixture()
+ {
+ base.InitFixture();
+ WixDirectoryElement programFilesFolderElement = (WixDirectoryElement)editor.Document.RootDirectory.FirstChild;
+ view.SelectedElement = programFilesFolderElement;
+ editor.AddDirectory(directory);
+
+ appDirectoryElement = (WixDirectoryElement)programFilesFolderElement.FirstChild;
+ exeFileElement = (WixFileElement)appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='MyApp.exe']", new WixNamespaceManager(editor.Document.NameTable));
+ readmeFileElement = (WixFileElement)appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", new WixNamespaceManager(editor.Document.NameTable));
+ }
+
+ [Test]
+ public void IsDirty()
+ {
+ Assert.IsTrue(view.IsDirty);
+ }
+
+ [Test]
+ public void DirectoryElementAddedToView()
+ {
+ Assert.IsInstanceOfType(typeof(WixDirectoryElement), view.ElementsAdded[0]);
+ }
+
+ [Test]
+ public void AppDirectoryName()
+ {
+ Assert.AreEqual("MyApp", appDirectoryElement.ShortName);
+ }
+
+ [Test]
+ public void ExeFileElementAdded()
+ {
+ Assert.IsNotNull(exeFileElement);
+ }
+
+ [Test]
+ public void ReadmeFileElementAdded()
+ {
+ Assert.IsNotNull(readmeFileElement);
+ }
+
+ ///
+ /// Gets the MyApp directory files.
+ ///
+ ///
+ ///
+ public override string[] GetFiles(string path)
+ {
+ return files;
+ }
+
+ protected override string GetWixXml()
+ {
+ return "\r\n" +
+ "\t\r\n" +
+ "\t\t\r\n" +
+ "\t\t\r\n" +
+ "\t\t\t\r\n" +
+ "\t\t\t\r\n" +
+ "\t\t\r\n" +
+ "\t\r\n" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs
new file mode 100644
index 0000000000..5e9978f0b5
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs
@@ -0,0 +1,119 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.SharpDevelop.Project;
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+using System.Xml;
+using WixBinding.Tests.PackageFiles;
+using WixBinding.Tests.Utils;
+
+namespace WixBinding.Tests.DirectoryImport
+{
+ ///
+ /// Adds several directories and its contained files to the setup package.
+ /// The original package has several components already defined. This
+ /// test fixture checks that unique component ids are generated for the new
+ /// files.
+ ///
+ [TestFixture]
+ public class DuplicateComponentIdTestFixture : PackageFilesTestFixtureBase
+ {
+ WixDirectoryElement appDirectoryElement;
+ WixComponentElement readmeComponentElement;
+ WixComponentElement licenseComponentElement;
+ WixComponentElement exeComponentElement;
+ string directory = @"C:\Projects\Test\MyApp";
+ string[] files = new string[] {"MyApp.exe", "readme.txt", "license.txt"};
+
+ [TestFixtureSetUp]
+ public void SetUpFixture()
+ {
+ base.InitFixture();
+ editor.AddDirectory(directory);
+
+ WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
+ appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager);;
+ XmlNode fileElement = appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager);
+ readmeComponentElement = (WixComponentElement)fileElement.ParentNode;
+
+ fileElement = appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='license.txt']", nsManager);
+ licenseComponentElement = (WixComponentElement)fileElement.ParentNode;
+
+ exeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager);
+ }
+
+ ///
+ /// Parent directory is added to component id.
+ ///
+ [Test]
+ public void ReadmeComponentId()
+ {
+ Assert.AreEqual("MyAppReadmeTxt", readmeComponentElement.Id);
+ }
+
+ [Test]
+ public void LicenseComponentId()
+ {
+ Assert.AreEqual("MyAppLicenseTxt1", licenseComponentElement.Id);
+ }
+
+ [Test]
+ public void AppExeComponentId()
+ {
+ Assert.AreEqual("MyAppMyAppExe2", exeComponentElement.Id);
+ }
+
+ public override string[] GetFiles(string path)
+ {
+ if (path == directory) {
+ return files;
+ }
+ return new string[0];
+ }
+
+ public override string[] GetDirectories(string path)
+ {
+ return new string[0];
+ }
+
+ protected override string GetWixXml()
+ {
+ return "\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\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\r\n" +
+ "\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" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/AddRootDirectoryWithNoProductElementTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/AddRootDirectoryWithNoProductElementTestFixture.cs
new file mode 100644
index 0000000000..50cb9790ee
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/AddRootDirectoryWithNoProductElementTestFixture.cs
@@ -0,0 +1,32 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+
+namespace WixBinding.Tests.Document
+{
+ [TestFixture]
+ public class AddRootDirectoryWithNoProductElementTestFixture
+ {
+ [Test]
+ public void AddRootDirectory()
+ {
+ WixDocument doc = new WixDocument();
+ doc.LoadXml(GetWixXml());
+ WixDirectoryElement element = doc.AddRootDirectory();
+ Assert.IsNotNull(element);
+ }
+
+ string GetWixXml()
+ {
+ return "\r\n" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs
new file mode 100644
index 0000000000..680afdcf9e
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs
@@ -0,0 +1,109 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Xml;
+
+namespace WixBinding.Tests.Document
+{
+ [TestFixture]
+ public class ExistingFileIdGenerationTests
+ {
+ WixDocument doc;
+ WixComponentElement component;
+
+ [SetUp]
+ public void Init()
+ {
+ doc = new WixDocument();
+ doc.FileName = @"C:\Projects\Setup\Setup.wxs";
+ doc.LoadXml(GetWixXml());
+ component = (WixComponentElement)doc.SelectSingleNode("//w:Component", new WixNamespaceManager(doc.NameTable));
+ }
+
+ [Test]
+ public void FileIdAlreadyExists()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\doc\license.txt");
+ Assert.AreEqual("doc.license.txt", fileElement.Id);
+ }
+
+ [Test]
+ public void FileIdExists()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\doc\license.txt");
+ Assert.IsTrue(doc.FileIdExists("license.txt"));
+ }
+
+ [Test]
+ public void FileIdAlreadyExistsAndParentDirectoryUsingAltDirSeparator()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/doc/license.txt");
+ Assert.AreEqual("doc.license.txt", fileElement.Id);
+ }
+
+ [Test]
+ public void FileIdAlreadyExistsAndNoParentDirectory()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"license.txt");
+ Assert.AreEqual("license1.txt", fileElement.Id);
+ }
+
+ [Test]
+ public void FileIdAlreadyExistsAndParentDirectoryIsRoot()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"C:\license.txt");
+ Assert.AreEqual("license1.txt", fileElement.Id);
+ }
+
+ [Test]
+ public void FileIdWithNumberAlreadyExists()
+ {
+ component.AddFile(@"license.txt");
+ WixFileElement fileElement = new WixFileElement(doc, @"license.txt");
+ Assert.AreEqual("license2.txt", fileElement.Id);
+ }
+
+ [Test]
+ public void FileIdWithParentDirectoryAndNumberExists()
+ {
+ component.AddFile(@"C:/Projects/Setup/doc/license.txt");
+ WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/doc/license.txt");
+ Assert.AreEqual("doc.license1.txt", fileElement.Id);
+ }
+
+ string GetWixXml()
+ {
+ return "\r\n" +
+ "\t\r\n" +
+ "\t\t\r\n" +
+ "\t\t\r\n" +
+ "\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\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\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\r\n" +
+ "\t\t\r\n" +
+ "\t\r\n" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingShortFileNameTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingShortFileNameTests.cs
new file mode 100644
index 0000000000..3248fce911
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingShortFileNameTests.cs
@@ -0,0 +1,91 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Xml;
+
+namespace WixBinding.Tests.Document
+{
+ ///
+ /// Tests that the short filename generated takes into account existing
+ /// short filenames in the document. Note that only those files inside the
+ /// same directory are considered. It is perfectly valid to have the same
+ /// short filename installed to a different directory.
+ ///
+ [TestFixture]
+ public class ExistingShortNameTests
+ {
+ WixDocument doc;
+ WixComponentElement component;
+ WixComponentElement myAppComponent;
+
+ [SetUp]
+ public void Init()
+ {
+ doc = new WixDocument();
+ doc.FileName = @"C:\Projects\Setup\Setup.wxs";
+ doc.LoadXml(GetWixXml());
+ component = (WixComponentElement)doc.SelectSingleNode("//w:Component[@Id='SharpDevelopDocFiles']", new WixNamespaceManager(doc.NameTable));
+ myAppComponent = (WixComponentElement)doc.SelectSingleNode("//w:Component[@Id='SharpDevelopMyAppFiles']", new WixNamespaceManager(doc.NameTable));
+ }
+
+ [Test]
+ public void ShortNameAlreadyExists()
+ {
+ component.AddFile(@"C:\Projects\Setup\doc\changelog.xml");
+ WixFileElement fileElement = (WixFileElement)component.LastChild;
+ Assert.AreEqual("CHANGE_2.XML", fileElement.ShortName);
+ }
+
+ [Test]
+ public void ShortNameDoesNotExistInParentDirectory()
+ {
+ myAppComponent.AddFile(@"C:\Projects\Setup\doc\changelog.xml");
+ WixFileElement fileElement = (WixFileElement)myAppComponent.LastChild;
+ Assert.AreEqual("CHANGE_1.XML", fileElement.ShortName);
+ }
+
+ string GetWixXml()
+ {
+ return "\r\n" +
+ "\t\r\n" +
+ "\t\t\r\n" +
+ "\t\t\r\n" +
+ "\t\t\t\r\n" +
+ "\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\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\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\t\t\t\t\t\r\n" +
+ "\t\t\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\r\n" +
+ "\t\t\r\n" +
+ "\t\r\n" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs
index bc50692116..a367dabf72 100644
--- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddFilesTestFixture.cs
@@ -30,7 +30,7 @@ namespace WixBinding.Tests.PackageFiles
string readmeFileName;
[SetUp]
- public void SetUpFixture()
+ public void Init()
{
base.InitFixture();
componentElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0].ChildNodes[0];
@@ -120,6 +120,12 @@ namespace WixBinding.Tests.PackageFiles
{
Assert.AreSame(view.ElementsAdded[1], readmeFileElement);
}
+
+ [Test]
+ public void ComponentElementDiskId()
+ {
+ Assert.AreEqual("1", componentElement.GetAttribute("DiskId"));
+ }
protected override string GetWixXml()
{
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs
new file mode 100644
index 0000000000..835cf9064b
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ComponentDiskIdSetBeforeFilesAddedTestFixture.cs
@@ -0,0 +1,68 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.SharpDevelop.Project;
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+using System.Collections.Specialized;
+using System.IO;
+using System.Xml;
+using WixBinding.Tests.Utils;
+
+namespace WixBinding.Tests.PackageFiles
+{
+ ///
+ /// Adds several files to the selected component node when the component's
+ /// disk id is already set. This makes sure we do not change the disk id.
+ ///
+ [TestFixture]
+ public class ComponentDiskIdSetBeforeFilesAddedTestFixture : PackageFilesTestFixtureBase
+ {
+ XmlElement componentElement;
+
+ [SetUp]
+ public void Init()
+ {
+ base.InitFixture();
+ componentElement = (XmlElement)editor.Document.RootDirectory.ChildNodes[0].ChildNodes[0].ChildNodes[0];
+ view.SelectedElement = componentElement;
+ editor.SelectedElementChanged();
+ string exeFileName = Path.Combine(project.Directory, @"bin\TestApplication.exe");
+ string readmeFileName = Path.Combine(project.Directory, @"docs\readme.rtf");
+ string[] fileNames = new string[] {exeFileName, readmeFileName};
+ editor.AddFiles(fileNames);
+ }
+
+ [Test]
+ public void ComponentElementDiskId()
+ {
+ Assert.AreEqual("2", componentElement.GetAttribute("DiskId"));
+ }
+
+ protected override string GetWixXml()
+ {
+ return "\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\r\n" +
+ "\t\t\t\t\r\n" +
+ "\t\t\t\r\n" +
+ "\t\t\r\n" +
+ "\t\r\n" +
+ "";
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/FileIdGenerationTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/FileIdGenerationTests.cs
index 9a2847edbb..214bd8bbb4 100644
--- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/FileIdGenerationTests.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/FileIdGenerationTests.cs
@@ -8,12 +8,23 @@
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
+using System.Xml;
namespace WixBinding.Tests.PackageFiles
{
[TestFixture]
public class FileIdGenerationTests
{
+ WixDocument doc;
+
+ [TestFixtureSetUp]
+ public void SetupFixture()
+ {
+ doc = new WixDocument();
+ doc.FileName = @"C:\Projects\Setup\Setup.wxs";
+ doc.LoadXml("");
+ }
+
[Test]
public void ShortFileName()
{
@@ -27,7 +38,6 @@ namespace WixBinding.Tests.PackageFiles
Assert.AreEqual(String.Empty, WixFileElement.GenerateId(null));
}
-
[Test]
public void TruncatedShortFileName()
{
@@ -55,5 +65,12 @@ namespace WixBinding.Tests.PackageFiles
string fileName = "AEèSTAP.TXT";
Assert.AreEqual("AE_STAP.TXT", WixFileElement.GenerateId(fileName));
}
+
+ [Test]
+ public void NewWixFileElement()
+ {
+ WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\Files\readme.txt");
+ Assert.AreEqual("readme.txt", fileElement.Id);
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs
new file mode 100644
index 0000000000..b89ad0a6e5
--- /dev/null
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GenerateComponentIdTests.cs
@@ -0,0 +1,51 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using ICSharpCode.WixBinding;
+using NUnit.Framework;
+using System;
+
+namespace WixBinding.Tests.PackageFiles
+{
+ [TestFixture]
+ public class GenerateComponentIdTests
+ {
+ [Test]
+ public void SimpleFileName()
+ {
+ string fileName = "myapp.exe";
+ Assert.AreEqual("MyappExe", WixComponentElement.GenerateIdFromFileName(fileName));
+ }
+
+ [Test]
+ public void NoExtension()
+ {
+ string fileName = "myapp";
+ Assert.AreEqual("Myapp", WixComponentElement.GenerateIdFromFileName(fileName));
+ }
+
+ [Test]
+ public void OnlyExtension()
+ {
+ string fileName = ".bat";
+ Assert.AreEqual("Bat", WixComponentElement.GenerateIdFromFileName(fileName));
+ }
+
+ [Test]
+ public void SingleCharacterFileName()
+ {
+ string fileName = "a.bat";
+ Assert.AreEqual("ABat", WixComponentElement.GenerateIdFromFileName(fileName));
+ }
+
+ [Test]
+ public void EmptyString()
+ {
+ Assert.AreEqual(String.Empty, WixComponentElement.GenerateIdFromFileName(String.Empty));
+ }
+ }
+}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesTestFixtureBase.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesTestFixtureBase.cs
index c3547beda0..9205d22bd6 100644
--- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesTestFixtureBase.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/PackageFilesTestFixtureBase.cs
@@ -21,7 +21,7 @@ namespace WixBinding.Tests.PackageFiles
/// one setup.wxs file, creates the WixPackageEditor and calls its ShowPackageFiles
/// method.
///
- public class PackageFilesTestFixtureBase : ITextFileReader, IWixDocumentWriter
+ public class PackageFilesTestFixtureBase : ITextFileReader, IWixDocumentWriter, IDirectoryReader
{
protected WixPackageFilesEditor editor;
protected MockWixPackageFilesView view;
@@ -35,7 +35,7 @@ namespace WixBinding.Tests.PackageFiles
item.Include = "Setup.wxs";
project.Items.Add(item);
view = new MockWixPackageFilesView();
- editor = new WixPackageFilesEditor(view, this, this);
+ editor = new WixPackageFilesEditor(view, this, this, this);
editor.ShowFiles(project);
}
@@ -62,5 +62,15 @@ namespace WixBinding.Tests.PackageFiles
}
return null;
}
+
+ public virtual string[] GetFiles(string path)
+ {
+ return new string[0];
+ }
+
+ public virtual string[] GetDirectories(string path)
+ {
+ return new string[0];
+ }
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs
index 34dddd393b..172d92d900 100644
--- a/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs
+++ b/src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs
@@ -90,8 +90,14 @@ namespace WixBinding.Tests.PackageFiles
returnFileNameExistsCount = 99;
Assert.AreEqual("ABCD_100.TXT", ShortFileName.Convert(name, GetFileNameExists));
}
-
+ [Test]
+ public void PeriodsRemovedFromFileNameStart()
+ {
+ string name = "boo.exe.config";
+ Assert.AreEqual("BOOEXE.CON", ShortFileName.Convert(name));
+ }
+
bool GetFileNameExists(string fileName)
{
if (returnFileNameExistsCount == 0) {
@@ -100,6 +106,5 @@ namespace WixBinding.Tests.PackageFiles
--returnFileNameExistsCount;
return true;
}
-
}
}
diff --git a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj
index 84b24a764d..a9b45a2af4 100644
--- a/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj
+++ b/src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj
@@ -19,7 +19,7 @@
..\..\..\..\..\bin\UnitTests\
False
- DEBUG;TRACE
+ DEBUG%3bTRACE
true
Full
True
@@ -189,6 +189,14 @@
+
+
+
+
+
+
+
+
@@ -246,6 +254,7 @@
Always
+
\ No newline at end of file