Skip to content
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 @@ -12,9 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="[5.0.2-preview,6.0)" />

<!--<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="1.2.0-preview" />-->
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="[7.0.0-preview,7.0)" />
<ProjectReference Include="..\Management.ContainerRegistry\Microsoft.Azure.Management.ContainerRegistry.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Azure.Management.ContainerRegistry;
using Microsoft.Azure.Management.ContainerRegistry.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Resource = Microsoft.Azure.Management.ContainerRegistry.Models.Resource;
using Sku = Microsoft.Azure.Management.ContainerRegistry.Models.Sku;
using SkuName = Microsoft.Azure.Management.ContainerRegistry.Models.SkuName;

namespace ContainerRegistry.Tests
{
Expand All @@ -25,23 +28,30 @@ public class ContainerRegistryTestUtilities
{ "key1","value1"},
{ "key2","value2"}
};
public static Dictionary<string, string> DefaultNewTags = new Dictionary<string, string>
{
{ "key2","value2"},
{ "key3","value3"},
{ "key4","value4"}
};

public static string DefaultWebhookServiceUri = "http://www.microsoft.com";
public static string DefaultWebhookScope = "hello-world";

public static string GetDefaultRegistryLocation(ResourceManagementClient client)
{
Provider provider = client.Providers.Get(ContainerRegistryNamespace);
ProviderResourceType resourceType = provider.ResourceTypes.First(
t => StringComparer.OrdinalIgnoreCase.Equals(t.ResourceType, ContainerRegistryResourceType));
string location = resourceType.Locations.First();
return NormalizeLocation(location);
return resourceType.Locations.First();
}

public static string GetNonDefaultRegistryLocation(ResourceManagementClient client)
public static string GetNonDefaultRegistryLocation(ResourceManagementClient client, string defaultLocation)
{
Provider provider = client.Providers.Get(ContainerRegistryNamespace);
ProviderResourceType resourceType = provider.ResourceTypes.First(
t => StringComparer.OrdinalIgnoreCase.Equals(t.ResourceType, ContainerRegistryResourceType));
string location = resourceType.Locations.ToArray()[1];
return NormalizeLocation(location);
return resourceType.Locations.First(l => !NormalizeLocation(l).Equals(defaultLocation));
}

public static ResourceManagementClient GetResourceManagementClient(MockContext context, RecordedDelegatingHandler handler)
Expand All @@ -67,89 +77,117 @@ public static ContainerRegistryManagementClient GetContainerRegistryManagementCl

public static ResourceGroup CreateResourceGroup(ResourceManagementClient client)
{
var rgName = TestUtilities.GenerateName("acr_rg");

return client.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup
{
Location = GetDefaultRegistryLocation(client)
});
return client.ResourceGroups.CreateOrUpdate(
TestUtilities.GenerateName("acr_rg"),
new ResourceGroup
{
Location = GetDefaultRegistryLocation(client)
});
}

public static string CreateStorageAccount(StorageManagementClient client, ResourceGroup resourceGroup)
public static StorageAccount CreateStorageAccount(StorageManagementClient client, ResourceGroup resourceGroup)
{
string storageName = TestUtilities.GenerateName("acrstorage");

var createRequest = client.StorageAccounts.Create(resourceGroup.Name, storageName, new StorageAccountCreateParameters
{
Location = resourceGroup.Location,
Sku = new Microsoft.Azure.Management.Storage.Models.Sku { Name = SkuName.StandardLRS },
Kind = Kind.Storage
});

return storageName;
return client.StorageAccounts.Create(
resourceGroup.Name,
TestUtilities.GenerateName("acrstorage"),
new StorageAccountCreateParameters
{
Location = resourceGroup.Location,
Sku = new Microsoft.Azure.Management.Storage.Models.Sku
{
Name = Microsoft.Azure.Management.Storage.Models.SkuName.StandardLRS
},
Kind = Kind.Storage
});
}

public static string CreateContainerRegistry(ContainerRegistryManagementClient client, ResourceGroup resourceGroup, string storageName, string storageKey)
public static Registry CreateClassicContainerRegistry(ContainerRegistryManagementClient client, ResourceGroup resourceGroup, StorageAccount storageAccount)
{
string registryName = TestUtilities.GenerateName("acrregistry");
RegistryCreateParameters parameters = GetDefaultRegistryCreateParameters(resourceGroup, storageName, storageKey);

var createRequest = client.Registries.Create(resourceGroup.Name, registryName, parameters);

return registryName;
return client.Registries.Create(
resourceGroup.Name,
TestUtilities.GenerateName("acrregistry"),
new Registry
{
Location = resourceGroup.Location,
Sku = new Sku
{
Name = SkuName.Classic
},
StorageAccount = new StorageAccountProperties
{
Id = storageAccount.Id
},
Tags = DefaultTags
});
}

