Skip to content

Commit

Permalink
it looks like it's broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Oct 24, 2017
1 parent 1a063df commit 7b3275b
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Azure.Experiments</AssemblyName>
<RootNamespace>Azure.Experiments</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.Rest.Azure;
using System;
using System.Collections.Generic;
using Microsoft.Rest.Azure;using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand All @@ -18,10 +16,13 @@ public abstract class AzureObject

public abstract Task CheckOrCreateAsync();

public int Priority { get; }

protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
{
Name = name;
Dependencies = dependencies;
Priority = dependencies.Any() ? dependencies.Max(d => d.Priority) + 1 : 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Azure.Experiments
{
public sealed class DependencyLocation
{
public string Location { get; }

public int Priority { get; }

public DependencyLocation(string location, int priority)
{
Location = location;
Priority = priority;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using System;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -21,7 +20,7 @@ public SubnetObject(
protected override async Task<Subnet> CreateAsync()
{
// The Virtual Network should be created at this point.
var vn = await Vn.GetOrNullAsync();
var vn = Vn.Info;
vn.Subnets.Add(new Subnet { Name = Name, AddressPrefix = AddressPrefix });
vn = await Vn.Client.CreateOrUpdateAsync(
Vn.ResourceGroupName, Vn.Name, vn);
Expand Down
4 changes: 4 additions & 0 deletions experiments/Azure.Experiments/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>

<IsPackable>false</IsPackable>

<AssemblyName>Tests</AssemblyName>

<RootNamespace>Azure.Experiments.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
79 changes: 79 additions & 0 deletions experiments/Azure.Experiments/Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.Rest;
using Xunit;

namespace Azure.Experiments.Tests
{
public class UnitTests
{
private static Context C { get; }
= new Context(new TokenCredentials("a"), string.Empty);

//[Fact]
public void ResourceGroupObjectTest()
{
var rg = new ResourceGroupObject(C, "My");
Assert.Equal(0, rg.Priority);
}

//[Fact]
public void VirtualNetworkObjectTest()
{
var rg = new ResourceGroupObject(C, "My1");
var vn = new VirtualNetworkObject(C.CreateNetwork(), "My1", rg, "192.168.0.0/16");
Assert.Equal(1, vn.Priority);
}

//[Fact]
public void PublicIpAddressObjectTest()
{
var rg = new ResourceGroupObject(C, "MyPIA");
var pia = new PublicIpAddressObject(C.CreateNetwork(), "MyPIA", rg);
Assert.Equal(1, pia.Priority);
}

//[Fact]
public void NetworkSecurityGroupTest()
{
var c = Credentials.Get();
var rg = new ResourceGroupObject(c, "MyNSG");
var nsg = new NetworkSecurityGroupObject(c.CreateNetwork(), "MyNSG", rg);
Assert.Equal(1, nsg.Priority);
}

//[Fact]
public void SubnetObjectTest()
{
var rg = new ResourceGroupObject(C, "MySubnet");
var vn = new VirtualNetworkObject(C.CreateNetwork(), "MySubnet", rg, "192.168.0.0/16");
var subnet = new SubnetObject("MySubnet", vn, "192.168.1.0/24");
Assert.Equal(2, subnet.Priority);
}

//[Fact]
public void NetworkInterfaceObjectTest()
{
var network = C.CreateNetwork();
var rg = new ResourceGroupObject(C, "MyNI");
var vn = new VirtualNetworkObject(network, "MyNI", rg, "192.168.0.0/16");
var subnet = new SubnetObject("MyNI", vn, "192.168.1.0/24");
var pia = new PublicIpAddressObject(network, "MyNI", rg);
var nsg = new NetworkSecurityGroupObject(network, "MyNI", rg);
var ni = new NetworkInterfaceObject(network, "MyNI", rg, subnet, pia, nsg);
Assert.Equal(3, ni.Priority);
}

//[Fact]
public void VmObjectTest()
{
var network = C.CreateNetwork();
var rg = new ResourceGroupObject(C, "MyVM");
var vn = new VirtualNetworkObject(network, "MyVM", rg, "192.168.0.0/16");
var subnet = new SubnetObject("MyVM", vn, "192.168.1.0/24");
var pia = new PublicIpAddressObject(network, "MyVM", rg);
var nsg = new NetworkSecurityGroupObject(network, "MyVM", rg);
var ni = new NetworkInterfaceObject(network, "MyVM", rg, subnet, pia, nsg);
var vm = new VmObject(C, "MyVM", rg, ni, "MyVMUser", "@3as54dDd");
Assert.Equal(4, vm.Priority);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $build = Resolve-Path "..\build\"
$out = Join-Path $build "AzureRM.Compute.Experiments\"
Copy-Item .\AzureRM.Compute.Experiments.psd1 $out
Copy-Item .\AzureRM.Compute.Experiments.psm1 $out
Copy-Item ..\Azure.Experiments\Azure.Experiments\bin\Debug\net452\*.dll $out

$env:PSModulePath = $env:PSModulePath + ";" + $build.ToString()

Expand All @@ -20,6 +21,7 @@ Describe 'New-AzVm' {
It 'WhatIf' {
$result = New-AzVm -Name MyVM -Credential $vmCredential -WhatIf
}
<#
It 'Create Windows VM' {
Remove-AzureRmResourceGroup -Name Something1 -Force
Expand Down Expand Up @@ -47,4 +49,5 @@ Describe 'New-AzVm' {
$result.Name | Should Be MyVMA3
}
#>
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PowerShellVersion = '5.0'
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''
DotNetFrameworkVersion = '4.5.2'

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''
Expand All @@ -58,7 +58,7 @@ RequiredModules = @(
)

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
RequiredAssemblies = @("Azure.Experiments.dll")

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function New-AzVm {
)

PROCESS {
$x = New-Object Azure.Experiments.Context($null, $null)
Write-Host "X: " + $x

# TODO: make sure it's logged in.
$context = if ($AzureRmContext) {
Get-AzureRmContext -AzureRmContext $AzureRmContext
Expand Down

0 comments on commit 7b3275b

Please sign in to comment.