Skip to content

Commit 67c89b2

Browse files
Covering the case where you can activate an application package with no filePath needed
1 parent beb388e commit 67c89b2

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

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

Lines changed: 26 additions & 0 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;
@@ -66,6 +67,31 @@ public void UploadBatchApplicationPackageTest()
6667
batchClientMock.Verify(b => b.UploadAndActivateApplicationPackage(resourceGroup, accountName, applicationId, version, filePath, format, false), Times.Once());
6768
}
6869

70+
[Fact]
71+
[Trait(Category.AcceptanceType, Category.CheckIn)]
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+
6995
[Fact]
7096
[Trait(Category.AcceptanceType, Category.CheckIn)]
7197
public void ActivateApplicationPackageOnly()

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,40 @@ namespace Microsoft.Azure.Commands.Batch
2222
[Cmdlet(VerbsCommon.New, Constants.AzureRmBatchApplicationPackage), 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 UpdateAndActivateSet = "UpdateAndActivate";
27+
28+
[Parameter(Position = 0, ParameterSetName = UpdateAndActivateSet, 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 = UpdateAndActivateSet, 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 = UpdateAndActivateSet, 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]
41+
3542
public string ApplicationId { get; set; }
3643

37-
[Parameter(Position = 3, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
44+
[Parameter(Position = 3, ParameterSetName = UpdateAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
45+
[Parameter(Position = 3, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the version of the application.")]
3846
[ValidateNotNullOrEmpty]
3947
public string ApplicationVersion { get; set; }
4048

41-
[Parameter(Position = 4, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
49+
[Parameter(Position = 4, ParameterSetName = UpdateAndActivateSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
50+
[Parameter(Position = 4, ParameterSetName = ActivateOnlySet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "Specifies the format of the application package binary file.")]
4251
[ValidateNotNullOrEmpty]
4352
public string Format { get; set; }
4453

45-
[Parameter(ValueFromPipelineByPropertyName = true)]
54+
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = UpdateAndActivateSet, Mandatory = true, HelpMessage = "Specifies the file path of the application that will be uploaded to Azure Storage.")]
4655
[ValidateNotNullOrEmpty]
4756
public string FilePath { get; set; }
4857

49-
[Parameter(ValueFromPipelineByPropertyName = true)]
58+
[Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = ActivateOnlySet)]
5059
[ValidateNotNullOrEmpty]
5160
public SwitchParameter ActivateOnly { get; set; }
5261

src/ResourceManager/AzureBatch/Commands.Batch/Models/BatchClient.Applications.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ public virtual PSApplicationPackage UploadAndActivateApplicationPackage(
184184
}
185185
else
186186
{
187-
// Checks File path and resourceGroupName is valid
187+
if (string.IsNullOrEmpty(filePath))
188+
{
189+
throw new ArgumentNullException(Resources.NewAppPackageNoPathSpecified);
190+
}
191+
188192
if (!File.Exists(filePath))
189193
{
190194
throw new FileNotFoundException(string.Format(Resources.FileNotFound, filePath), filePath);

src/ResourceManager/AzureBatch/Commands.Batch/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/AzureBatch/Commands.Batch/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@
442442
<data name="FileNotFound" xml:space="preserve">
443443
<value>File not found {0}.</value>
444444
</data>
445+
<data name="NewAppPackageNoPathSpecified" xml:space="preserve">
446+
<value>When uploading a new application package, you must specify a value for the FilePath parameter.</value>
447+
</data>
445448
<data name="FailedToUpload" xml:space="preserve">
446449
<value>Failed to upload {0} to Azure Storage. {1}.</value>
447450
</data>

0 commit comments

Comments
 (0)