Skip to content

Commit df0d205

Browse files
committed
Merge pull request #2 from jackmagic313/dev
fix whitespace bugs for hub and pipeline & add some negative test cases
2 parents ef3d20b + f01ca1b commit df0d205

File tree

8 files changed

+138
-10
lines changed

8 files changed

+138
-10
lines changed

src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ function Test-DataFactoryPiping
124124

125125
# Test the data factory no longer exists
126126
Assert-ThrowsContains { Get-AzureDataFactory -ResourceGroupName $rgname -Name $dfname } "ResourceNotFound"
127-
}
127+
}

src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Collections.Generic;
1615
using Microsoft.Azure.Commands.DataFactories.Models;
1716
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1817
using Moq;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
1921
using Xunit;
2022

2123
namespace Microsoft.Azure.Commands.DataFactories.Test
@@ -78,6 +80,30 @@ public void CanGetHub()
7880
commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
7981
}
8082

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void GetHubWithEmptyName()
86+
{
87+
// Action
88+
cmdlet.Name = String.Empty;
89+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
90+
91+
// Assert
92+
Assert.Contains("Value cannot be null", exception.Message);
93+
}
94+
95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void GetHubWithWhiteSpaceName()
98+
{
99+
// Action
100+
cmdlet.Name = " ";
101+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
102+
103+
// Assert
104+
Assert.Contains("Value cannot be null", exception.Message);
105+
}
106+
81107
[Fact]
82108
[Trait(Category.AcceptanceType, Category.CheckIn)]
83109
public void CanListHubs()

src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Collections.Generic;
1615
using Microsoft.Azure.Commands.DataFactories.Models;
1716
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1817
using Moq;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
1921
using Xunit;
2022

2123
namespace Microsoft.Azure.Commands.DataFactories.Test
@@ -78,6 +80,30 @@ public void CanGetPipeline()
7880
commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
7981
}
8082

83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void GetPipelineWithEmptyName()
86+
{
87+
// Action
88+
cmdlet.Name = String.Empty;
89+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
90+
91+
// Assert
92+
Assert.Contains("Value cannot be null", exception.Message);
93+
}
94+
95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void GetPipelineWithWhiteSpaceName()
98+
{
99+
// Action
100+
cmdlet.Name = " ";
101+
Exception exception = Assert.Throws<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());
102+
103+
// Assert
104+
Assert.Contains("Value cannot be null", exception.Message);
105+
}
106+
81107
[Fact]
82108
[Trait(Category.AcceptanceType, Category.CheckIn)]
83109
public void CanListPipelines()

src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.DataFactories.Models;
16+
using Microsoft.Azure.Commands.DataFactories.Properties;
1517
using System.Collections.Generic;
18+
using System.Globalization;
1619
using System.Management.Automation;
1720
using System.Security.Permissions;
18-
using Microsoft.Azure.Commands.DataFactories.Models;
19-
using System.Globalization;
20-
using Microsoft.Azure.Commands.DataFactories.Properties;
2121

2222
namespace Microsoft.Azure.Commands.DataFactories
2323
{
@@ -31,6 +31,12 @@ public class GetAzureDataFactoryHubCommand : HubContextBaseCmdlet
3131
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
3232
public override void ExecuteCmdlet()
3333
{
34+
// ValidationNotNullOrEmpty doesn't handle whitespaces well
35+
if (Name != null && string.IsNullOrWhiteSpace(Name))
36+
{
37+
throw new PSArgumentNullException("Name");
38+
}
39+
3440
if (ParameterSetName == ByFactoryObject)
3541
{
3642
if (DataFactory == null)

src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.DataFactories.Models;
16+
using Microsoft.Azure.Commands.DataFactories.Properties;
1517
using System;
18+
using System.Collections;
1619
using System.Collections.Generic;
20+
using System.Globalization;
1721
using System.Management.Automation;
1822
using System.Security.Permissions;
19-
using Microsoft.Azure.Commands.DataFactories.Models;
20-
using System.Collections;
21-
using System.Globalization;
22-
using Microsoft.Azure.Commands.DataFactories.Properties;
2323

2424
namespace Microsoft.Azure.Commands.DataFactories
2525
{
@@ -42,6 +42,12 @@ public class GetAzureDataFactoryPipelineCommand : DataFactoryBaseCmdlet
4242
[EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)]
4343
public override void ExecuteCmdlet()
4444
{
45+
// ValidationNotNullOrEmpty doesn't handle whitespaces well
46+
if (Name != null && string.IsNullOrWhiteSpace(Name))
47+
{
48+
throw new PSArgumentNullException("Name");
49+
}
50+
4551
if (ParameterSetName == ByFactoryObject)
4652
{
4753
if (DataFactory == null)

src/ServiceManagement/Services/Commands.Utilities/Microsoft.WindowsAzure.Commands.dll-Help.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28113,4 +28113,14 @@
2811328113
</maml:navigationLink>
2811428114
</maml:relatedLinks>
2811528115
</command:command>
28116+
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
28117+
<command:details>
28118+
<command:name>New-AzureDataFactory</command:name>
28119+
<maml:description>
28120+
<maml:para>You must be in AzureResourceManager mode to run Azure Data Factory cmdlets. To switch to AzureResourceManager mode, run Switch-AzureMode AzureResourceManager.</maml:para>
28121+
</maml:description>
28122+
<command:verb>New</command:verb>
28123+
<command:noun>AzureDataFactory</command:noun>
28124+
</command:details>
28125+
</command:command>
2811628126
</helpItems>

src/ServiceManagement/Services/Commands/Commands.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
<Compile Include="MediaServices\NewAzureMediaServiceCommand.cs" />
210210
<Compile Include="MediaServices\NewAzureMediaServiceKeyCommand.cs" />
211211
<Compile Include="MediaServices\RemoveAzureMediaServiceCommand.cs" />
212+
<Compile Include="DataFactories\NewAzureDataFactoryStubCommand.cs" />
212213
<Compile Include="Scheduler\GetSchedulerJobCollectionCommand.cs" />
213214
<Compile Include="Scheduler\GetSchedulerJobCommand.cs" />
214215
<Compile Include="Scheduler\GetSchedulerJobHistoryCommand.cs" />
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections;
16+
using System.Management.Automation;
17+
using System.Security.Permissions;
18+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
20+
namespace Microsoft.WindowsAzure.Commands.DataFactories
21+
{
22+
/// <summary>
23+
/// In order to show warning for ADF cmdlets if client is using service management mode
24+
/// </summary>
25+
[Cmdlet(VerbsCommon.New, "AzureDataFactory")]
26+
public class NewAzureDataFactoryStubCommand : AzurePSCmdlet
27+
{
28+
//Just to make sure there is no error messages for parameters when clients use "New-AzureDataFactory"
29+
[Parameter(Mandatory = false)]
30+
public string ResourceGroupName { get; set; }
31+
32+
[Parameter(Mandatory = false)]
33+
public string Name { get; set; }
34+
35+
[Parameter(Mandatory = false)]
36+
public string Location { get; set; }
37+
38+
[Parameter(Mandatory = false)]
39+
public Hashtable Tags { get; set; }
40+
41+
[Parameter(Mandatory = false)]
42+
public SwitchParameter Force { get; set; }
43+
44+
/// <summary>
45+
/// Execute this cmdlet.
46+
/// </summary>
47+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
48+
public override void ExecuteCmdlet()
49+
{
50+
WriteWarning("You must be in AzureResourceManager mode to run Azure Data Factory cmdlets. To switch to AzureResourceManager mode, run Switch-AzureMode AzureResourceManager.");
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)