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

@MsBuild [DeploymentItem] - added option to provide output directory #901

Merged
merged 2 commits into from Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -85,7 +85,15 @@ public override void SetTestMethod(TestClassGenerationContext generationContext,
IEnumerable<string> deploymentItems = generationContext.CustomData[DEPLOYMENTITEM_TAG] as IEnumerable<string>;
foreach (string deploymentItem in deploymentItems)
{
CodeDomHelper.AddAttribute(testMethod, DEPLOYMENTITEM_ATTR, deploymentItem);
var outputDirProvided = deploymentItem.Split(':').Any();
if (!outputDirProvided)
Copy link
Contributor

Choose a reason for hiding this comment

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

please invert the if

{
CodeDomHelper.AddAttribute(testMethod, DEPLOYMENTITEM_ATTR, deploymentItem);
}
else
{
CodeDomHelper.AddAttribute(testMethod, DEPLOYMENTITEM_ATTR, deploymentItem.Split(':'));
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/TechTalk.SpecFlow.Specs/Drivers/InputProjectDriver.cs
Expand Up @@ -147,7 +147,10 @@ public void AddFeatureFile(string featureFileText, string featureFileName = null

public ContentFileInput AddContentFile(string fileName, string fileContent)
{
var contentFileInput = new ContentFileInput(fileName, fileContent);
var file = Path.GetFileName(fileName);
var directory = Path.GetDirectoryName(fileName);

var contentFileInput = string.IsNullOrEmpty(directory) || directory == "." ? new ContentFileInput(file, fileContent) : new ContentFileInput(file, fileContent, directory);
Copy link
Contributor

Choose a reason for hiding this comment

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

please refactor this to a separate method

ContentFiles.Add(contentFileInput);
return contentFileInput;
}
Expand Down
Expand Up @@ -64,6 +64,7 @@ public Project GenerateProject(InputProjectDriver inputProjectDriver)
foreach (var contentFileInput in inputProjectDriver.ContentFiles)
{
string outputPath = Path.Combine(inputProjectDriver.CompilationFolder, contentFileInput.ProjectRelativePath);
new FileInfo(outputPath).Directory?.Create();
Copy link
Contributor

Choose a reason for hiding this comment

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

what about System.IO.Directory.CreateDirectory(Path.GetDirectoryName(outputPath)) ?

File.WriteAllText(outputPath, contentFileInput.Content, Encoding.UTF8);
project.AddItem("Content", contentFileInput.ProjectRelativePath, new[]
{
Expand Down
51 changes: 51 additions & 0 deletions Tests/TechTalk.SpecFlow.Specs/Features/MsTestProvider.feature
Expand Up @@ -106,6 +106,57 @@ Scenario: Should be able to deploy files
</TestSettings>
"""
When I execute the tests with MsTest
Then the execution summary should contain
| Succeeded |
| 1 |

@config
Scenario: Should be able to deploy files to specific folder
Given there is a SpecFlow project
And the following binding class
"""
using Microsoft.VisualStudio.TestTools.UnitTesting;

[Binding]
public class DeploymentItemSteps
{
[Then(@"the file '(.*)' exists")]
public void ThenTheFileExists(string fileName)
{
Assert.IsTrue(File.Exists(fileName));
}
}
"""
And there is a feature file in the project as
"""
@MsTest:DeploymentItem:TestXmls\:TestXmls
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use a different name for folder and file in this example?

Feature: Deployment Item Feature

Scenario: Deployment Item Scenario
Then the file 'TestXmls\DeploymentItemTestFile.txt' exists
"""
And there is a content file 'TestXmls\DeploymentItemTestFile.txt' in the project as
"""
This is a deployment item file
"""
And the specflow configuration is
"""
<specFlow>
<unitTestProvider name="MsTest"/>
</specFlow>
"""
And there is a test settings file 'Local.testsettings'
"""
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings
id="b8f2810b-cd53-4519-8b18-d0e599219d54"
name="Local"
enableDefaultDataCollectors="false"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Deployment enabled="true" />
</TestSettings>
"""
When I execute the tests with MsTest
Then the execution summary should contain
| Succeeded |
| 1 |