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
2 changes: 1 addition & 1 deletion src/SDKs/Dns/AzSdk.RP.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--This file and it's contents are updated at build time moving or editing might result in build failure. Take due deligence while editing this file-->
<PropertyGroup>
<AzureApiTag>Network_2017-10-01;</AzureApiTag>
<AzureApiTag>Network_2018-03-01-preview;</AzureApiTag>
<PackageTags>$(PackageTags);$(CommonTags);$(AzureApiTag);</PackageTags>
</PropertyGroup>
</Project>
7 changes: 2 additions & 5 deletions src/SDKs/Dns/Dns.Tests/Dns.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Network" Version="14.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
</ItemGroup>

<ItemGroup>
<!--<PackageReference Include="Microsoft.Azure.Management.Dns" Version="1.8.0-preview" />-->
<ProjectReference Include="..\Management.Dns\Microsoft.Azure.Management.Dns.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<!--Do not remove until VS Test Tools fixes #472-->
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="15.3.0" />
</ItemGroup>
</Project>
</Project>
115 changes: 91 additions & 24 deletions src/SDKs/Dns/Dns.Tests/Helpers/ResourceGroupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.Dns.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Test;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;
using Microsoft.Azure.Management.Dns.Models;
using SubResource = Microsoft.Azure.Management.Dns.Models.SubResource;

namespace Microsoft.Azure.Management.Dns.Testing
{
using Rest.ClientRuntime.Azure.TestFramework;

public static class ResourceGroupHelper
{
// DNS resources are in location "global" but resource groups cannot be in that same location
private const string ResourceLocation = "Central US";

private static readonly Random RandomGenerator = new Random();

/// <summary>
/// Default constructor for management clients, using the TestSupport Infrastructure
/// </summary>
Expand All @@ -25,8 +32,7 @@ public static ResourceManagementClient GetResourcesClient(
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<ResourceManagementClient>(
handlers: handler);
var client = context.GetServiceClient<ResourceManagementClient>(handlers: handler);
return client;
}

Expand All @@ -35,15 +41,28 @@ public static ResourceManagementClient GetResourcesClient(
/// using the TestSupport Infrastructure
/// </summary>
/// <param name="handler"></param>
/// <returns>A resource management client, created from the current context
/// (environment variables)</returns>
/// <returns>A resource management client, created from the current context (environment variables)</returns>
public static DnsManagementClient GetDnsClient(
MockContext context,
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<DnsManagementClient>(
handlers: handler);
var client = context.GetServiceClient<DnsManagementClient>(handlers: handler);
return client;
}

/// <summary>
/// Default constructor for network clients,
/// using the TestSupport Infrastructure
/// </summary>
/// <param name="handler"></param>
/// <returns>A netowrk management client, created from the current context (environment variables)</returns>
public static NetworkManagementClient GetNetworkClient(
MockContext context,
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<NetworkManagementClient>(handlers: handler);
return client;
}

Expand All @@ -68,8 +87,7 @@ public static string GetResourceLocation(
parts[1],
StringComparison.OrdinalIgnoreCase))
{
location = resource.Locations.FirstOrDefault(
loca => !string.IsNullOrEmpty(loca));
location = resource.Locations.FirstOrDefault(loca => !string.IsNullOrEmpty(loca));
}
}

Expand All @@ -79,22 +97,13 @@ public static string GetResourceLocation(
public static ResourceGroup CreateResourceGroup(
ResourceManagementClient resourcesClient)
{
string resourceGroupName =
TestUtilities.GenerateName("hydratestdnsrg");

// DNS resources are in location "global" but resource groups
// can't be in that same location
string location = "Central US";

Assert.False(
string.IsNullOrEmpty(location),
"CSM did not return any valid locations for DNS resources");
string resourceGroupName = TestUtilities.GenerateName("hydratestdnsrg");

var response = resourcesClient.ResourceGroups.CreateOrUpdate(
resourceGroupName,
new ResourceGroup
{
Location = location
Location = ResourceLocation
});

return response;
Expand All @@ -109,13 +118,71 @@ public static Zone CreateZone(
return dnsClient.Zones.CreateOrUpdate(
resourceGroup.Name,
zoneName,
new Microsoft.Azure.Management.Dns.Models.Zone
new Zone
{
ZoneType = ZoneType.Public,
Location = location,
Etag = null
},
null,
null);
}

public static Zone CreatePrivateZone(
DnsManagementClient dnsClient,
string zoneName,
string location,
IList<SubResource> registrationVnets,
IList<SubResource> resolutionVnets,
ResourceGroup resourceGroup)
{
return dnsClient.Zones.CreateOrUpdate(
resourceGroup.Name,
zoneName,
new Zone
{
ZoneType = ZoneType.Private,
Location = location,
Etag = null,
RegistrationVirtualNetworks = registrationVnets,
ResolutionVirtualNetworks = resolutionVnets,
},
null,
null);
}

public static VirtualNetwork CreateVirtualNetwork(
string resourceGroupName,
NetworkManagementClient networkClient)
{
var virtualNetworkName = TestUtilities.GenerateName("hydratestdnsvn");
var subnetName = TestUtilities.GenerateName("hydratestdnssubnet");

var vnet = new VirtualNetwork
{
AddressSpace = new AddressSpace
{
AddressPrefixes = new List<string>
{
"10.0.0.0/16"
}
},
Subnets = new List<Subnet>
{
new Subnet
{
Name = subnetName,
AddressPrefix = "10.0." + RandomGenerator.Next(0, 255) + ".0/24"
}
},
Location = ResourceLocation
};

var putVnetResponse = networkClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, virtualNetworkName, vnet);
Assert.Equal("Succeeded", putVnetResponse.ProvisioningState);

var getVnetResponse = networkClient.VirtualNetworks.Get(resourceGroupName, virtualNetworkName);
return getVnetResponse;
}
}
}
Loading