Browse Source

WiX Setup Files property grid now has a file browser and drop down lists with possible attribute values based on the WiX schema.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1860 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
3f2e742b70
  1. 81
      src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/DropDownEditor.cs
  2. 79
      src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/DropDownEditorListBox.cs
  3. 38
      src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/GuidEditor.cs
  4. 57
      src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/RelativeFileNameEditor.cs
  5. 14
      src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/WixXmlAttributePropertyDescriptor.cs
  6. 27
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs
  7. 4
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
  8. 43
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixSchemaCompletionData.cs
  9. 50
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixXmlAttribute.cs
  10. 1
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixXmlAttributeType.cs
  11. 3
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
  12. 76
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GetRelativeFileNameTestFixture.cs
  13. 5
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/MissingFileAttributesTestFixture.cs
  14. 43
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs
  15. 9
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixSchemaTests.cs
  16. 48
      src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/DropDownPropertyDescriptorTestFixture.cs
  17. 107
      src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/DropDownTypeEditorTestFixture.cs
  18. 51
      src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/FileNamePropertyDescriptorTestFixture.cs
  19. 19
      src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/GuidPropertyDescriptorTestFixture.cs
  20. 8
      src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/WixXmlAttributePropertyDescriptorTestFixture.cs
  21. 9
      src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWindowsFormsEditorService.cs
  22. 16
      src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs
  23. 4
      src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj

81
src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/DropDownEditor.cs

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace ICSharpCode.WixBinding
{
public class DropDownEditor : UITypeEditor
{
/// <summary>
/// Returns the drop down style.
/// </summary>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override bool IsDropDownResizable {
get {
return false;
}
}
/// <summary>
/// Shows the drop down editor control in the drop down so the user
/// can change the value.
/// </summary>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService = null;
if (provider != null) {
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
}
if (editorService != null) {
using (Control control = CreateDropDownControl(context, editorService)) {
SetValue(control, value);
editorService.DropDownControl(control);
value = GetValue(control);
}
}
return value;
}
/// <summary>
/// Creates the drop down control.
/// </summary>
protected virtual Control CreateDropDownControl(ITypeDescriptorContext context, IWindowsFormsEditorService editorService)
{
return new DropDownEditorListBox(context, editorService);
}
/// <summary>
/// Sets the current value in the drop down control.
/// </summary>
protected virtual void SetValue(Control control, object value)
{
DropDownEditorListBox listBox = (DropDownEditorListBox)control;
listBox.Value = (string)value;
}
/// <summary>
/// Gets the current value from the drop down control.
/// </summary>
protected virtual object GetValue(Control control)
{
DropDownEditorListBox listBox = (DropDownEditorListBox)control;
return listBox.Value;
}
}
}

79
src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/DropDownEditorListBox.cs

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace ICSharpCode.WixBinding
{
public class DropDownEditorListBox : ListBox
{
IWindowsFormsEditorService editorService;
string dropDownValue = String.Empty;
WixXmlAttributePropertyDescriptor propertyDescriptor;
public DropDownEditorListBox(ITypeDescriptorContext context, IWindowsFormsEditorService editorService)
{
this.editorService = editorService;
BorderStyle = BorderStyle.None;
if (context != null) {
propertyDescriptor = context.PropertyDescriptor as WixXmlAttributePropertyDescriptor;
}
AddDropDownItems();
}
public string Value {
get {
return dropDownValue;
}
set {
dropDownValue = value;
SelectListItem(dropDownValue);
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
int index = IndexFromPoint(e.Location);
if (index != -1) {
dropDownValue = (string)SelectedItem;
editorService.CloseDropDown();
}
}
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.KeyData == Keys.Return) {
if (SelectedIndex != -1) {
dropDownValue = (string)SelectedItem;
}
editorService.CloseDropDown();
}
}
void AddDropDownItems()
{
if (propertyDescriptor != null && propertyDescriptor.WixXmlAttribute.HasValues) {
foreach (string item in propertyDescriptor.WixXmlAttribute.Values) {
Items.Add(item);
}
}
}
void SelectListItem(string item)
{
int index = Items.IndexOf(item);
SelectedIndex = index;
}
}
}

38
src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/GuidEditor.cs

