Skip to content

Commit

Permalink
Recurse search support for VSTS extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyzwezdin committed Nov 6, 2016
1 parent 4f519d0 commit 235da79
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
99 changes: 99 additions & 0 deletions src/MagicChunks.Tests/Documents/JsonDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,105 @@ public void Transform()
}", result, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
}

[Fact]
public void Transform2()
{
// Arrange

var document = new JsonDocument(@"{
""Data"": {
""DefaultConnection"": {
""ConnectionString"": ""mongodb://"",
""DatabaseName"": ""test1""
}
},
""Logging"": {
""IncludeScopes"": false,
""LogLevel"": {
""Default"": ""Verbose"",
""System"": ""Information"",
""Microsoft"": ""Information""
}
},
""Smtp"": {
""Method"": ""SpecifiedPickupDirectory"",
""From"": {
""Address"": ""test1@gmail.com"",
""DisplayName"": ""test""
},
""SpecifiedPickupDirectory"": {
""PickupDirectoryLocation"": ""test\\maildrop\\"",
""AbsolutePath"": false
},
""Network"": {
""Host"": ""smtp.gmail.com"",
""Port"": 587,
""Timeout"": 3000,
""EnableSsl"": true,
""Credentials"": {
""Username"": ""test@gmail.com"",
""Password"": ""asdasdasd""
}
}
}
}");


// Act

document.ReplaceKey(new[] { "Data", "DefaultConnection", "ConnectionString" }, "mongodb://server1.local.db1.test");
document.ReplaceKey(new[] { "Smtp", "Network", "Host" }, "test.ru");

var result = document.ToString();


// Assert

Assert.Equal(@"{
""Data"": {
""DefaultConnection"": {
""ConnectionString"": ""mongodb://server1.local.db1.test"",
""DatabaseName"": ""test1""
}
},
""Logging"": {
""IncludeScopes"": false,
""LogLevel"": {
""Default"": ""Verbose"",
""System"": ""Information"",
""Microsoft"": ""Information""
}
},
""Smtp"": {
""Method"": ""SpecifiedPickupDirectory"",
""From"": {
""Address"": ""test1@gmail.com"",
""DisplayName"": ""test""
},
""SpecifiedPickupDirectory"": {
""PickupDirectoryLocation"": ""test\\maildrop\\"",
""AbsolutePath"": false
},
""Network"": {
""Host"": ""test.ru"",
""Port"": 587,
""Timeout"": 3000,
""EnableSsl"": true,
""Credentials"": {
""Username"": ""test@gmail.com"",
""Password"": ""asdasdasd""
}
}
}
}", result, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
}

[Fact]
public void Remove()
{
Expand Down
9 changes: 5 additions & 4 deletions src/MagicChunks/VSTS/MagicChunks/transform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ param(
[String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()]
$sourcePath,

[bool]
[String] [Parameter(Mandatory = $true)]
$sourcePathRecurse,

[String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -43,7 +43,7 @@ if ($transformationType -eq "file" -And [String]::IsNullOrEmpty($transformations
# Parse transformations

try {
$transforms = New-Object -TypeName MagicChunks.Core.TransformationCollection `
$transforms = New-Object -TypeName MagicChunks.Core.TransformationCollection

if ($transformationType -eq "file") {
if (Test-Path $transformationsFile) {
Expand All @@ -56,6 +56,7 @@ try {
}

foreach($t in ($transformations.Replace("\", "\\") | ConvertFrom-Json).psobject.properties) {
Write-Host "Transformation found: $($t.name): $($t.value)"
$transforms.Add($t.name, $t.value)
}
}
Expand All @@ -67,7 +68,7 @@ catch {

# Find files to transform

if ($sourcePathRecurse) {
if ([System.Convert]::ToBoolean($sourcePathRecurse)) {
$files = Get-ChildItem $sourcePath -Recurse
}
else {
Expand All @@ -90,7 +91,7 @@ foreach ($file in $files) {

[MagicChunks.TransformTask]::Transform(($fileType, $null)[[string]::IsNullOrWhitespace($fileType) -or ($fileType -eq "Auto")], $file, $target, $transforms)

Write-Host "File transformed to $($target)"
Write-Host "File $($file) transformed into $($target)"
}
catch {
Write-Error -Message "File $($file) transformation error: $($_.Exception.Message)" -Exception $_.Exception
Expand Down

0 comments on commit 235da79

Please sign in to comment.