14 changed files with 308 additions and 55 deletions
@ -0,0 +1,12 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public interface IPropertyFactory |
||||||
|
{ |
||||||
|
Property CreateProperty(string name); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class ProjectItemProperty : Property |
||||||
|
{ |
||||||
|
ProjectItem projectItem; |
||||||
|
|
||||||
|
public ProjectItemProperty(ProjectItem projectItem, string name) |
||||||
|
: base(projectItem.ContainingProject, name) |
||||||
|
{ |
||||||
|
this.projectItem = projectItem; |
||||||
|
} |
||||||
|
|
||||||
|
protected override object GetProperty() |
||||||
|
{ |
||||||
|
return projectItem.GetProperty(Name); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void SetProperty(object value) |
||||||
|
{ |
||||||
|
projectItem.SetProperty(Name, value); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class ProjectItemPropertyFactory : IPropertyFactory |
||||||
|
{ |
||||||
|
ProjectItem projectItem; |
||||||
|
|
||||||
|
public ProjectItemPropertyFactory(ProjectItem projectItem) |
||||||
|
{ |
||||||
|
this.projectItem = projectItem; |
||||||
|
} |
||||||
|
|
||||||
|
public Property CreateProperty(string name) |
||||||
|
{ |
||||||
|
return new ProjectItemProperty(projectItem, name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class ProjectProperty : Property |
||||||
|
{ |
||||||
|
public ProjectProperty(Project project, string name) |
||||||
|
: base(project, name) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected override object GetProperty() |
||||||
|
{ |
||||||
|
string value = Project.MSBuildProject.GetUnevalatedProperty(Name); |
||||||
|
if (value != null) { |
||||||
|
return value; |
||||||
|
} |
||||||
|
|
||||||
|
if (IsTargetFrameworkMoniker(Name)) { |
||||||
|
return GetTargetFrameworkMoniker(); |
||||||
|
} |
||||||
|
return EmptyStringIfNull(value); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsTargetFrameworkMoniker(string name) |
||||||
|
{ |
||||||
|
return String.Equals(name, "TargetFrameworkMoniker", StringComparison.InvariantCultureIgnoreCase); |
||||||
|
} |
||||||
|
|
||||||
|
string GetTargetFrameworkMoniker() |
||||||
|
{ |
||||||
|
var targetFramework = new ProjectTargetFramework(Project.MSBuildProject); |
||||||
|
return targetFramework.TargetFrameworkName.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
string EmptyStringIfNull(string value) |
||||||
|
{ |
||||||
|
if (value != null) { |
||||||
|
return value; |
||||||
|
} |
||||||
|
return String.Empty; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void SetProperty(object value) |
||||||
|
{ |
||||||
|
bool escapeValue = false; |
||||||
|
Project.MSBuildProject.SetProperty(Name, value as string, escapeValue); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.PackageManagement.EnvDTE |
||||||
|
{ |
||||||
|
public class ProjectPropertyFactory : IPropertyFactory |
||||||
|
{ |
||||||
|
Project project; |
||||||
|
|
||||||
|
public ProjectPropertyFactory(Project project) |
||||||
|
{ |
||||||
|
this.project = project; |
||||||
|
} |
||||||
|
|
||||||
|
public Property CreateProperty(string name) |
||||||
|
{ |
||||||
|
return new ProjectProperty(project, name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,80 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.PackageManagement.EnvDTE; |
||||||
|
using NUnit.Framework; |
||||||
|
using PackageManagement.Tests.Helpers; |
||||||
|
using SD = ICSharpCode.SharpDevelop.Project; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests.EnvDTE |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ProjectItemPropertyTests |
||||||
|
{ |
||||||
|
ProjectItem projectItem; |
||||||
|
SD.FileProjectItem msbuildFileProjectItem; |
||||||
|
TestableDTEProject project; |
||||||
|
TestableProject msbuildProject; |
||||||
|
Properties properties; |
||||||
|
|
||||||
|
void CreateProjectItemProperties() |
||||||
|
{ |
||||||
|
project = new TestableDTEProject(); |
||||||
|
msbuildProject = project.TestableProject; |
||||||
|
msbuildFileProjectItem = new SD.FileProjectItem(msbuildProject, SD.ItemType.Compile); |
||||||
|
projectItem = new ProjectItem(project, msbuildFileProjectItem); |
||||||
|
properties = projectItem.Properties; |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Value_GetCopyToOutputDirectoryPropertyValue_ReturnsCopyToOutputDirectoryValueFromMSBuildProject() |
||||||
|
{ |
||||||
|
CreateProjectItemProperties(); |
||||||
|
msbuildFileProjectItem.CopyToOutputDirectory = SD.CopyToOutputDirectory.PreserveNewest; |
||||||
|
|
||||||
|
var propertyObject = properties.Item("CopyToOutputDirectory").Value; |
||||||
|
var propertyValue = (UInt32)propertyObject; |
||||||
|
var propertyValueAsEnum = (SD.CopyToOutputDirectory)propertyValue; |
||||||
|
|
||||||
|
Assert.AreEqual(SD.CopyToOutputDirectory.PreserveNewest, propertyValueAsEnum); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Name_ProjectItemNameIsTest_ReturnsTest() |
||||||
|
{ |
||||||
|
CreateProjectItemProperties(); |
||||||
|
var property = new ProjectItemProperty(projectItem, "Test"); |
||||||
|
|
||||||
|
string name = property.Name; |
||||||
|
|
||||||
|
Assert.AreEqual("Test", name); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Value_SetCopyToOutputDirectoryPropertyValueToAlways_SetsCopyToOutputDirectoryValueInMSBuildProject() |
||||||
|
{ |
||||||
|
CreateProjectItemProperties(); |
||||||
|
|
||||||
|
UInt32 copyToOutputDirectoryAlways = 1; |
||||||
|
properties.Item("CopyToOutputDirectory").Value = copyToOutputDirectoryAlways; |
||||||
|
|
||||||
|
var copyToOutputDirectory = msbuildFileProjectItem.CopyToOutputDirectory; |
||||||
|
|
||||||
|
Assert.AreEqual(SD.CopyToOutputDirectory.Always, copyToOutputDirectory); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Value_SetCopyToOutputDirectoryPropertyValueToAlways_ProjectIsSaved() |
||||||
|
{ |
||||||
|
CreateProjectItemProperties(); |
||||||
|
|
||||||
|
UInt32 copyToOutputDirectoryAlways = 1; |
||||||
|
properties.Item("CopyToOutputDirectory").Value = copyToOutputDirectoryAlways; |
||||||
|
|
||||||
|
bool saved = msbuildProject.IsSaved; |
||||||
|
|
||||||
|
Assert.IsTrue(saved); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue