Skip to content

Commit 16fe53f

Browse files
authored
Merge pull request Azure#561 from Azure/dev
huangpf PR: dev <- Azure:dev
2 parents 992ad31 + a197579 commit 16fe53f

File tree

13 files changed

+192
-64
lines changed

13 files changed

+192
-64
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/Applications/NewBatchApplicationPackageCommandTests.cs

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

15+
using System;
1516
using System.Management.Automation;
1617
using Microsoft.Azure.Commands.Batch.Models;
1718
using Microsoft.WindowsAzure.Commands.ScenarioTest;
@@ -68,23 +69,46 @@ public void UploadBatchApplicationPackageTest()
6869

6970
[Fact]
7071
[Trait(Category.AcceptanceType, Category.CheckIn)]
71-
public void ActivateApplicationPackage()
72+
public void UploadBatchApplicationPackageNoFilePathProvidedTest()
73+
{
74+
string accountName = "account01";
75+
string resourceGroup = "resourceGroup";
76+
string applicationId = "applicationId";
77+
string version = "version";
78+
string format = "zip";
79+
string filePath = "";
80+
81+
cmdlet.BatchClient = new BatchClient();
82+
83+
cmdlet.AccountName = accountName;
84+
cmdlet.ResourceGroupName = resourceGroup;
85+
cmdlet.ApplicationId = applicationId;
86+
cmdlet.ApplicationVersion = version;
87+
cmdlet.FilePath = filePath;
88+
cmdlet.Format = format;
89+
cmdlet.ActivateOnly = false;
90+
91+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
92+
93+
}
94+
95+
[Fact]
96+
[Trait(Category.AcceptanceType, Category.CheckIn)]
97+
public void ActivateApplicationPackageOnly()
7298
{
7399
string accountName = "account01";
74100
string resourceGroup = "resourceGroup";
75101
string applicationId = "applicationId";
76-
string filePath = "~/fake/filepath";
77102
string version = "version";
78103
string format = "zip";
79104

80105
PSApplicationPackage applicationPackageResponse = new PSApplicationPackage();
81106

82-
batchClientMock.Setup(b => b.UploadAndActivateApplicationPackage(resourceGroup, accountName, applicationId, version, filePath, format, true)).Returns(applicationPackageResponse);
107+
batchClientMock.Setup(b => b.UploadAndActivateApplicationPackage(resourceGroup, accountName, applicationId, version, null, format, true)).Returns(applicationPackageResponse);
83108

84109
cmdlet.AccountName = accountName;
85110
cmdlet.ResourceGroupName = resourceGroup;
86111
cmdlet.ApplicationId = applicationId;
87-
cmdlet.FilePath = filePath;
88112
cmdlet.ApplicationVersion = version;
89113
cmdlet.Format = format;
90114
cmdlet.ActivateOnly = true;
@@ -93,7 +117,7 @@ public void ActivateApplicationPackage()
93117
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
94118
cmdlet.ExecuteCmdlet();
95119

96-
batchClientMock.Verify(b => b.UploadAndActivateApplicationPackage(resourceGroup, accountName, applicationId, version, filePath, format, true), Times.Once());
120+
batchClientMock.Verify(b => b.UploadAndActivateApplicationPackage(resourceGroup, accountName, applicationId, version, null, format, true), Times.Once());
97121
}
98122
}
99123
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/BatchApplicationTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ public void TestCreatePoolWithApplicationPackage()
101101
{
102102
return new string[]
103103
{
104-
string.Format(string.Format("Test-CreatePoolWithApplicationPackage '{0}' '{1}' '{2}' '{3}'", id, version,
105-
poolId, filePath))
104+
string.Format(string.Format("Test-CreatePoolWithApplicationPackage '{0}' '{1}' '{2}'", id, version, poolId))
106105
};
107106
},
108107
() =>
@@ -130,8 +129,7 @@ public void TestUpdatePoolWithApplicationPackage()
130129
{
131130
return new string[]
132131
{
133-
string.Format("Test-UpdatePoolWithApplicationPackage '{0}' '{1}' '{2}' '{3}'", id, version,
134-
poolId, filePath)
132+
string.Format("Test-UpdatePoolWithApplicationPackage '{0}' '{1}' '{2}'", id, version, poolId)
135133
};
136134
},
137135
() =>

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/BatchApplicationTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Test-UploadApplicationPackage
4848
# Setup
4949
$context = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext
5050

51-
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -FilePath $filePath -format "zip" -Activate
51+
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -format "zip" -ActivateOnly
5252

5353
Assert-AreEqual $applicationId $addAppPack.Id
5454
Assert-AreEqual $applicationVersion $addAppPack.Version
@@ -68,7 +68,7 @@ function Test-UpdateApplicationPackage
6868

6969
$beforeUpdateApp = Get-AzureRmBatchApplication -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId
7070

71-
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -FilePath $filePath -format "zip" -Activate
71+
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -format "zip" -ActivateOnly
7272
Set-AzureRmBatchApplication -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -displayName $newDisplayName -defaultVersion $applicationVersion
7373

7474
$afterUpdateApp = Get-AzureRmBatchApplication -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId
@@ -91,7 +91,7 @@ function Test-CreatePoolWithApplicationPackage
9191

9292
try
9393
{
94-
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -FilePath $filePath -format "zip" -Activate
94+
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -format "zip" -ActivateOnly
9595

9696
Assert-AreEqual $applicationId $addAppPack.Id
9797
Assert-AreEqual $applicationVersion $addAppPack.Version
@@ -126,7 +126,7 @@ function Test-UpdatePoolWithApplicationPackage
126126

127127
$context = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext
128128

129-
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -FilePath $filePath -format "zip" -Activate
129+
$addAppPack = New-AzureRmBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationId $applicationId -ApplicationVersion $applicationVersion -format "zip" -ActivateOnly
130130

131131
Assert-AreEqual $applicationId $addAppPack.Id
132132
Assert-AreEqual $applicationVersion $addAppPack.Version

src/ResourceManager/AzureBatch/Commands.Batch/Applications/NewBatchApplicationPackageCommand.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,42 @@
1919

2020
namespace Microsoft.Azure.Commands.Batch
2121
{
22-
[Cmdlet(VerbsCommon.New, Constants.AzureRmBatchApplicationPackage), OutputType(typeof(PSApplicationPackage))]
22+
[Cmdlet(VerbsCommon.New, Constants.AzureRmBatchApplicationPackage, DefaultParameterSetName = UploadAndActivateSet), OutputType(typeof(PSApplicationPackage))]
2323
public class NewBatchApplicationPackageCommand : BatchCmdletBase
2424
{
25-
[Parameter(Position = 0, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the Batch account.")]
25+
internal const string ActivateOnlySet = "ActivateOnly";
26+
internal const string UploadAndActivateSet = "UpdateAndActivate";
27+
28+
[Parameter(Position = 0, ParameterSetName = UploadAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the Batch account.")]
29+
[Parameter(Position = 0, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the Batch account.")]
2630
[ValidateNotNullOrEmpty]
2731
public string AccountName { get; set; }
2832

29-
[Parameter(Position = 1, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the resource group that contains the Batch account.")]
33+
[Parameter(Position = 1, ParameterSetName = UploadAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the resource group that contains the Batch account.")]
34+
[Parameter(Position = 1, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the name of the resource group that contains the Batch account.")]
3035
[ValidateNotNullOrEmpty]
3136
public string ResourceGroupName { get; set; }
3237

33-
[Parameter(Position = 2, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the id of the application.")]
38+
[Parameter(Position = 2, ParameterSetName = UploadAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the id of the application.")]
39+
[Parameter(Position = 2, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the id of the application.")]
3440
[ValidateNotNullOrEmpty]
3541
public string ApplicationId { get; set; }
3642

37-
[Parameter(Position = 3, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
43+
[Parameter(Position = 3, ParameterSetName = UploadAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
44+
[Parameter(Position = 3, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
3845
[ValidateNotNullOrEmpty]
3946
public string ApplicationVersion { get; set; }
4047

41-
[Parameter(Position = 4, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the file to be uploaded as the application package binary file.")]
48+
[Parameter(Position = 4, ParameterSetName = UploadAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
49+
[Parameter(Position = 4, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
4250
[ValidateNotNullOrEmpty]
43-
public string FilePath { get; set; }
51+
public string Format { get; set; }
4452

45-
[Parameter(Position = 5, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
53+
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = UploadAndActivateSet, Mandatory = true, HelpMessage = "Specifies the file path of the application that will be uploaded to Azure Storage.")]
4654
[ValidateNotNullOrEmpty]
47-
public string Format { get; set; }
55+
public string FilePath { get; set; }
4856

49-
[Parameter(Position = 6, ValueFromPipelineByPropertyName = true)]
57+
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ActivateOnlySet)]
5058
[ValidateNotNullOrEmpty]
5159
public SwitchParameter ActivateOnly { get; set; }
5260

0 commit comments

Comments
 (0)