Skip to content

fix whitespace bugs for hub and pipeline & add some negative test cases #2

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

Merged
merged 6 commits into from
Nov 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ function Test-DataFactoryPiping

# Test the data factory no longer exists
Assert-ThrowsContains { Get-AzureDataFactory -ResourceGroupName $rgname -Name $dfname } "ResourceNotFound"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PSArgumentNullException>(() => 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<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());

// Assert
Assert.Contains("Value cannot be null", exception.Message);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanListHubs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PSArgumentNullException>(() => 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<PSArgumentNullException>(() => cmdlet.ExecuteCmdlet());

// Assert
Assert.Contains("Value cannot be null", exception.Message);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanListPipelines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28113,4 +28113,14 @@
</maml:navigationLink>
</maml:relatedLinks>
</command:command>
<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">
<command:details>
<command:name>New-AzureDataFactory</command:name>
<maml:description>
<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>
</maml:description>
<command:verb>New</command:verb>
<command:noun>AzureDataFactory</command:noun>
</command:details>
</command:command>
</helpItems>
1 change: 1 addition & 0 deletions src/ServiceManagement/Services/Commands/Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<Compile Include="MediaServices\NewAzureMediaServiceCommand.cs" />
<Compile Include="MediaServices\NewAzureMediaServiceKeyCommand.cs" />
<Compile Include="MediaServices\RemoveAzureMediaServiceCommand.cs" />
<Compile Include="DataFactories\NewAzureDataFactoryStubCommand.cs" />
<Compile Include="Scheduler\GetSchedulerJobCollectionCommand.cs" />
<Compile Include="Scheduler\GetSchedulerJobCommand.cs" />
<Compile Include="Scheduler\GetSchedulerJobHistoryCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// In order to show warning for ADF cmdlets if client is using service management mode
/// </summary>
[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; }

/// <summary>
/// Execute this cmdlet.
/// </summary>
[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.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract message in Resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it but it won't work if I put the stub command into Command.Resource project since if the command was there, it will only work in the AzureResourceManager Mode

}
}
}