Browse Source

Ported WixBinding.Tests to MSBuild 4.0.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/dotnet4@4300 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
13a3c93e61
  1. 40
      src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs
  2. 51
      src/AddIns/BackendBindings/WixBinding/Test/Project/CreateWixProjectItemTests.cs
  3. 12
      src/AddIns/BackendBindings/WixBinding/Test/Project/WixBuilderCannotBuildNonWixProjectTestFixture.cs
  4. 2
      src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj
  5. 57
      src/Main/Base/Project/Src/Project/Items/ProjectItem.cs
  6. 4
      src/Main/Base/Project/Src/Project/MSBuildItemWrapper.cs

40
src/AddIns/BackendBindings/WixBinding/Test/Project/CreateNewWixProjectObjectTestFixture.cs

@ -5,6 +5,7 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using Microsoft.Build.Construction;
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
@ -12,7 +13,6 @@ using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding; using ICSharpCode.WixBinding;
using MSBuild = Microsoft.Build.BuildEngine;
using NUnit.Framework; using NUnit.Framework;
using WixBinding.Tests.Utils; using WixBinding.Tests.Utils;
@ -68,17 +68,10 @@ namespace WixBinding.Tests.Project
[Test] [Test]
public void Imports() public void Imports()
{ {
// this is machine-dependent, it's possible that additional imports are loaded lock (project.SyncRoot) {
//Assert.AreEqual(2, project.MSBuildProject.Imports.Count); Assert.AreEqual(1, project.MSBuildProjectFile.Imports.Count());
Microsoft.Build.BuildEngine.Import[] imports = new Microsoft.Build.BuildEngine.Import[project.MSBuildProject.Imports.Count]; Assert.AreEqual(WixProject.DefaultTargetsFile, project.MSBuildProjectFile.Imports.Single().Project);
project.MSBuildProject.Imports.CopyTo(imports, 0);
string[] paths = new string[imports.Length];
for (int i = 0; i < imports.Length; i++) {
paths[i] = imports[i].ProjectPath;
} }
Assert.Contains(WixProject.DefaultTargetsFile, paths);
} }
[Test] [Test]
@ -90,7 +83,7 @@ namespace WixBinding.Tests.Project
[Test] [Test]
public void WixToolPathCondition() public void WixToolPathCondition()
{ {
MSBuild.BuildProperty property = GetMSBuildProperty("WixToolPath"); ProjectPropertyElement property = GetMSBuildProperty("WixToolPath");
Assert.AreEqual(" '$(WixToolPath)' == '' ", property.Condition); Assert.AreEqual(" '$(WixToolPath)' == '' ", property.Condition);
} }
@ -99,13 +92,13 @@ namespace WixBinding.Tests.Project
{ {
Assert.IsNull(project.GetUnevalatedProperty("ToolPath")); Assert.IsNull(project.GetUnevalatedProperty("ToolPath"));
} }
[Test] [Test]
public void WixMSBuildExtensionsPathShouldNotExist() public void WixMSBuildExtensionsPathShouldNotExist()
{ {
Assert.IsNull(project.GetUnevalatedProperty("WixMSBuildExtensionsPath")); Assert.IsNull(project.GetUnevalatedProperty("WixMSBuildExtensionsPath"));
} }
[Test] [Test]
public void WixTargetsPath() public void WixTargetsPath()
{ {
@ -115,7 +108,7 @@ namespace WixBinding.Tests.Project
[Test] [Test]
public void WixTargetsPathCondition() public void WixTargetsPathCondition()
{ {
MSBuild.BuildProperty property = GetMSBuildProperty("WixTargetsPath"); ProjectPropertyElement property = GetMSBuildProperty("WixTargetsPath");
Assert.AreEqual(" '$(WixTargetsPath)' == '' ", property.Condition); Assert.AreEqual(" '$(WixTargetsPath)' == '' ", property.Condition);
} }
@ -128,7 +121,7 @@ namespace WixBinding.Tests.Project
[Test] [Test]
public void WixTasksPathCondition() public void WixTasksPathCondition()
{ {
MSBuild.BuildProperty property = GetMSBuildProperty("WixTasksPath"); ProjectPropertyElement property = GetMSBuildProperty("WixTasksPath");
Assert.AreEqual(" '$(WixTasksPath)' == '' ", property.Condition); Assert.AreEqual(" '$(WixTasksPath)' == '' ", property.Condition);
} }
@ -165,15 +158,12 @@ namespace WixBinding.Tests.Project
/// <summary> /// <summary>
/// Gets the MSBuild build property with the specified name from the WixProject. /// Gets the MSBuild build property with the specified name from the WixProject.
/// </summary> /// </summary>
MSBuild.BuildProperty GetMSBuildProperty(string name) ProjectPropertyElement GetMSBuildProperty(string name)
{ {
MSBuild.Project msbuildProject = project.MSBuildProject; foreach (ProjectPropertyGroupElement g in project.MSBuildProjectFile.PropertyGroups) {
foreach (MSBuild.BuildPropertyGroup g in msbuildProject.PropertyGroups.Cast<MSBuild.BuildPropertyGroup>().ToList()) { foreach (ProjectPropertyElement element in g.Properties) {
if (!g.IsImported) { if (element.Name == name)
MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, name); return element;
if (property != null) {
return property;
}
} }
} }
return null; return null;

51
src/AddIns/BackendBindings/WixBinding/Test/Project/CreateWixProjectItemTests.cs

@ -5,13 +5,13 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System;
using ICSharpCode.SharpDevelop.Internal.Templates; using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding; using ICSharpCode.WixBinding;
using NUnit.Framework; using NUnit.Framework;
using System; using System.Collections.Generic;
using WixBinding.Tests.Utils; using WixBinding.Tests.Utils;
using Microsoft.Build.BuildEngine;
namespace WixBinding.Tests.Project namespace WixBinding.Tests.Project
{ {
@ -21,6 +21,53 @@ namespace WixBinding.Tests.Project
[TestFixture] [TestFixture]
public class CreateWixProjectItemTests public class CreateWixProjectItemTests
{ {
class BuildItem : IProjectItemBackendStore
{
public BuildItem(string type, string include)
{
this.ItemType = new ItemType(type);
this.UnevaluatedInclude = include;
this.EvaluatedInclude = include;
}
/// Gets the owning project.
public IProject Project { get { throw new NotImplementedException(); } }
public string UnevaluatedInclude { get; set; }
public string EvaluatedInclude { get; set; }
public ItemType ItemType { get; set; }
public string GetEvaluatedMetadata(string name)
{
throw new NotImplementedException();
}
public string GetMetadata(string name)
{
throw new NotImplementedException();
}
public bool HasMetadata(string name)
{
throw new NotImplementedException();
}
public void RemoveMetadata(string name)
{
throw new NotImplementedException();
}
public void SetEvaluatedMetadata(string name, string value)
{
throw new NotImplementedException();
}
public void SetMetadata(string name, string value)
{
throw new NotImplementedException();
}
public IEnumerable<string> MetadataNames {
get {
throw new NotImplementedException();
}
}
}
[Test] [Test]
public void CreateReferenceProjectItem() public void CreateReferenceProjectItem()
{ {

12
src/AddIns/BackendBindings/WixBinding/Test/Project/WixBuilderCannotBuildNonWixProjectTestFixture.cs

@ -5,10 +5,11 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.SharpDevelop.Internal.Templates;
using System;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding; using ICSharpCode.WixBinding;
using NUnit.Framework; using NUnit.Framework;
using System;
namespace WixBinding.Tests.Project namespace WixBinding.Tests.Project
{ {
@ -25,9 +26,14 @@ namespace WixBinding.Tests.Project
public void SetUpFixture() public void SetUpFixture()
{ {
wixNodeBuilder = new WixProjectNodeBuilder(); wixNodeBuilder = new WixProjectNodeBuilder();
project = new MSBuildBasedProject(MSBuildInternals.CreateEngine()); project = new MSBuildBasedProject(
new ProjectCreateInformation {
OutputProjectFileName = @"C:\Projects\Test\test.csproj",
Solution = new Solution(),
ProjectName = "test"
}
);
project.IdGuid = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"; project.IdGuid = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
project.FileName = @"C:\Projects\Test\test.csproj";
} }
[Test] [Test]

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

@ -34,6 +34,7 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.Build" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
@ -44,7 +45,6 @@
<HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath> <HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath>
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
</Reference> </Reference>
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Framework" /> <Reference Include="Microsoft.Build.Framework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

57
src/Main/Base/Project/Src/Project/Items/ProjectItem.cs

@ -344,16 +344,67 @@ namespace ICSharpCode.SharpDevelop.Project
// use CreateProjectItem to ensure the clone has the same class // use CreateProjectItem to ensure the clone has the same class
// (derived from ProjectItem) // (derived from ProjectItem)
ProjectItem copy = targetProject.CreateProjectItem(CloneBuildItem()); ProjectItem copy = targetProject.CreateProjectItem(new CloneBuildItem(this));
// remove reference to cloned item, leaving an unbound project item // remove reference to cloned item, leaving an unbound project item
copy.BuildItem = null; copy.BuildItem = null;
return copy; return copy;
} }
IProjectItemBackendStore CloneBuildItem() class CloneBuildItem : IProjectItemBackendStore
{ {
throw new NotImplementedException(); ProjectItem parent;
public CloneBuildItem(ProjectItem parent)
{
this.parent = parent;
}
/// Gets the owning project.
public IProject Project {
get { throw new NotSupportedException(); }
}
public string UnevaluatedInclude {
get { return parent.Include; }
set { throw new NotSupportedException(); }
}
public string EvaluatedInclude {
get { return parent.Include; }
set { throw new NotSupportedException(); }
}
public ItemType ItemType {
get { return parent.ItemType; }
set { throw new NotSupportedException(); }
}
public string GetEvaluatedMetadata(string name)
{
return parent.GetEvaluatedMetadata(name);
}
public string GetMetadata(string name)
{
return parent.GetMetadata(name);
}
public bool HasMetadata(string name)
{
return parent.HasMetadata(name);
}
public void RemoveMetadata(string name)
{
parent.RemoveMetadata(name);
}
public void SetEvaluatedMetadata(string name, string value)
{
parent.SetEvaluatedMetadata(name, value);
}
public void SetMetadata(string name, string value)
{
parent.SetMetadata(name, value);
}
public IEnumerable<string> MetadataNames {
get { return parent.MetadataNames; }
}
} }
object ICloneable.Clone() object ICloneable.Clone()

4
src/Main/Base/Project/Src/Project/MSBuildItemWrapper.cs

@ -37,8 +37,8 @@ namespace ICSharpCode.SharpDevelop.Project
set { item.UnevaluatedInclude = value; } set { item.UnevaluatedInclude = value; }
} }
public string EvaluatedInclude { public string EvaluatedInclude {
get { return item.UnevaluatedInclude; } get { return item.EvaluatedInclude; }
set { item.UnevaluatedInclude = value; } set { item.UnevaluatedInclude = MSBuildInternals.Escape(value); }
} }
public ItemType ItemType { public ItemType ItemType {

Loading…
Cancel
Save