-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathProviderListBuilder.cs
119 lines (102 loc) · 4.66 KB
/
ProviderListBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
{
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.ResourceManager.Models;
public class ProviderListBuilder
{
private List<ProviderBuilder> Providers { get; } = new List<ProviderBuilder>();
public ProviderBuilder AddProvider(string name)
{
var rv = new ProviderBuilder(name);
this.Providers.Add(rv);
return rv;
}
public IList<Provider> List => new List<Provider>(this.Providers.Select(item => item.Provider));
public class ProviderBuilder
{
public string Namespace { get; }
private List<ResourceTypeBuilder> ResourceTypes { get; } = new List<ResourceTypeBuilder>();
public ProviderBuilder(string providerNamespace)
{
this.Namespace = providerNamespace;
}
public Provider Provider => new Provider(
namespaceProperty: this.Namespace,
resourceTypes: this.ResourceTypes.Select(item => item.ResourceType).ToList(),
registrationState: "Registered");
public ResourceTypeBuilder AddResourceType(string resourceType, IEnumerable<string> apiVersions = null, IEnumerable<string> locations = null)
{
var rv = new ResourceTypeBuilder(resourceType, apiVersions, locations);
this.ResourceTypes.Add(rv);
return rv;
}
}
public class ResourceTypeBuilder
{
public static IList<string> DefaultApiVersions { get; } = new List<string> { "2018-01-01", "2016-01-01" };
public static IList<string> DefaultLocations { get; } = new List<string> { "East US", "West US", "South US" };
private string Name { get; }
private List<string> ApiVersions { get; } = new List<string>();
private List<string> Locations { get; } = new List<string>();
private List<AliasBuilder> Aliases { get; } = new List<AliasBuilder>();
public ResourceTypeBuilder(string resourceType, IEnumerable<string> apiVersions = null, IEnumerable<string> locations = null)
{
this.Name = resourceType;
this.ApiVersions.AddRange(apiVersions ?? ResourceTypeBuilder.DefaultApiVersions);
this.Locations.AddRange(locations ?? ResourceTypeBuilder.DefaultLocations);
}
public ProviderResourceType ResourceType => new ProviderResourceType
{
ResourceType = this.Name,
ApiVersions = this.ApiVersions,
Locations = this.Locations,
Aliases = this.Aliases.Select(alias => alias.Alias).ToList()
};
public AliasBuilder AddAlias(string name)
{
var rv = new AliasBuilder(name);
this.Aliases.Add(rv);
return rv;
}
}
public class AliasBuilder
{
public static IList<string> DefaultApiVersions { get; } = new List<string> { "2018-01-01", "2016-01-01" };
private string Name { get; }
private List<AliasPathType> Paths { get; } = new List<AliasPathType>();
public AliasBuilder(string name)
{
this.Name = name;
}
public AliasType Alias => new AliasType
{
Name = this.Name,
Paths = this.Paths
};
public AliasPathType AddAliasPath(string path, IEnumerable<string> apiVersions = null)
{
var rv = new AliasPathType
{
Path = path,
ApiVersions = apiVersions?.ToList() ?? AliasBuilder.DefaultApiVersions
};
this.Paths.Add(rv);
return rv;
}
}
}
}