@ -16,41 +16,27 @@ namespace ICSharpCode.WixBinding @@ -16,41 +16,27 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// Property grid editor for Guids
/// </summary>
public class GuidEditor : UITypeEditor
public class GuidEditor : DropDownEditor
{
public GuidEditor()
{
}
/// <summary>
/// Returns the drop down style.
/// </summary>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
protected override Control CreateDropDownControl(ITypeDescriptorContext context, IWindowsFormsEditorService editorService)
{
return UITypeEditorEditStyle.DropDown;
return new GuidEditorListBox(editorService);
}
/// <summary>
/// Shows the Guid editor control in the drop down so the user
/// can change the Guid.
/// </summary>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
protected override void SetValue(Control control, object value)
{
IWindowsFormsEditorService editorService = null;
if (provider != null) {
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
}
if (editorService != null) {
using (GuidEditorListBox listBox = new GuidEditorListBox(editorService)) {
listBox.Guid = (string)value;
editorService.DropDownControl(listBox);
value = listBox.Guid;
}
}
return value;
GuidEditorListBox listBox = (GuidEditorListBox)control;
listBox.Guid = (string)value;
}
protected override object GetValue(Control control)
{
GuidEditorListBox listBox = (GuidEditorListBox)control;
return listBox.Guid;
}
}
}

57
src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/RelativeFileNameEditor.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Windows.Forms.Design;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Used to editor relative filenames in the property grid.
/// </summary>
public class RelativeFileNameEditor : FileNameEditor
{
public RelativeFileNameEditor()
{
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
WixDocument document = GetWixDocument(context);
// Convert relative path to full path for editing.
string relativePath = (string)value;
string fullPath = document.GetFullPath(relativePath);
string newFullPath = (string)base.EditValue(context, provider, fullPath);
// Convert full path back to relative path.
return document.GetRelativePath(newFullPath);
}
/// <summary>
/// Gets the Wix document associated with the property
/// descriptor.
/// </summary>
WixDocument GetWixDocument(ITypeDescriptorContext context)
{
WixDocument document = null;
if (context != null) {
WixXmlAttributePropertyDescriptor propertyDescriptor = context.PropertyDescriptor as WixXmlAttributePropertyDescriptor;
if (propertyDescriptor != null) {
document = propertyDescriptor.WixXmlAttribute.Document;
}
}
if (document != null) {
return document;
}
return new WixDocument();
}
}
}

14
src/AddIns/BackendBindings/WixBinding/Project/Src/PropertyGrid/WixXmlAttributePropertyDescriptor.cs

@ -41,6 +41,12 @@ namespace ICSharpCode.WixBinding @@ -41,6 +41,12 @@ namespace ICSharpCode.WixBinding
return new PropertyDescriptorCollection(properties.ToArray());
}
public WixXmlAttribute WixXmlAttribute {
get {
return wixXmlAttribute;
}
}
public override Type ComponentType {
get {
return wixXmlAttribute.GetType();
@ -108,6 +114,14 @@ namespace ICSharpCode.WixBinding @@ -108,6 +114,14 @@ namespace ICSharpCode.WixBinding
case WixXmlAttributeType.Uuid:
attributes.Add(new EditorAttribute(typeof(GuidEditor), typeof(UITypeEditor)));
break;
case WixXmlAttributeType.FileName:
attributes.Add(new EditorAttribute(typeof(RelativeFileNameEditor), typeof(UITypeEditor)));
break;
case WixXmlAttributeType.Text:
if (wixXmlAttribute.HasValues) {
attributes.Add(new EditorAttribute(typeof(DropDownEditor), typeof(UITypeEditor)));
}
break;
}
return attributes.ToArray();
}

27
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDocument.cs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
@ -666,6 +667,32 @@ namespace ICSharpCode.WixBinding @@ -666,6 +667,32 @@ namespace ICSharpCode.WixBinding
return ElementIdExists(WixComponentElement.ComponentElementName, id);
}
/// <summary>
/// Returns the full path based on the location of
/// this WixDocument.
/// </summary>
public string GetFullPath(string relativePath)
{
if (fileName != null && fileName.Length > 0) {
string basePath = Path.GetDirectoryName(fileName);
return FileUtility.GetAbsolutePath(basePath, relativePath);
}
return relativePath;
}
/// <summary>
/// Returns the relative path based on the location of
/// this WixDocument.
/// </summary>
public string GetRelativePath(string fullPath)
{
if (fileName != null && fileName.Length > 0) {
string basePath = Path.GetDirectoryName(fileName);
return FileUtility.GetRelativePath(basePath, fullPath);
}
return fullPath;
}
/// <summary>
/// Reads the dialog id and adds it to the list of dialogs found so far.
/// </summary>

