diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1 b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1 index cd4867b2d57f..a0fc1ac31145 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1 +++ b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryTests.ps1 @@ -124,4 +124,4 @@ function Test-DataFactoryPiping # Test the data factory no longer exists Assert-ThrowsContains { Get-AzureDataFactory -ResourceGroupName $rgname -Name $dfname } "ResourceNotFound" -} +} \ No newline at end of file diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs index 69b5378fcb5f..e7e7a3d58743 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetHubTests.cs @@ -12,10 +12,12 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System.Collections.Generic; using Microsoft.Azure.Commands.DataFactories.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Moq; +using System; +using System.Collections.Generic; +using System.Management.Automation; using Xunit; namespace Microsoft.Azure.Commands.DataFactories.Test @@ -78,6 +80,30 @@ public void CanGetHub() commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); } + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetHubWithEmptyName() + { + // Action + cmdlet.Name = String.Empty; + Exception exception = Assert.Throws(() => cmdlet.ExecuteCmdlet()); + + // Assert + Assert.Contains("Value cannot be null", exception.Message); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetHubWithWhiteSpaceName() + { + // Action + cmdlet.Name = " "; + Exception exception = Assert.Throws(() => cmdlet.ExecuteCmdlet()); + + // Assert + Assert.Contains("Value cannot be null", exception.Message); + } + [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CanListHubs() diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs index 8fa189de9633..e0ec60dd4d13 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories.Test/UnitTests/GetPipelineTests.cs @@ -12,10 +12,12 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System.Collections.Generic; using Microsoft.Azure.Commands.DataFactories.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Moq; +using System; +using System.Collections.Generic; +using System.Management.Automation; using Xunit; namespace Microsoft.Azure.Commands.DataFactories.Test @@ -78,6 +80,30 @@ public void CanGetPipeline() commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once()); } + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetPipelineWithEmptyName() + { + // Action + cmdlet.Name = String.Empty; + Exception exception = Assert.Throws(() => cmdlet.ExecuteCmdlet()); + + // Assert + Assert.Contains("Value cannot be null", exception.Message); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetPipelineWithWhiteSpaceName() + { + // Action + cmdlet.Name = " "; + Exception exception = Assert.Throws(() => cmdlet.ExecuteCmdlet()); + + // Assert + Assert.Contains("Value cannot be null", exception.Message); + } + [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CanListPipelines() diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs b/src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs index 666bdddd5e6d..86395da92486 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Hubs/GetAzureDataFactoryHubCommand.cs @@ -12,12 +12,12 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.Azure.Commands.DataFactories.Models; +using Microsoft.Azure.Commands.DataFactories.Properties; using System.Collections.Generic; +using System.Globalization; using System.Management.Automation; using System.Security.Permissions; -using Microsoft.Azure.Commands.DataFactories.Models; -using System.Globalization; -using Microsoft.Azure.Commands.DataFactories.Properties; namespace Microsoft.Azure.Commands.DataFactories { @@ -31,6 +31,12 @@ public class GetAzureDataFactoryHubCommand : HubContextBaseCmdlet [EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)] public override void ExecuteCmdlet() { + // ValidationNotNullOrEmpty doesn't handle whitespaces well + if (Name != null && string.IsNullOrWhiteSpace(Name)) + { + throw new PSArgumentNullException("Name"); + } + if (ParameterSetName == ByFactoryObject) { if (DataFactory == null) diff --git a/src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs b/src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs index 5899cf9baeac..9ed7fe5bf516 100644 --- a/src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs +++ b/src/ResourceManager/DataFactories/Commands.DataFactories/Pipelines/GetAzureDataFactoryPipelineCommand.cs @@ -12,14 +12,14 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.Azure.Commands.DataFactories.Models; +using Microsoft.Azure.Commands.DataFactories.Properties; using System; +using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Management.Automation; using System.Security.Permissions; -using Microsoft.Azure.Commands.DataFactories.Models; -using System.Collections; -using System.Globalization; -using Microsoft.Azure.Commands.DataFactories.Properties; namespace Microsoft.Azure.Commands.DataFactories { @@ -42,6 +42,12 @@ public class GetAzureDataFactoryPipelineCommand : DataFactoryBaseCmdlet [EnvironmentPermission(SecurityAction.Demand, Unrestricted = true)] public override void ExecuteCmdlet() { + // ValidationNotNullOrEmpty doesn't handle whitespaces well + if (Name != null && string.IsNullOrWhiteSpace(Name)) + { + throw new PSArgumentNullException("Name"); + } + if (ParameterSetName == ByFactoryObject) { if (DataFactory == null) diff --git a/src/ServiceManagement/Services/Commands.Utilities/Microsoft.WindowsAzure.Commands.dll-Help.xml b/src/ServiceManagement/Services/Commands.Utilities/Microsoft.WindowsAzure.Commands.dll-Help.xml index e9c58c344e82..6e306d40f9a0 100644 --- a/src/ServiceManagement/Services/Commands.Utilities/Microsoft.WindowsAzure.Commands.dll-Help.xml +++ b/src/ServiceManagement/Services/Commands.Utilities/Microsoft.WindowsAzure.Commands.dll-Help.xml @@ -28113,4 +28113,14 @@ + + + New-AzureDataFactory + + You must be in AzureResourceManager mode to run Azure Data Factory cmdlets. To switch to AzureResourceManager mode, run Switch-AzureMode AzureResourceManager. + + New + AzureDataFactory + + diff --git a/src/ServiceManagement/Services/Commands/Commands.csproj b/src/ServiceManagement/Services/Commands/Commands.csproj index 476a8dfec958..88ceee9f7525 100644 --- a/src/ServiceManagement/Services/Commands/Commands.csproj +++ b/src/ServiceManagement/Services/Commands/Commands.csproj @@ -209,6 +209,7 @@ + diff --git a/src/ServiceManagement/Services/Commands/DataFactories/NewAzureDataFactoryStubCommand.cs b/src/ServiceManagement/Services/Commands/DataFactories/NewAzureDataFactoryStubCommand.cs new file mode 100644 index 000000000000..059c6f1f4f39 --- /dev/null +++ b/src/ServiceManagement/Services/Commands/DataFactories/NewAzureDataFactoryStubCommand.cs @@ -0,0 +1,53 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.WindowsAzure.Commands.DataFactories +{ + /// + /// In order to show warning for ADF cmdlets if client is using service management mode + /// + [Cmdlet(VerbsCommon.New, "AzureDataFactory")] + public class NewAzureDataFactoryStubCommand : AzurePSCmdlet + { + //Just to make sure there is no error messages for parameters when clients use "New-AzureDataFactory" + [Parameter(Mandatory = false)] + public string ResourceGroupName { get; set; } + + [Parameter(Mandatory = false)] + public string Name { get; set; } + + [Parameter(Mandatory = false)] + public string Location { get; set; } + + [Parameter(Mandatory = false)] + public Hashtable Tags { get; set; } + + [Parameter(Mandatory = false)] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + WriteWarning("You must be in AzureResourceManager mode to run Azure Data Factory cmdlets. To switch to AzureResourceManager mode, run Switch-AzureMode AzureResourceManager."); + } + } +}