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

Fixing issues with deployment item from VS IDE #95

Merged
merged 3 commits into from
Mar 6, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
using System;

/// <summary>
/// Used to specify deployment item (file or directory) for per-test deployment.
/// Can be specified on test class or test method.
/// Can have multiple instances of the attribute to specify more than one item.
/// The item path can be absolute or relative, if relative, it is relative to RunConfig.RelativePathRoot.
/// </summary>
/// <example>
/// [DeploymentItem("file1.xml")]
/// [DeploymentItem("file2.xml", "DataFiles")]
/// [DeploymentItem("bin\Debug")]
/// </example>
/// <remarks>
/// DeploymentItemAttribute is currently not supported in .Net Core. This is just a placehodler for support in the future.
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public sealed class DeploymentItemAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class.
/// </summary>
/// <param name="path">The file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
public DeploymentItemAttribute(string path)
{
this.Path = path;
this.OutputDirectory = string.Empty;
}

/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class
/// </summary>
/// <param name="path">The relative or absolute path to the file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
/// <param name="outputDirectory">The path of the directory to which the items are to be copied. It can be either absolute or relative to the deployment directory. All files and directories identified by <paramref name="path"/> will be copied to this directory.</param>
public DeploymentItemAttribute(string path, string outputDirectory)
{
this.Path = path;
this.OutputDirectory = outputDirectory;
}

/// <summary>
/// Gets the path of the source file or folder to be copied.
/// </summary>
public string Path { get; }

/// <summary>
/// Gets the path of the directory to which the item is copied.
/// </summary>
public string OutputDirectory { get; }
}
}
1 change: 1 addition & 0 deletions src/TestFramework/Extension.Core/Extension.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<LocDocumentationSubPath>Extensions\Core</LocDocumentationSubPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Attributes\DeploymentItemAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
using System;

/// <summary>
/// Used to specify deployment item (file or directory) for per-test deployment.
/// Can be specified on test class or test method.
/// Can have multiple instances of the attribute to specify more than one item.
/// The item path can be absolute or relative, if relative, it is relative to RunConfig.RelativePathRoot.
/// </summary>
/// <example>
/// [DeploymentItem("file1.xml")]
/// [DeploymentItem("file2.xml", "DataFiles")]
/// [DeploymentItem("bin\Debug")]
/// </example>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public sealed class DeploymentItemAttribute : Attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not support it for .NETCore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the attribute in .Net Core as well. This would however not be visible in UWP since it does not even make sense there.

{
/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class.
/// </summary>
/// <param name="path">The file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
public DeploymentItemAttribute(string path)
{
this.Path = path;
this.OutputDirectory = string.Empty;
}

/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class
/// </summary>
/// <param name="path">The relative or absolute path to the file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
/// <param name="outputDirectory">The path of the directory to which the items are to be copied. It can be either absolute or relative to the deployment directory. All files and directories identified by <paramref name="path"/> will be copied to this directory.</param>
public DeploymentItemAttribute(string path, string outputDirectory)
{
this.Path = path;
this.OutputDirectory = outputDirectory;
}

/// <summary>
/// Gets the path of the source file or folder to be copied.
/// </summary>
public string Path { get; }

/// <summary>
/// Gets the path of the directory to which the item is copied.
/// </summary>
public string OutputDirectory { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes\DeploymentItemAttribute.cs" />
<Compile Include="ConfigurationSettings\ConfigurationNames.cs" />
<Compile Include="ConfigurationSettings\DataSourceElement.cs" />
<Compile Include="ConfigurationSettings\DataSourceElementCollection.cs" />
Expand Down
46 changes: 0 additions & 46 deletions src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,52 +405,6 @@ public TestResult()
public IList<string> ResultFiles { get; set; }
}

/// <summary>
/// Used to specify deployment item (file or directory) for per-test deployment.
/// Can be specified on test class or test method.
/// Can have multiple instances of the attribute to specify more than one item.
/// The item path can be absolute or relative, if relative, it is relative to RunConfig.RelativePathRoot.
/// </summary>
/// <example>
/// [DeploymentItem("file1.xml")]
/// [DeploymentItem("file2.xml", "DataFiles")]
/// [DeploymentItem("bin\Debug")]
/// </example>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public sealed class DeploymentItemAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class.
/// </summary>
/// <param name="path">The file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
public DeploymentItemAttribute(string path)
{
this.Path = path;
this.OutputDirectory = string.Empty;
}

/// <summary>
/// Initializes a new instance of the <see cref="DeploymentItemAttribute"/> class
/// </summary>
/// <param name="path">The relative or absolute path to the file or directory to deploy. The path is relative to the build output directory. The item will be copied to the same directory as the deployed test assemblies.</param>
/// <param name="outputDirectory">The path of the directory to which the items are to be copied. It can be either absolute or relative to the deployment directory. All files and directories identified by <paramref name="path"/> will be copied to this directory.</param>
public DeploymentItemAttribute(string path, string outputDirectory)
{
this.Path = path;
this.OutputDirectory = outputDirectory;
}

/// <summary>
/// Gets the path of the source file or folder to be copied.
/// </summary>
public string Path { get; }

/// <summary>
/// Gets the path of the directory to which the item is copied.
/// </summary>
public string OutputDirectory { get; }
}