4
src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.WixBinding @@ -25,7 +25,7 @@ namespace ICSharpCode.WixBinding
ITextFileReader fileReader;
IWixDocumentWriter documentWriter;
IDirectoryReader directoryReader;
WixDocument document;
static WixDocument document;
WixSchemaCompletionData wixSchemaCompletionData;
bool usingRootDirectoryRef;
StringCollection excludedItems = new StringCollection();
@ -58,6 +58,7 @@ namespace ICSharpCode.WixBinding @@ -58,6 +58,7 @@ namespace ICSharpCode.WixBinding
/// from the editor.</param>
public WixPackageFilesEditor(IWixPackageFilesView view, ITextFileReader fileReader, IWixDocumentWriter documentWriter, IDirectoryReader directoryReader)
{
document = null;
this.view = view;
this.fileReader = fileReader;
this.documentWriter = documentWriter;
@ -79,6 +80,7 @@ namespace ICSharpCode.WixBinding @@ -79,6 +80,7 @@ namespace ICSharpCode.WixBinding
public void ShowFiles(WixProject project)
{
// Look for Wix document containing root directory.
document = null;
if (project.WixSourceFiles.Count > 0) {
bool errors = false;
WixDocument currentDocument = null;

43
src/AddIns/BackendBindings/WixBinding/Project/Src/WixSchemaCompletionData.cs

@ -67,13 +67,28 @@ namespace ICSharpCode.WixBinding @@ -67,13 +67,28 @@ namespace ICSharpCode.WixBinding
foreach (XmlAttribute attribute in element.Attributes) {
string attributeName = attribute.Name;
WixXmlAttributeType type = GetWixAttributeType(elementName, attributeName);
WixXmlAttribute wixAttribute = new WixXmlAttribute(attributeName, attribute.Value, type);
WixDocument document = GetWixDocument(element);
string[] attributeValues = GetAttributeValues(elementName, attributeName);
WixXmlAttribute wixAttribute = new WixXmlAttribute(attributeName, attribute.Value, type, attributeValues, document);
attributes.Add(wixAttribute);
}
attributes.AddRange(GetMissingAttributes(elementName, attributes, GetAttributeNames(elementName)));
attributes.AddRange(GetMissingAttributes(element, attributes, GetAttributeNames(elementName)));
return attributes;
}
/// <summary>
/// Gets the attribute values allowed for the specified attribute.
/// </summary>
public string[] GetAttributeValues(string elementName, string attributeName)
{
XmlElementPath path = GetPath(elementName);
List<string> values = new List<string>();
foreach (ICompletionData data in GetAttributeValueCompletionData(path, attributeName)) {
values.Add(data.Text);
}
return values.ToArray();
}
/// <summary>
/// Returns the deprecated attributes for the specified element name.
/// </summary>
@ -220,6 +235,14 @@ namespace ICSharpCode.WixBinding @@ -220,6 +235,14 @@ namespace ICSharpCode.WixBinding
return WixXmlAttributeType.ComponentGuid;
}
}
if (elementName == "File") {
switch (attributeName) {
case "Source":
case "src":
return WixXmlAttributeType.FileName;
}
}
return WixXmlAttributeType.Text;
}
@ -227,16 +250,28 @@ namespace ICSharpCode.WixBinding @@ -227,16 +250,28 @@ namespace ICSharpCode.WixBinding
/// Gets the attributes that have not been added to the
/// <paramref name="attributes"/>.
/// </summary>
WixXmlAttributeCollection GetMissingAttributes(string elementName, WixXmlAttributeCollection existingAttributes, string[] attributes)
WixXmlAttributeCollection GetMissingAttributes(XmlElement element, WixXmlAttributeCollection existingAttributes, string[] attributes)
{
WixXmlAttributeCollection missingAttributes = new WixXmlAttributeCollection();
foreach (string name in attributes) {
if (existingAttributes[name] == null) {
string elementName = element.Name;
WixXmlAttributeType type = GetWixAttributeType(elementName, name);
missingAttributes.Add(new WixXmlAttribute(name, type));
string[] attributeValues = GetAttributeValues(elementName, name);
WixDocument document = GetWixDocument(element);
missingAttributes.Add(new WixXmlAttribute(name, type, attributeValues, document));
}
}
return missingAttributes;
}
/// <summary>
/// Gets the WixDocument from the XmlElement if it is associated with
/// a WixDocument.
/// </summary>
WixDocument GetWixDocument(XmlElement element)
{
return element.OwnerDocument as WixDocument;
}
}
}