public static RegistryCreateParameters GetDefaultRegistryCreateParameters(ResourceGroup resourceGroup, string storageName, string storageKey)
public static Registry CreateManagedContainerRegistry(ContainerRegistryManagementClient client, string resourceGroupName, string location)
{
RegistryCreateParameters parameters = new RegistryCreateParameters
{
Location = resourceGroup.Location,
Sku = new Microsoft.Azure.Management.ContainerRegistry.Models.Sku
return client.Registries.Create(
resourceGroupName,
TestUtilities.GenerateName("acrregistry"),
new Registry
{
Name = "Basic"
},
StorageAccount = new StorageAccountParameters
Location = location,
Sku = new Sku
{
Name = SkuName.Premium
},
Tags = DefaultTags
});
}

public static Webhook CreatedContainerRegistryWebhook(ContainerRegistryManagementClient client, string resourceGroupName, string registryName, string location)
{
return client.Webhooks.Create(
resourceGroupName,
registryName,
TestUtilities.GenerateName("acrwebhook"),
new WebhookCreateParameters
{
Name = storageName,
AccessKey = storageKey
},
Tags = DefaultTags
};
Location = location,
ServiceUri = DefaultWebhookServiceUri,
Actions = new List<string>() { WebhookAction.Push },
Tags = DefaultTags
});
}

return parameters;
public static Replication CreatedContainerRegistryReplication(ContainerRegistryManagementClient client, string resourceGroupName, string registryName, string location)
{
return client.Replications.Create(
resourceGroupName,
registryName,
NormalizeLocation(location),
location,
DefaultTags);
}

public static string GetStorageAccessKey(StorageManagementClient client, ResourceGroup resourceGroup, string storageName)
public static void ValidateResourceDefaultTags(Resource resource)
{
return client.StorageAccounts.ListKeys(resourceGroup.Name, storageName).Keys[0].Value;
ValidateResource(resource);
Assert.NotNull(resource.Tags);
Assert.Equal(2, resource.Tags.Count);
Assert.Equal("value1", resource.Tags["key1"]);
Assert.Equal("value2", resource.Tags["key2"]);
}

public static void VerifyRegistryProperties(Registry registry, string storageName, bool useDefaults)
{
Assert.NotNull(registry);
Assert.NotNull(registry.Id);
Assert.NotNull(registry.Name);
Assert.NotNull(registry.Location);
Assert.NotNull(registry.Sku);
Assert.Equal(registry.Sku.Name, "Basic");
Assert.Equal(registry.Sku.Tier, Microsoft.Azure.Management.ContainerRegistry.Models.SkuTier.Basic);
Assert.Equal(registry.ProvisioningState, Microsoft.Azure.Management.ContainerRegistry.Models.ProvisioningState.Succeeded);
Assert.NotNull(registry.AdminUserEnabled);
Assert.NotNull(registry.LoginServer);
Assert.NotNull(registry.CreationDate);
Assert.NotNull(registry.StorageAccount);
Assert.NotNull(registry.StorageAccount.Name);

Assert.Equal(registry.StorageAccount.Name, storageName);

if (useDefaults)
{
Assert.Equal(registry.AdminUserEnabled, false);
Assert.NotNull(registry.Tags);
Assert.Equal(2, registry.Tags.Count);
Assert.Equal(registry.Tags["key1"], "value1");
Assert.Equal(registry.Tags["key2"], "value2");
}
public static void ValidateResourceDefaultNewTags(Resource resource)
{
ValidateResource(resource);
Assert.NotNull(resource.Tags);
Assert.Equal(3, resource.Tags.Count);
Assert.Equal("value2", resource.Tags["key2"]);
Assert.Equal("value3", resource.Tags["key3"]);
Assert.Equal("value4", resource.Tags["key4"]);
}

private static void ValidateResource(Resource resource)
{
Assert.NotNull(resource);
Assert.NotNull(resource.Id);
Assert.NotNull(resource.Name);
Assert.NotNull(resource.Type);
Assert.NotNull(resource.Location);
}

private static string NormalizeLocation(string location)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading