Skip to content

Commit 381a986

Browse files
Unit tests.
1 parent ca51bc7 commit 381a986

19 files changed

+184
-48
lines changed

experiments/Azure.Experiments/Azure.Experiments/ResourceOperations.cs renamed to experiments/Azure.Experiments/Azure.Experiments/CreateOrUpdateAsyncOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Microsoft.Azure.Experiments
66
{
7-
public static class ResourceOperations
7+
public static class CreateOrUpdateAsyncOperation
88
{
9-
public static async Task<IState> CreateAsync<Config>(
9+
public static async Task<IState> CreateOrUpdateAsync<Config>(
1010
this IResourceConfig<Config> config,
1111
IClient client,
1212
IState current,

experiments/Azure.Experiments/Azure.Experiments/CurrentState.cs renamed to experiments/Azure.Experiments/Azure.Experiments/GetAsyncOperation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
namespace Microsoft.Azure.Experiments
88
{
9-
public static class CurrentState
9+
public static class GetAsyncOperation
1010
{
11-
public static async Task<IState> GetState<Config>(
11+
public static async Task<IState> GetAsync<Config>(
1212
this IResourceConfig<Config> resourceConfig,
1313
IClient client,
1414
CancellationToken cancellationToken)

experiments/Azure.Experiments/Azure.Experiments/Network/VirtualNetworkPolicy.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ public static class VirtualNetworkPolicy
1616
p.ResourceGroupName, p.Name, p.Config, p.CancellationToken));
1717

1818
public static ResourceConfig<VirtualNetwork> CreateVirtualNetworkConfig(
19-
this ResourceConfig<ResourceGroup> resourceGroup, string name)
20-
=> Policy.CreateConfig(resourceGroup, name);
19+
this ResourceConfig<ResourceGroup> resourceGroup,
20+
string name,
21+
string addressPrefix)
22+
=> Policy.CreateConfig(
23+
resourceGroup,
24+
name,
25+
_ => new VirtualNetwork
26+
{
27+
AddressSpace = new AddressSpace
28+
{
29+
AddressPrefixes = new[] { addressPrefix }
30+
}
31+
});
2132
}
2233
}

experiments/Azure.Experiments/Azure.Experiments/Old/Compute/VirtualMachineObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Azure.Experiments.Network;
2+
using Microsoft.Azure.Experiments;
23
using Microsoft.Azure.Management.Compute;
34
using Microsoft.Azure.Management.Compute.Models;
45
using System.Threading.Tasks;
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
using Microsoft.Azure.Management.Network;
2-
using Microsoft.Rest;
1+
using Microsoft.Azure.Experiments;
2+
using Microsoft.Azure.Management.Network;
33

44
namespace Azure.Experiments
55
{
6-
public class Context
6+
public static class ContextEx
77
{
8-
public Context(ServiceClientCredentials credentials, string subscriptionId)
9-
{
10-
Credentials = credentials;
11-
SubscriptionId = subscriptionId;
12-
}
13-
14-
public ServiceClientCredentials Credentials { get; }
15-
16-
public string SubscriptionId { get; }
17-
18-
public NetworkManagementClient CreateNetwork()
19-
=> new NetworkManagementClient(Credentials)
8+
public static NetworkManagementClient CreateNetwork(this Context context)
9+
=> new NetworkManagementClient(context.Credentials)
2010
{
21-
SubscriptionId = SubscriptionId
11+
SubscriptionId = context.SubscriptionId
2212
};
2313
}
2414
}

experiments/Azure.Experiments/Azure.Experiments/Old/ResourceGroupObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Azure.Management.ResourceManager.Models;
22
using Microsoft.Azure.Management.ResourceManager;
33
using System.Threading.Tasks;
4+
using Microsoft.Azure.Experiments;
45

56
namespace Azure.Experiments
67
{

experiments/Azure.Experiments/Azure.Experiments/CreateParameters.cs renamed to experiments/Azure.Experiments/Azure.Experiments/Parameters.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System.Collections.Concurrent;
1+
using System.Linq;
22

33
namespace Microsoft.Azure.Experiments
44
{
55
public static class Parameters
66
{
77
public static IState GetParameters<Config>(
8-
string subscription, string location, IResourceConfig<Config> config)
8+
this IResourceConfig<Config> config,
9+
string subscription,
10+
string location)
911
where Config : class
1012
{
1113
var visitor = new Visitor(subscription, location);
@@ -21,12 +23,19 @@ public Visitor(string subscription, string location)
2123
Location = location;
2224
}
2325

26+
public object GetUntyped(IResourceConfig config)
27+
=> Result.GetOrAddUntyped(config, () => config.Apply(this));
28+
2429
public Config Get<Config>(IResourceConfig<Config> config)
2530
where Config : class
26-
=> Result.GetOrAdd(config, () => config.Apply(this) as Config);
31+
=> GetUntyped(config) as Config;
2732

2833
public object Visit<Config>(ResourceConfig<Config> config) where Config : class
2934
{
35+
foreach (var d in config.Dependencies)
36+
{
37+
GetUntyped(d);
38+
}
3039
var p = config.CreateConfig(Subscription);
3140
config.Policy.SetLocation(p, Location);
3241
return p;

experiments/Azure.Experiments/Azure.Experiments/ResourcePolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public ResourcePolicy(
2424
Func<Config, string> getLocation,
2525
Action<Config, string> setLocation)
2626
{
27+
GetId = getId;
2728
GetAsync = getAsync;
2829
CreateOrUpdateAsync = createOrUpdateAsync;
2930
GetLocation = getLocation;

experiments/Azure.Experiments/Tests/AuthenticationResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Azure.Experiments.Tests
1+
namespace Microsoft.Azure.Experiments.Tests
22
{
33
internal sealed class AuthenticationResponse
44
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.Azure.Management.Network;
2+
using Microsoft.Azure.Management.ResourceManager;
3+
using System;
4+
5+
namespace Microsoft.Azure.Experiments.Tests
6+
{
7+
class Client : IClient
8+
{
9+
public Client(Context context)
10+
{
11+
Context = context;
12+
}
13+
14+
public Context Context { get; }
15+
16+
public T GetClient<T>()
17+
where T: class, IDisposable
18+
{
19+
if (typeof(T) == typeof(INetworkManagementClient))
20+
{
21+
return new NetworkManagementClient(Context.Credentials)
22+
{
23+
SubscriptionId = Context.SubscriptionId
24+
} as T;
25+
}
26+
else if (typeof(T) == typeof(IResourceManagementClient))
27+
{
28+
return new ResourceManagementClient(Context.Credentials)
29+
{
30+
SubscriptionId = Context.SubscriptionId
31+
} as T;
32+
}
33+
throw new Exception("unknown client type");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)