50
src/AddIns/BackendBindings/WixBinding/Project/Src/WixXmlAttribute.cs

@ -19,19 +19,33 @@ namespace ICSharpCode.WixBinding @@ -19,19 +19,33 @@ namespace ICSharpCode.WixBinding
/// </summary>
public class WixXmlAttribute
{
string[] values;
string name = String.Empty;
string attributeValue = String.Empty;
WixXmlAttributeType type = WixXmlAttributeType.Text;
WixDocument document;
public WixXmlAttribute(string name, string value, WixXmlAttributeType type)
public WixXmlAttribute(string name, string value, WixXmlAttributeType type, string[] values, WixDocument document)
{
this.name = name;
attributeValue = value;
this.type = type;
this.values = values;
this.document = document;
}
public WixXmlAttribute(string name, string value, WixXmlAttributeType type)
: this(name, value, type, new string[0], null)
{
}
public WixXmlAttribute(string name, WixXmlAttributeType type)
: this(name, String.Empty, type, new string[0], null)
{
}
public WixXmlAttribute(string name, WixXmlAttributeType type)
: this(name, String.Empty, type)
public WixXmlAttribute(string name, WixXmlAttributeType type, string[] values, WixDocument document)
: this(name, String.Empty, type, values, document)
{
}
@ -68,5 +82,35 @@ namespace ICSharpCode.WixBinding @@ -68,5 +82,35 @@ namespace ICSharpCode.WixBinding
return type;
}
}
/// <summary>
/// Gets the set of allowed values for this attribute.
/// </summary>
public string[] Values {
get {
return values;
}
}
/// <summary>
/// Gets whether this attribute has any allowed values.
/// </summary>
public bool HasValues {
get {
if (values != null) {
return values.Length > 0;
}
return false;
}
}
/// <summary>
/// Gets the WixDocument this attribute is associated with.
/// </summary>
public WixDocument Document {
get {
return document;
}
}
}
}

1
src/AddIns/BackendBindings/WixBinding/Project/Src/WixXmlAttributeType.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.WixBinding @@ -13,6 +13,7 @@ namespace ICSharpCode.WixBinding
{
AutogenUuid,
ComponentGuid,
FileName,
Uuid,
Text
}

3
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj

@ -141,6 +141,9 @@ @@ -141,6 +141,9 @@
<Compile Include="Src\Commands\AddDirectoryCommand.cs" />
<Compile Include="Src\PropertyGrid\GuidEditor.cs" />
<Compile Include="Src\PropertyGrid\GuidEditorListBox.cs" />
<Compile Include="Src\PropertyGrid\RelativeFileNameEditor.cs" />
<Compile Include="Src\PropertyGrid\DropDownEditor.cs" />
<Compile Include="Src\PropertyGrid\DropDownEditorListBox.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="WixBinding.addin">

