Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added DeploymentItemExAttribute, much like DeploymentItem, but supports long file paths #3

Merged
merged 4 commits into from
Mar 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Examples:

Building
--------
The solution is strong named. Local builds are delay signed. To have the delay signing set-up, the solution needs to be built from the command line. Visual Studio should be restarted after the command line build is run. There are two options for building at the command line.
The solution is strong named. Local builds are delay signed. To have the delay signing set-up, the solution needs to be built from an elevated command prompt. Visual Studio should be restarted after the command line build is run. There are two options for building at the command line.

##### Run the .cmd file
[To Do]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<description>StealFocus MSTestExtensions package.</description>
<copyright>Copyright StealFocus. All rights reserved.</copyright>
<tags>StealFocus MSTestExtensions</tags>
<dependencies />
<dependencies>
<dependency id="ZetaLongPaths" version="1.0.0" />
</dependencies>
</metadata>
</package>
1 change: 1 addition & 0 deletions Source/StealFocus.MSTestExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
BuildServer.testsettings = BuildServer.testsettings
FxCopCustomDictionary.xml = FxCopCustomDictionary.xml
Local.testsettings = Local.testsettings
..\README.md = ..\README.md
Settings.StyleCop = Settings.StyleCop
StealFocus.MSTestExtensions.ruleset = StealFocus.MSTestExtensions.ruleset
StealFocus.MSTestExtensions.StrongNameKeyPair.snk = StealFocus.MSTestExtensions.StrongNameKeyPair.snk
Expand Down
122 changes: 122 additions & 0 deletions Source/StealFocus.MSTestExtensions/DeploymentItemWithLongPathAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
namespace StealFocus.MSTestExtensions
{
using System;
using System.IO;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Security;
using ZetaLongPaths;

internal class DeploymentItemWithLongPathAspect : MSTestExtensionsTestAspect<DeploymentItemWithLongPathAttribute>, IMessageSink, IMSTestExtensionsTestAspect
{
public IMessageSink NextSink
{
[SecurityCritical] get; private set;
}

/// <summary>
/// SyncProcessMessage Method.
/// </summary>
/// <param name="msg">An <see cref="IMessage"/>. The message.</param>
/// <returns>An <see cref="IMessage"/>. The reply.</returns>
[SecurityCritical]
public IMessage SyncProcessMessage(IMessage msg)
{
if (msg == null)
{
throw new ArgumentNullException("msg");
}

DeploymentItemWithLongPathAttribute deploymentItemWithLongPathAttribute = GetAttribute(msg);
if (deploymentItemWithLongPathAttribute != null)
{
// by default, mstest sets the test results folder to format: %current directory%\TestResults\%username%_%computername% %datetime%\Out
// TODO: get the value of the RelativePathRoot property setting in the current .testsettings file
string solutionPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;

string source = ZlpPathHelper.GetAbsolutePath(deploymentItemWithLongPathAttribute.Path, solutionPath);
string destinationPath = ZlpPathHelper.GetAbsolutePath(deploymentItemWithLongPathAttribute.OutputDirectory, Directory.GetCurrentDirectory());

bool fileExists = ZlpIOHelper.FileExists(source);
bool directoryExists = ZlpIOHelper.DirectoryExists(source);
if ((!fileExists) && (!directoryExists))
{
throw new MSTestExtensionsException("\"" + source + "\" does not exist.");
}

if (fileExists)
{
CopyFile(source, ZlpPathHelper.Combine(destinationPath, ZlpPathHelper.GetFileNameFromFilePath(source)));
}

if (directoryExists)
{
this.CopyDirectory(source, destinationPath);
}
}

return this.NextSink.SyncProcessMessage(msg);
}

/// <summary>
/// AsyncProcessMessage Method.
/// </summary>
/// <param name="msg">An <see cref="IMessage"/>. The message.</param>
/// <param name="replySink">An <see cref="IMessageSink"/>. The reply.</param>
/// <returns>An <see cref="IMessageSink"/>. The return.</returns>
[SecurityCritical]
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
{
throw new InvalidOperationException();
}

/// <summary>
/// Adds a message sink.
/// </summary>
/// <param name="messageSink">An <see cref="IMessageSink"/>. The message sink.</param>
public void AddMessageSink(IMessageSink messageSink)
{
this.NextSink = messageSink;
}

private static void CopyFile(string source, string destination)
{
if (ZlpIOHelper.FileExists(destination))
{
// TODO: add warning to test results
}
else
{
ZlpIOHelper.CopyFile(source, destination, false);
}
}

private void CopyDirectory(string source, string destination)
{
if (!ZlpIOHelper.DirectoryExists(destination))
{
ZlpIOHelper.CreateDirectory(destination);
}

ZlpFileInfo[] files = ZlpIOHelper.GetFiles(source, SearchOption.TopDirectoryOnly);
foreach (ZlpFileInfo file in files)
{
string destinationFile = ZlpPathHelper.Combine(destination, ZlpPathHelper.GetFileNameFromFilePath(file.FullName));

CopyFile(file.FullName, destinationFile);
}

ZlpDirectoryInfo[] sourceSubDirectories = ZlpIOHelper.GetDirectories(source);
foreach (ZlpDirectoryInfo sourceSubDirectory in sourceSubDirectories)
{
string sourceSubDirectoryName = sourceSubDirectory.FullName.Substring(source.Length + 1);

string destinationSubDirectoryName = ZlpPathHelper.Combine(destination, sourceSubDirectoryName);

this.CopyDirectory(
ZlpPathHelper.Combine(source, sourceSubDirectoryName),
destinationSubDirectoryName);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace StealFocus.MSTestExtensions
{
using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// DeploymentItemWithLongPath, much like DeploymentItem, but supports long file paths.
/// It allows the source and destination deployment items to have long file paths (greater than 256 characters).
/// See the unresolved Microsoft connect bug here:
/// http://connect.microsoft.com/VisualStudio/feedback/details/753341/unit-test-deploymentitem-attribute-is-limits-file-paths-with-a-maximum-file-path-length-of-about-256-characters
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public sealed class DeploymentItemWithLongPathAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemWithLongPathAttribute"/> class.
/// </summary>
/// <param name="path">The path.</param>
public DeploymentItemWithLongPathAttribute(string path)
{
this.Path = path;
this.OutputDirectory = string.Empty;
}

/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemWithLongPathAttribute"/> class.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="outputDirectory">The output directory.</param>
public DeploymentItemWithLongPathAttribute(string path, string outputDirectory)
{
this.Path = path;
this.OutputDirectory = outputDirectory;
}

/// <summary>
/// Gets the path.
/// </summary>
/// <value>
/// The path.
/// </value>
public string Path { get; private set; }

/// <summary>
/// Gets the output directory.
/// </summary>
/// <value>
/// The output directory.
/// </value>
public string OutputDirectory { get; private set; }
}
}
1 change: 1 addition & 0 deletions Source/StealFocus.MSTestExtensions/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "StealFocus.MSTestExtensions.TestTimerAspect")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "StealFocus.MSTestExtensions.TestTransactionAspect")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "TestTimer", Scope = "member", Target = "StealFocus.MSTestExtensions.TestTimerAspect.#SyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "StealFocus.MSTestExtensions.DeploymentItemWithLongPathAspect")]
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public override void GetPropertiesForNewContext(IConstructionCallMessage msg)
msg.ContextProperties.Add(new MSTestExtensionsTestProperty<TestTimerAspect>());
msg.ContextProperties.Add(new MSTestExtensionsTestProperty<TestTransactionAspect>());
msg.ContextProperties.Add(new MSTestExtensionsTestProperty<ExpectedExceptionMessageAspect>());
msg.ContextProperties.Add(new MSTestExtensionsTestProperty<DeploymentItemWithLongPathAspect>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<AssemblyName>StealFocus.MSTestExtensions</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -48,8 +50,13 @@
<Reference Include="System.Core" />
<Reference Include="System.Transactions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="ZetaLongPaths">
<HintPath>..\packages\ZetaLongPaths.1.0.0\lib\ZetaLongPaths.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DeploymentItemWithLongPathAspect.cs" />
<Compile Include="DeploymentItemWithLongPathAttribute.cs" />
<Compile Include="MSTestExtensionsException.cs" />
<Compile Include="MSTestExtensionsTestAspect.cs" />
<Compile Include="MSTestExtensionsTestAttribute.cs" />
Expand All @@ -75,6 +82,7 @@
<None Include="..\StealFocus.MSTestExtensions.StrongNamePublicKey.snk">
<Link>StealFocus.MSTestExtensions.StrongNamePublicKey.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\Scripts\StealFocus.MSTestExtensions.Build.Project.CSharp.targets" />
Expand Down
4 changes: 4 additions & 0 deletions Source/StealFocus.MSTestExtensions/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ZetaLongPaths" version="1.0.0" targetFramework="net40" />
</packages>
Binary file not shown.
21 changes: 21 additions & 0 deletions Source/packages/ZetaLongPaths.1.0.0/ZetaLongPaths.1.0.0.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>ZetaLongPaths</id>
<version>1.0.0</version>
<title>Zeta Long Paths</title>
<authors>Uwe Keim</authors>
<owners>Uwe Keim</owners>
<projectUrl>http://zetalongpaths.codeplex.com/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A .NET library to access files and directories with more than 260 characters length.</description>
<summary>A .NET library to access files and directories with more than 260 characters length.</summary>
<releaseNotes />
<copyright />
<language>en-US</language>
<tags>file, io</tags>
<references>
<reference file="ZetaLongPaths.dll" />
</references>
</metadata>
</package>
Binary file not shown.
4 changes: 4 additions & 0 deletions Source/packages/repositories.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\StealFocus.MSTestExtensions\packages.config" />
</repositories>