Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add scenario tests for container and context cmdlet

  • Loading branch information...
commit e5b31c7ad4eada30144b244b1819cce6994afd3a 1 parent 01b1e30
Yao xmbms authored
2  WindowsAzurePowershell/src/Management.ScenarioTest/Common/Constants.cs
View
@@ -18,6 +18,8 @@ public class Category
public const string Websites = "Websites";
+ public const string Storage = "Storage";
+
public const string Store = "Store";
}
}
6 WindowsAzurePowershell/src/Management.ScenarioTest/Management.ScenarioTest.csproj
View
@@ -118,7 +118,9 @@
<Compile Include="Common\PowerShellTest.cs" />
<Compile Include="Common\TestCredentialHelper.cs" />
<Compile Include="Common\WindowsAzurePowerShellTest.cs" />
+ <None Include="Resources\Storage\StorageContext.ps1" />
<Compile Include="StorageTests\StorageContainerTest.cs" />
+ <Compile Include="StorageTests\StorageContextTest.cs" />
<Compile Include="StoreTests\StoreTests.cs" />
<Compile Include="WebsitesTests\WebsitesTests.cs" />
<Compile Include="CredentialTests\CredentialTests.cs" />
@@ -187,6 +189,10 @@
<Project>{8bbe3c78-69c6-42fe-b1fe-b3aa24771ece}</Project>
<Name>Management.ServiceBus</Name>
</ProjectReference>
+ <ProjectReference Include="..\Management.Storage\Management.Storage.csproj">
+ <Project>{08cf7da7-0392-4a19-b79b-e1ff67cdb81a}</Project>
+ <Name>Management.Storage</Name>
+ </ProjectReference>
<ProjectReference Include="..\Management.Store\Management.Store.csproj">
<Project>{2ac37c6a-41de-4341-88a4-a79f209bba83}</Project>
<Name>Management.Store</Name>
110 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/Storage/StorageContainer.ps1
View
@@ -12,12 +12,118 @@
# limitations under the License.
# ----------------------------------------------------------------------------------
+$containerName = "testcredentials-storage";
+$containerPrefix = "testcredentials-";
+
<#
.SYNOPSIS
Tests using Get-AzureStorageContainer without container name.
#>
function Test-GetAzureStorageContainerWithoutContainerName
{
- Echo "Test";
- Get-AzureStorageContainer
+ $containers = Get-AzureStorageContainer;
+ Assert-True {$containers.Count -ge 1};
+ $container = $containers | ? {$_.Name -eq $containerName}
+ Assert-NotNull $container;
+}
+
+<#
+.SYNOPSIS
+Tests using Get-AzureStorageContainer with container name.
+#>
+function Test-GetAzureStorageContainerWithContainerName
+{
+ $containers = Get-AzureStorageContainer $containerName;
+ Assert-True {$containers.Count -eq 1};
+ Assert-AreEqual $containers[0].Name $containerName;
+}
+
+<#
+.SYNOPSIS
+Tests using Get-AzureStorageContainer with container prefix.
+#>
+function Test-GetAzureStorageContainerWithPrefix
+{
+ $containers = Get-AzureStorageContainer -Prefix $containerPrefix;
+ Assert-True {$containers.Count -ge 1};
+ $containers | % {Assert-True {$_.Name.StartsWith($containerPrefix)}}
+}
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContainer.
+#>
+function Test-NewAzureStorageContainer
+{
+ $randomName = [System.Guid]::NewGuid().ToString();
+ $container = New-AzureStorageContainer $randomName;
+ Assert-True {$container.Count -eq 1};
+ Assert-True {$container[0].Name -eq $randomName}
+ Assert-True {$container[0].PublicAccess.ToString() -eq "Off"}
+
+ try
+ {
+ $container[0].CloudBlobContainer.DeleteIfExists();
+ }
+ catch
+ {}
+}
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContainer with specified acl level
+#>
+function Test-NewAzureStorageContainerWithPermission
+{
+ $randomName = [System.Guid]::NewGuid().ToString();
+ $container = New-AzureStorageContainer $randomName -Permission Container;
+ Assert-True {$container[0].Name -eq $randomName}
+ Assert-True {$container[0].PublicAccess.ToString() -eq "Container"}
+
+ try
+ {
+ $container[0].CloudBlobContainer.DeleteIfExists();
+ }
+ catch
+ {}
+}
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContainer to create a container which already exists
+#>
+function Test-NewExistsAzureStorageContainer
+{
+ Assert-Throws {New-AzureStorageContainer $containerName} "Container '$containerName' already exists."
+}
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContainer with invalid container name
+#>
+function Test-NewExistsAzureStorageContainerWithInvalidContainerName
+{
+ $invalidName = "a";
+ Assert-Throws {New-AzureStorageContainer $invalidName} "Container name '$invalidName' is invalid."
+}
+
+<#
+.SYNOPSIS
+Tests using Remove-AzureStorageContainer
+#>
+function Test-RemoveAzureStorageContainer
+{
+ $randomName = [System.Guid]::NewGuid().ToString();
+ New-AzureStorageContainer $randomName
+ Remove-AzureStorageContainer $randomName -Force
}
+
+<#
+.SYNOPSIS
+Tests using Remove-AzureStorageContainer by container pipeline
+#>
+function Test-RemoveAzureStorageContainerByContainerPipeline
+{
+ $randomName = [System.Guid]::NewGuid().ToString();
+ New-AzureStorageContainer $randomName | Get-AzureStorageContainer | Remove-AzureStorageContainer -Force
+}
37 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/Storage/StorageContext.ps1
View
@@ -0,0 +1,37 @@
+# ----------------------------------------------------------------------------------
+#
+# 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.
+# ----------------------------------------------------------------------------------
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContext with anonymous storage account
+#>
+function Test-NewAnonymousStorageContext
+{
+ $account = "test";
+ $context = New-AzureStorageContext -StorageAccountName $account -Anonymous;
+ Assert-AreEqual $context.StorageAccountName "[Anonymous]"
+}
+
+<#
+.SYNOPSIS
+Tests using New-AzureStorageContext with storage account name and key
+#>
+function Test-NewStorageContextWithNameAndKey
+{
+ $account = "test";
+ $key = "XM+4nFQ832Qfi4mH/ChQwdQUmTqrZqbQTJWpAQZ6klWjTVsIBVZy5xNdCDje4EWP0gdXK9vIFAY8LOmz85Wmcg==";
+ $context = New-AzureStorageContext -StorageAccountName $account -StorageAccountKey $key -Protocol Https
+ Assert-AreEqual $context.StorageAccountName $account
+ Assert-True {$context.BlobEndPoint.ToString().StartsWith("https://")}
+}
11 WindowsAzurePowershell/src/Management.ScenarioTest/Resources/TestAzure.psd1
View
@@ -58,11 +58,12 @@ ScriptsToProcess = @()
# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = '.\Microsoft.WindowsAzure.Management.CloudService.dll',
- '.\Microsoft.WindowsAzure.Management.Service.dll',
- '.\Microsoft.WindowsAzure.Management.Websites.dll',
- '.\Microsoft.WindowsAzure.Management.ServiceManagement.dll',
- '.\Microsoft.WindowsAzure.Management.ServiceBus.dll',
- '.\Microsoft.WindowsAzure.Management.Store.dll'
+# '.\Microsoft.WindowsAzure.Management.Service.dll',
+# '.\Microsoft.WindowsAzure.Management.Websites.dll',
+# '.\Microsoft.WindowsAzure.Management.ServiceManagement.dll',
+# '.\Microsoft.WindowsAzure.Management.ServiceBus.dll',
+ '.\..\..\..\..\..\Package\Release\Microsoft.WindowsAzure.Management.Storage.dll'
+# '.\Microsoft.WindowsAzure.Management.Store.dll'
# Functions to export from this module
FunctionsToExport = '*'
60 WindowsAzurePowershell/src/Management.ScenarioTest/StorageTests/StorageContainerTest.cs
View
@@ -16,6 +16,7 @@ namespace Microsoft.WindowsAzure.Management.ScenarioTest.StorageTests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Management.ScenarioTest.Common;
+ using Microsoft.WindowsAzure.Management.Storage;
[TestClass]
public class StorageContainerTest : WindowsAzurePowerShellTest
@@ -23,13 +24,70 @@ public class StorageContainerTest : WindowsAzurePowerShellTest
public StorageContainerTest()
: base("Storage\\StorageContainer.ps1")
{
-
}
[TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
public void GetStorageContainerWithoutContainerName()
{
RunPowerShellTest("Test-GetAzureStorageContainerWithoutContainerName");
}
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void GetAzureStorageContainerWithPrefix()
+ {
+ RunPowerShellTest("Test-GetAzureStorageContainerWithPrefix");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewAzureStorageContainer()
+ {
+ RunPowerShellTest("Test-NewAzureStorageContainer");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewAzureStorageContainerWithPermission()
+ {
+ RunPowerShellTest("Test-NewAzureStorageContainerWithPermission");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewExistsAzureStorageContainer()
+ {
+ RunPowerShellTest("Test-NewExistsAzureStorageContainer");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewExistsAzureStorageContainerWithInvalidContainerName()
+ {
+ RunPowerShellTest("Test-NewExistsAzureStorageContainerWithInvalidContainerName");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void RemoveAzureStorageContainer()
+ {
+ RunPowerShellTest("Test-RemoveAzureStorageContainer");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void RemoveAzureStorageContainerByContainerPipeline()
+ {
+ RunPowerShellTest("Test-RemoveAzureStorageContainerByContainerPipeline");
+ }
}
}
44 WindowsAzurePowershell/src/Management.ScenarioTest/StorageTests/StorageContextTest.cs
View
@@ -0,0 +1,44 @@
+// ----------------------------------------------------------------------------------
+//
+// 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.
+// ----------------------------------------------------------------------------------
+
+namespace Microsoft.WindowsAzure.Management.ScenarioTest.StorageTests
+{
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using Microsoft.WindowsAzure.Management.ScenarioTest.Common;
+
+ [TestClass]
+ public class StorageContextTest : WindowsAzurePowerShellTest
+ {
+ public StorageContextTest()
+ : base("Storage\\StorageContext.ps1")
+ {
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewAnonymousStorageContext()
+ {
+ RunPowerShellTest("Test-NewAnonymousStorageContext");
+ }
+
+ [TestMethod]
+ [TestCategory(Category.All)]
+ [TestCategory(Category.Storage)]
+ public void NewStorageContextWithNameAndKey()
+ {
+ RunPowerShellTest("Test-NewStorageContextWithNameAndKey");
+ }
+ }
+}
5 WindowsAzurePowershell/src/Management.Storage/Model/ResourceModel/AzureStorageContext.cs
View
@@ -73,6 +73,11 @@ public AzureStorageContext(CloudStorageAccount account)
StorageAccountName = account.Credentials.AccountName;
Context = this;
Name = String.Empty;
+
+ if (string.IsNullOrEmpty(StorageAccountName))
+ {
+ StorageAccountName = Resources.AnonymousAccountName;
+ }
}
}
}
11 WindowsAzurePowershell/src/Management.Storage/Resources.Designer.cs
View
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.18010
+// Runtime Version:4.0.30319.18033
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -61,6 +61,15 @@ internal class Resources {
}
/// <summary>
+ /// Looks up a localized string similar to [Anonymous].
+ /// </summary>
+ internal static string AnonymousAccountName {
+ get {
+ return ResourceManager.GetString("AnonymousAccountName", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to {0} begin processing without ParameterSet..
/// </summary>
internal static string BeginProcessingWithoutParameterSetLog {
3  WindowsAzurePowershell/src/Management.Storage/Resources.resx
View
@@ -368,4 +368,7 @@
<data name="CannotGetStorageAccountFromEnvironmentVariable" xml:space="preserve">
<value>Can not get storage account from environment variable 'AZURE_STORAGE_CONNECTION_STRING'. Please check whether this environment variable is valid.</value>
</data>
+ <data name="AnonymousAccountName" xml:space="preserve">
+ <value>[Anonymous]</value>
+ </data>
</root>
6 WindowsAzurePowershell/src/Management/Cmdlets/Common/CmdletBase.cs
View
@@ -123,11 +123,11 @@ protected override void BeginProcessing()
{
if (string.IsNullOrEmpty(ParameterSetName))
{
- WriteVerboseWithTimestamp(String.Format(Resources.BeginProcessingWithoutParameterSetLog, this.GetType().Name));
+ WriteDebugWithTimestamp(String.Format(Resources.BeginProcessingWithoutParameterSetLog, this.GetType().Name));
}
else
{
- WriteVerboseWithTimestamp(String.Format(Resources.BeginProcessingWithParameterSetLog, this.GetType().Name, ParameterSetName));
+ WriteDebugWithTimestamp(String.Format(Resources.BeginProcessingWithParameterSetLog, this.GetType().Name, ParameterSetName));
}
base.BeginProcessing();
@@ -139,7 +139,7 @@ protected override void BeginProcessing()
protected override void EndProcessing()
{
string message = string.Format(Resources.EndProcessingLog, this.GetType().Name);
- WriteVerboseWithTimestamp(message);
+ WriteDebugWithTimestamp(message);
base.EndProcessing();
}
Please sign in to comment.
Something went wrong with that request. Please try again.