76
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/GetRelativeFileNameTestFixture.cs

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
namespace WixBinding.Tests.PackageFiles
{
[TestFixture]
public class GetRelativeFileNameTestFixture
{
WixDocument doc;
string fullPathBeforeWixDocumentLoaded;
string relativePathBeforeWixDocumentLoaded;
[SetUp]
public void Init()
{
doc = new WixDocument();
string relativeFileNamePath = @"..\..\bin\Test.exe";
fullPathBeforeWixDocumentLoaded = doc.GetFullPath(relativeFileNamePath);
string fullFileName = @"C:\Projects\MySetup\Test\Test.exe";
relativePathBeforeWixDocumentLoaded = doc.GetRelativePath(fullFileName);
doc.LoadXml("<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'></Wix>");
doc.FileName = @"C:\Projects\Test\Setup.wxs";
}
/// <summary>
/// The WixPackageFilesEditor does not change the path if no document
/// is loaded since there is no WixDocument to work out the full path.
/// </summary>
[Test]
public void FullPathBeforeWixDocumentLoaded()
{
Assert.AreEqual(@"..\..\bin\Test.exe", fullPathBeforeWixDocumentLoaded);
}
/// <summary>
/// Again the path should be the same as that passed in since
/// no WixDocument is available to work out the relative path.
/// </summary>
[Test]
public void RelativePathBeforeWixDocumentLoaded()
{
Assert.AreEqual(@"C:\Projects\MySetup\Test\Test.exe", relativePathBeforeWixDocumentLoaded);
}
[Test]
public void FullPath()
{
string relativePath = @"..\Source\bin\Test.exe";
Assert.AreEqual(@"C:\Projects\Source\bin\Test.exe", doc.GetFullPath(relativePath));
}
[Test]
public void RelativePath()
{
string fullPath = @"C:\Projects\MyTest\bin\Test.exe";
Assert.AreEqual(@"..\MyTest\bin\Test.exe", doc.GetRelativePath(fullPath));
}
[Test]
public void NullWixDocumentFileName()
{
doc.FileName = null;
string relativeFileNamePath = @"..\..\bin\Test.exe";
Assert.AreEqual(relativeFileNamePath, doc.GetFullPath(relativeFileNamePath));
}
}
}

5
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/MissingFileAttributesTestFixture.cs

@ -16,13 +16,13 @@ namespace WixBinding.Tests.PackageFiles @@ -16,13 +16,13 @@ namespace WixBinding.Tests.PackageFiles
[TestFixture]
public class MissingAttributesTests
{
XmlDocument doc;
WixDocument doc;
WixSchemaCompletionData schema = new WixSchemaCompletionData();
[TestFixtureSetUp]
public void SetUpFixture()
{
doc = new XmlDocument();
doc = new WixDocument();
doc.LoadXml("<Wix xmlns='" + WixNamespaceManager.Namespace + "'/>");
}
@ -32,6 +32,7 @@ namespace WixBinding.Tests.PackageFiles @@ -32,6 +32,7 @@ namespace WixBinding.Tests.PackageFiles
XmlElement element = doc.CreateElement("File", WixNamespaceManager.Namespace);
WixXmlAttributeCollection attributes = schema.GetAttributes(element);
Assert.IsTrue(attributes.Count > 0);
Assert.IsTrue(Object.ReferenceEquals(attributes[0].Document, doc));
}
[Test]

43
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixAttributeTypeTests.cs