/// <summary>
/// Specifies connection string, table name and row access method for data driven testing.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public void GetTestFromMethodShouldSetDeploymentItemsToNullIfNotPresent()
var methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

// Setup mocks
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(It.IsAny<MemberInfo>(), typeof(UTF.DeploymentItemAttribute))).Returns(new Attribute[] { });
this.testablePlatformServiceProvider.MockTestDeployment.Setup(
td => td.GetDeploymentItems(It.IsAny<MethodInfo>(), It.IsAny<Type>(), this.warnings))
.Returns((KeyValuePair<string, string>[])null);
Expand All @@ -333,8 +332,6 @@ public void GetTestFromMethodShouldSetDeploymentItems()
var deploymentItems = new[] { new KeyValuePair<string, string>("C:\\temp", string.Empty) };

// Setup mocks
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(typeof(DummyTestClass).GetTypeInfo(), typeof(UTF.DeploymentItemAttribute))).Returns(new Attribute[] { new UTF.DeploymentItemAttribute("C:\\temp") });
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.DeploymentItemAttribute))).Returns(new Attribute[] { });
this.testablePlatformServiceProvider.MockTestDeployment.Setup(
td => td.GetDeploymentItems(methodInfo, typeof(DummyTestClass), this.warnings)).Returns(deploymentItems);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services
{
extern alias FrameworkV1;
extern alias FrameworkV2;
extern alias FrameworkV2DesktopExtension;

using System.Collections.Generic;
using System.IO;
Expand All @@ -25,7 +26,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services
using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
using Ignore = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;
using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFrameworkV2Extension = FrameworkV2DesktopExtension::Microsoft.VisualStudio.TestTools.UnitTesting;
using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;

Expand Down Expand Up @@ -563,18 +564,18 @@ public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceI

private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair<string, string>[] deploymentItems)
{
var deploymentItemAttributes = new List<TestFrameworkV2.DeploymentItemAttribute>();
var deploymentItemAttributes = new List<TestFrameworkV2Extension.DeploymentItemAttribute>();

foreach (var deploymentItem in deploymentItems)
{
deploymentItemAttributes.Add(new TestFrameworkV2.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
}

this.mockReflectionUtility.Setup(
ru =>
ru.GetCustomAttributes(
memberInfo,
typeof(TestFrameworkV2.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
}

private TestCase GetTestCase(string source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities
{
extern alias FrameworkV1;
extern alias FrameworkV2;
extern alias FrameworkV2DesktopExtension;

using System.Collections.Generic;
using System.Linq;
Expand All @@ -22,6 +23,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities
using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert;
using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFrameworkV2Extension = FrameworkV2DesktopExtension::Microsoft.VisualStudio.TestTools.UnitTesting;
using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;

Expand Down Expand Up @@ -451,18 +453,18 @@ public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent()

private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair<string, string>[] deploymentItems)
{
var deploymentItemAttributes = new List<TestFrameworkV2.DeploymentItemAttribute>();
var deploymentItemAttributes = new List<TestFrameworkV2Extension.DeploymentItemAttribute>();

foreach (var deploymentItem in deploymentItems)
{
deploymentItemAttributes.Add(new TestFrameworkV2.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
}

this.mockReflectionUtility.Setup(
ru =>
ru.GetCustomAttributes(
memberInfo,
typeof(TestFrameworkV2.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
}

#endregion
Expand Down