From 235da7951f0be3a6263bdec2c44f1e9a1ffe093b Mon Sep 17 00:00:00 2001 From: Sergey Zwezdin Date: Sun, 6 Nov 2016 08:54:21 +0500 Subject: [PATCH] Recurse search support for VSTS extension #6 --- .../Documents/JsonDocumentTests.cs | 99 +++++++++++++++++++ .../VSTS/MagicChunks/transform.ps1 | 9 +- 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/src/MagicChunks.Tests/Documents/JsonDocumentTests.cs b/src/MagicChunks.Tests/Documents/JsonDocumentTests.cs index 7c4bd3a..07d2ebe 100644 --- a/src/MagicChunks.Tests/Documents/JsonDocumentTests.cs +++ b/src/MagicChunks.Tests/Documents/JsonDocumentTests.cs @@ -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() { diff --git a/src/MagicChunks/VSTS/MagicChunks/transform.ps1 b/src/MagicChunks/VSTS/MagicChunks/transform.ps1 index e513ca9..0bde7de 100644 --- a/src/MagicChunks/VSTS/MagicChunks/transform.ps1 +++ b/src/MagicChunks/VSTS/MagicChunks/transform.ps1 @@ -3,7 +3,7 @@ param( [String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] $sourcePath, - [bool] + [String] [Parameter(Mandatory = $true)] $sourcePathRecurse, [String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] @@ -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) { @@ -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) } } @@ -67,7 +68,7 @@ catch { # Find files to transform -if ($sourcePathRecurse) { +if ([System.Convert]::ToBoolean($sourcePathRecurse)) { $files = Get-ChildItem $sourcePath -Recurse } else { @@ -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