Skip to content

Commit

Permalink
PublicIpAddressObject
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Oct 14, 2017
1 parent ebfa508 commit 3237c8e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Xunit;
using Microsoft.Azure.Management.Compute;
using System.Threading.Tasks;

namespace Azure.Experiments.Tests
{
public class ComputeTest
{
[Fact]
public async void ResourceGroupTest()
public async Task ResourceGroupTest()
{
var c = Credentials.Get();
var rg = new ResourceGroupObject("My");
Expand All @@ -16,7 +17,7 @@ public async void ResourceGroupTest()
}

[Fact]
public async void VirtualNetworkTest()
public async Task VirtualNetworkTest()
{
var c = Credentials.Get();
var rg = new ResourceGroupObject("My1");
Expand All @@ -26,7 +27,16 @@ public async void VirtualNetworkTest()
}

[Fact]
public async void Test1()
public async Task PublicIpAddressTest()
{
var c = Credentials.Get();
var rg = new ResourceGroupObject("MyPIA");
var pia = new PublicIpAddressObject("MyPIA", rg);
var info = await pia.GetOrCreateAsync(c);
}

[Fact]
public async Task Test1()
{
var c = Credentials.Get();
var client = new ComputeManagementClient(c.Credentials)
Expand Down
9 changes: 8 additions & 1 deletion experiments/Azure.Experiments/Azure.Experiments/Context.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Rest;
using Microsoft.Azure.Management.Network;
using Microsoft.Rest;

namespace Azure.Experiments
{
Expand All @@ -13,5 +14,11 @@ public Context(ServiceClientCredentials credentials, string subscriptionId)
public ServiceClientCredentials Credentials { get; }

public string SubscriptionId { get; }

public NetworkManagementClient CreateNetwork()
=> new NetworkManagementClient(Credentials)
{
SubscriptionId = SubscriptionId
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using System;
using System.Threading.Tasks;

namespace Azure.Experiments
{
public sealed class PublicIpAddressObject :
ResourceObject<PublicIPAddress, IPublicIPAddressesOperations>
{
public PublicIpAddressObject(string name, ResourceGroupObject rg) : base(name, rg)
{
}

protected override Task<PublicIPAddress> CreateAsync(IPublicIPAddressesOperations c)
=> c.CreateOrUpdateAsync(
ResourceGroupName,
Name,
new PublicIPAddress { Location = "eastus" });

protected override IPublicIPAddressesOperations CreateClient(Context c)
=> c.CreateNetwork().PublicIPAddresses;

protected override Task DeleteAsync(IPublicIPAddressesOperations c)
{
throw new NotImplementedException();
}

protected override Task<PublicIPAddress> GetOrThrowAsync(IPublicIPAddressesOperations c)
=> c.GetAsync(ResourceGroupName, Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Azure.Experiments
{
public abstract class AzureResource<T, C> : AzureObject<T, C>
public abstract class ResourceObject<T, C> : AzureObject<T, C>
where T : class
{
protected string ResourceGroupName { get; }

protected AzureResource(
protected ResourceObject(
string name,
ResourceGroupObject rg,
IEnumerable<AzureObject> dependencies)
Expand All @@ -17,7 +17,7 @@ protected AzureResource(
ResourceGroupName = rg.Name;
}

protected AzureResource(
protected ResourceObject(
string name,
ResourceGroupObject rg)
: this(name, rg, Enumerable.Empty<AzureObject>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Azure.Experiments
{
public sealed class VirtualNetworkObject :
AzureResource<VirtualNetwork, IVirtualNetworksOperations>
ResourceObject<VirtualNetwork, IVirtualNetworksOperations>
{
public VirtualNetworkObject(
string name,
Expand All @@ -30,9 +30,7 @@ protected override Task<VirtualNetwork> CreateAsync(IVirtualNetworksOperations c
});

protected override IVirtualNetworksOperations CreateClient(Context c)
=> new NetworkManagementClient(c.Credentials)
{ SubscriptionId = c.SubscriptionId }
.VirtualNetworks;
=> c.CreateNetwork().VirtualNetworks;

protected override Task DeleteAsync(IVirtualNetworksOperations c)
=> c.DeleteAsync(ResourceGroupName, Name);
Expand Down

0 comments on commit 3237c8e

Please sign in to comment.