@ -18,12 +18,17 @@ namespace WixBinding.Tests.PackageFiles @@ -18,12 +18,17 @@ namespace WixBinding.Tests.PackageFiles
WixXmlAttribute productIdAttribute;
WixXmlAttribute productUpgradeCodeAttribute;
WixXmlAttribute componentGuidAttribute;
WixXmlAttribute componentKeyPathAttribute;
WixXmlAttribute fileSourceAttribute;
WixXmlAttribute fileSrcAttribute;
WixSchemaCompletionData wixSchema = new WixSchemaCompletionData();
WixDocument doc;
[SetUp]
public void Init()
{
WixDocument doc = new WixDocument();
doc = new WixDocument();
doc.FileName = @"C:\Projects\Setup\Files.wxs";
doc.LoadXml(GetWixXml());
XmlElement productElement = doc.Product;
WixXmlAttributeCollection attributes = wixSchema.GetAttributes(productElement);
@ -33,6 +38,12 @@ namespace WixBinding.Tests.PackageFiles @@ -33,6 +38,12 @@ namespace WixBinding.Tests.PackageFiles
XmlElement componentElement = (XmlElement)doc.SelectSingleNode("//w:Component", new WixNamespaceManager(doc.NameTable));
attributes = wixSchema.GetAttributes(componentElement);
componentGuidAttribute = attributes["Guid"];
componentKeyPathAttribute = attributes["KeyPath"];
XmlElement fileElement = (XmlElement)doc.SelectSingleNode("//w:File", new WixNamespaceManager(doc.NameTable));
attributes = wixSchema.GetAttributes(fileElement);
fileSourceAttribute = attributes["Source"];
fileSrcAttribute = attributes["src"];
}
[Test]
@ -40,6 +51,12 @@ namespace WixBinding.Tests.PackageFiles @@ -40,6 +51,12 @@ namespace WixBinding.Tests.PackageFiles
{
Assert.AreEqual(WixXmlAttributeType.AutogenUuid, productIdAttribute.AttributeType);
}
[Test]
public void ProductIdAttributeHasDocument()
{
Assert.IsTrue(Object.ReferenceEquals(doc, productIdAttribute.Document));
}
[Test]
public void UpgradeCodeAttributeIsUuid()
@ -53,6 +70,26 @@ namespace WixBinding.Tests.PackageFiles @@ -53,6 +70,26 @@ namespace WixBinding.Tests.PackageFiles
Assert.AreEqual(WixXmlAttributeType.ComponentGuid, componentGuidAttribute.AttributeType);
}
[Test]
public void FileSourceAttributeIsFileName()
{
Assert.AreEqual(WixXmlAttributeType.FileName, fileSourceAttribute.AttributeType);
}
[Test]
public void FileSrcAttributeIsFileName()
{
Assert.AreEqual(WixXmlAttributeType.FileName, fileSrcAttribute.AttributeType);
}
[Test]
public void KeyPathHasYesNoValues()
{
Assert.Contains("yes", componentKeyPathAttribute.Values);
Assert.Contains("no", componentKeyPathAttribute.Values);
Assert.AreEqual(WixXmlAttributeType.Text, componentKeyPathAttribute.AttributeType);
}
string GetWixXml()
{
return "<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\r\n" +
@ -63,7 +100,9 @@ namespace WixBinding.Tests.PackageFiles @@ -63,7 +100,9 @@ namespace WixBinding.Tests.PackageFiles
"\t Id='????????-????-????-????-????????????'>\r\n" +
"\t\t<Fragment>\r\n" +
"\t\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
"\t\t\t\t<Component Guid=''/>\r\n" +
"\t\t\t\t<Component Guid=''>\r\n" +
"\t\t\t\t\t<File src='bin\\test.exe'/>\r\n" +
"\t\t\t\t</Component>\r\n" +
"\t\t\t</Directory>\r\n" +
"\t\t</Fragment>\r\n" +
"\t</Product>\r\n" +

9
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/WixSchemaTests.cs

@ -67,5 +67,14 @@ namespace WixBinding.Tests.PackageFiles @@ -67,5 +67,14 @@ namespace WixBinding.Tests.PackageFiles
QualifiedName attributeName = schema.GetAttributeType("Product", "Id");
Assert.AreEqual("autogenuuid", attributeName.Name);
}
[Test]
public void ComponentKeyPathAttributeValues()
{
string[] values = schema.GetAttributeValues("Component", "KeyPath");
Assert.AreEqual(2, values.Length);
Assert.Contains("yes", values);
Assert.Contains("no", values);
}
}
}

48
src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/DropDownPropertyDescriptorTestFixture.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.PropertyGrid
{
/// <summary>
/// Tests that the DropDownEditor is specified as the editor for a
/// WixAttributePropertyDescriptor that has possible attribute values.
/// </summary>
[TestFixture]
public class DropDownPropertyDescriptorTestFixture
{
WixXmlAttributePropertyDescriptor propertyDescriptor;
EditorAttribute editorAttribute;
[TestFixtureSetUp]
public void SetUpFixture()
{
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.Text, new string[] {"a", "b"}, null);
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute);
editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes);
}
[Test]
public void EditorAttributeAdded()
{
Assert.IsNotNull(editorAttribute);
}
[Test]
public void EditorAttributeTypeName()
{
Assert.AreEqual(typeof(DropDownEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName);
}
}
}

107
src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/DropDownTypeEditorTestFixture.cs

@ -0,0 +1,107 @@ @@ -0,0 +1,107 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.PropertyGrid
{
[TestFixture]
public class DropDownTypeEditorTestFixture
{
DropDownEditor editor;
object newValue;
string expectedNewValue;
MockServiceProvider mockServiceProvider;
MockWindowsFormsEditorService mockWindowsFormsEditorService;
Type expectedControlType;
[TestFixtureSetUp]
public void SetUpFixture()
{
editor = new DropDownEditor();
// Edit the value.
mockServiceProvider = new MockServiceProvider();
mockWindowsFormsEditorService = new MockWindowsFormsEditorService();
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService);
expectedNewValue = "NewValue";
mockWindowsFormsEditorService.SetNewValue(expectedNewValue);
newValue = editor.EditValue(mockServiceProvider, "Test");
expectedControlType = mockWindowsFormsEditorService.GetDropDownControlTypeUsed();
}
[Test]
public void DropDownEditStyle()
{
Assert.AreEqual(UITypeEditorEditStyle.DropDown, editor.GetEditStyle());
}
[Test]
public void IsDropDownResizable()
{
Assert.IsFalse(editor.IsDropDownResizable);
}
[Test]
public void NewValue()
{
Assert.AreEqual(newValue, expectedNewValue);
}
[Test]
public void WindowsFormsEditorServiceRequested()
{
Assert.AreEqual(typeof(IWindowsFormsEditorService),
mockServiceProvider.GetServiceRequested(0));
}
[Test]
public void SameValueReturnedIfNoServiceProviderSet()
{
string oldValue = "Test";
string newValue = (string)editor.EditValue(null, null, oldValue);
Assert.IsTrue(Object.ReferenceEquals(oldValue, newValue));
}
[Test]
public void SameValueReturnedIfWindowsFormsServiceReturned()
{
mockServiceProvider.SetServiceToReturn(null);
string oldValue = "Test";
string newValue = (string)editor.EditValue(null, mockServiceProvider, oldValue);
Assert.IsTrue(Object.ReferenceEquals(oldValue, newValue));
Assert.AreEqual(typeof(IWindowsFormsEditorService),
mockServiceProvider.GetServiceRequested(1));
}
[Test]
public void SameValueReturnedIfNotEdited()
{
mockWindowsFormsEditorService = new MockWindowsFormsEditorService();
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService);
string oldValue = "test";
string newValue = (string)editor.EditValue(null, mockServiceProvider, oldValue);
Assert.AreEqual(oldValue, newValue);
}
[Test]
public void DropDownEditorControlUsedAsDropDownControl()
{
Assert.AreEqual("DropDownEditorListBox", expectedControlType.Name);
}
}
}

51
src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/FileNamePropertyDescriptorTestFixture.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.PropertyGrid
{
[TestFixture]
public class FileNamePropertyDescriptorTestFixture
{
WixXmlAttributePropertyDescriptor propertyDescriptor;
EditorAttribute editorAttribute;
[TestFixtureSetUp]
public void SetUpFixture()
{
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.FileName);
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute);
editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes);
}
[Test]
public void EditorAttributeAdded()
{
Assert.IsNotNull(editorAttribute);
}
[Test]
public void EditorAttributeBaseTypeName()
{
Assert.AreEqual(typeof(UITypeEditor).AssemblyQualifiedName, editorAttribute.EditorBaseTypeName);
}
[Test]
public void EditorAttributeTypeName()
{
Assert.AreEqual(typeof(RelativeFileNameEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName);
}
}
}

19
src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/GuidPropertyDescriptorTestFixture.cs

@ -11,6 +11,7 @@ using System; @@ -11,6 +11,7 @@ using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.PropertyGrid
{
@ -25,7 +26,7 @@ namespace WixBinding.Tests.PropertyGrid @@ -25,7 +26,7 @@ namespace WixBinding.Tests.PropertyGrid
{
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.ComponentGuid);
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute);
editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes);
editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes);
}
[Test]
@ -51,7 +52,7 @@ namespace WixBinding.Tests.PropertyGrid @@ -51,7 +52,7 @@ namespace WixBinding.Tests.PropertyGrid
{
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.AutogenUuid);
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute);
EditorAttribute editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes);
EditorAttribute editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes);
Assert.IsNotNull(editorAttribute);
Assert.AreEqual(typeof(GuidEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName);
@ -62,22 +63,10 @@ namespace WixBinding.Tests.PropertyGrid @@ -62,22 +63,10 @@ namespace WixBinding.Tests.PropertyGrid
{
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.Uuid);
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute);
EditorAttribute editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes);
EditorAttribute editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes);
Assert.IsNotNull(editorAttribute);
Assert.AreEqual(typeof(GuidEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName);
}
static EditorAttribute GetEditorAttribute(AttributeCollection attributes)
{
foreach (Attribute attribute in attributes) {
EditorAttribute editorAttribute = attribute as EditorAttribute;
if (editorAttribute != null) {
return editorAttribute;
}
}
return null;
}
}
}

8
src/AddIns/BackendBindings/WixBinding/Test/PropertyGrid/WixXmlAttributePropertyDescriptorTestFixture.cs

@ -24,13 +24,19 @@ namespace WixBinding.Tests.PropertyGrid @@ -24,13 +24,19 @@ namespace WixBinding.Tests.PropertyGrid
wixXmlAttribute = new WixXmlAttribute("LongName", "InitialValue", WixXmlAttributeType.Text);
pd = new WixXmlAttributePropertyDescriptor(wixXmlAttribute);
}
[Test]
public void Name()
{
Assert.AreEqual("LongName", pd.Name);
}
[Test]
public void WixXmlAttributeSet()
{
Assert.IsTrue(Object.ReferenceEquals(wixXmlAttribute, pd.WixXmlAttribute));
}
[Test]
public void NoAttributes()
{

9
src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWindowsFormsEditorService.cs

@ -31,9 +31,12 @@ namespace WixBinding.Tests.Utils @@ -31,9 +31,12 @@ namespace WixBinding.Tests.Utils
controlType = control.GetType();
if (newValueSet) {
GuidEditorListBox listBox = control as GuidEditorListBox;
if (listBox != null) {
listBox.Guid = newValue;
GuidEditorListBox guidListBox = control as GuidEditorListBox;
DropDownEditorListBox dropDownListBox = control as DropDownEditorListBox;
if (guidListBox != null) {
guidListBox.Guid = newValue;
} else if (dropDownListBox != null) {
dropDownListBox.Value = newValue;
}
}
}

16
src/AddIns/BackendBindings/WixBinding/Test/Utils/WixBindingTestsHelper.cs

@ -9,6 +9,7 @@ using ICSharpCode.SharpDevelop.Internal.Templates; @@ -9,6 +9,7 @@ using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding;
using System;
using System.ComponentModel;
namespace WixBinding.Tests.Utils
{
@ -24,7 +25,6 @@ namespace WixBinding.Tests.Utils @@ -24,7 +25,6 @@ namespace WixBinding.Tests.Utils
/// <summary>
/// Creates a WixProject that contains no WixObject or WixLibrary items.
/// </summary>
/// <returns></returns>
public static WixProject CreateEmptyWixProject()
{
ProjectCreateInformation info = new ProjectCreateInformation();
@ -33,5 +33,19 @@ namespace WixBinding.Tests.Utils @@ -33,5 +33,19 @@ namespace WixBinding.Tests.Utils
return new WixProject(info);
}
/// <summary>
/// Returns the EditorAttribute in the AttributeCollection.
/// </summary>
public static EditorAttribute GetEditorAttribute(AttributeCollection attributes)
{
foreach (Attribute attribute in attributes) {
EditorAttribute editorAttribute = attribute as EditorAttribute;
if (editorAttribute != null) {
return editorAttribute;
}
}
return null;
}
}
}

4
src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj

@ -207,6 +207,10 @@ @@ -207,6 +207,10 @@
<Compile Include="Utils\MockServiceProvider.cs" />
<Compile Include="Utils\MockWindowsFormsEditorService.cs" />
<Compile Include="PropertyGrid\GuidPropertyDescriptorTestFixture.cs" />
<Compile Include="PropertyGrid\FileNamePropertyDescriptorTestFixture.cs" />
<Compile Include="PackageFiles\GetRelativeFileNameTestFixture.cs" />
<Compile Include="PropertyGrid\DropDownTypeEditorTestFixture.cs" />
<Compile Include="PropertyGrid\DropDownPropertyDescriptorTestFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project\WixBinding.csproj">

Loading…
Cancel
Save