private bool RegisterTemplateSpec(DbAccess dbAccess, Type templateClass) { if (templateClass.GetInterface(typeof(ITemplateProperties).FullName) == null) { return(false); } else { ITemplateProperties templateProperties = Activator.CreateInstance(templateClass) as ITemplateProperties; if (templateProperties == null) { return(false); } else { TemplateSpec templateSpec = templateProperties.GetPropertiesSpec(); if (templateSpec == null) { return(false); } foreach (KeyValuePair <string, TemplateSpec.TemplatePropertySpec> p in templateSpec.Properties) { dbAccess.RegisterTemplatesSpec(templateClass.FullName, p.Key, p.Value.StringValue, p.Value.LinkState, p.Value.Description, p.Value.SortOrder); } return(true); } } }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("ForeignKeyBaseTable", "schema.ForeignKeyBaseTable", null, "{+}Foreign Key Base Table"); spec.AddProperty("AliasFormat", "{0}${1}", null, "[*]Only apply when column name is duplicate - {0}: Table; {1}: ColumnName"); return(spec); }
public override void ExecuteCmdlet() { try { ResourceIdentifier resourceIdentifier = (ResourceId != null) ? new ResourceIdentifier(ResourceId) : null; ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName; Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId); // Get the template spec version model from the SDK: TemplateSpecVersion specificVersion = TemplateSpecsSdkClient.TemplateSpecsClient.TemplateSpecVersions.Get( ResourceGroupName, Name, Version ); // Get the parent template spec from the SDK. We do this because we want to retrieve the // template spec name with its proper casing for naming our main template output file (the // Name parameter may have mismatched casing): TemplateSpec parentTemplateSpec = TemplateSpecsSdkClient.TemplateSpecsClient.TemplateSpecs.Get(ResourceGroupName, Name); PackagedTemplate packagedTemplate = new PackagedTemplate(specificVersion); // TODO: Handle overwriting prompts... // Ensure our output path is resolved based on the current powershell working // directory instead of the current process directory: OutputFolder = ResolveUserPath(OutputFolder); string mainTemplateFileName = $"{parentTemplateSpec.Name}.{specificVersion.Name}.json"; string uiFormDefinitionFileName = $"{parentTemplateSpec.Name}.{specificVersion.Name}.uiformdefinition.json"; string fullRootTemplateFilePath = Path.GetFullPath( Path.Combine(OutputFolder, mainTemplateFileName) ); if (ShouldProcess(specificVersion.Id, $"Export to '{fullRootTemplateFilePath}'")) { TemplateSpecPackagingEngine.Unpack( packagedTemplate, OutputFolder, mainTemplateFileName, uiFormDefinitionFileName); } WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", fullRootTemplateFilePath)); } catch (Exception ex) { WriteExceptionError(ex); } }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("NonPivotedColumns", "COL1, COL2, COL3", null, "{+}Non-pivoted columns"); spec.AddProperty("ValueColumn", "MEASURE_COL", null, "{+}Specify a name for each output column to represent the unpivoted measure values"); spec.AddProperty("PivotColumn", "TYPE_COL", null, "{+}Specify a name for each output column that will hold descriptor values (unpivot_for_clause)"); spec.AddProperty("UnpivotColumns", "*", null, "[*]Specify the input data columns whose names will become values in the output columns - the list of pivoted columns (not values) to be unpivoted"); return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); // <ToDo> Specify all properties to be used in the template: spec.AddProperty("ObjectView", "schema.ObjectView", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); // ... ... spec.AddProperty("CustomPropertyName", "ExampleValue", null, "{+}Customization is necessary property description ... (Max 1024 Chars)"); // ... ... spec.AddProperty("OptionPropertyName", "DefaultValue", null, "[*]Default can be acceptable property description ... (Max 1024 Chars)"); // </ToDo> return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("SourceFilter", "", null, "[*]Search conditions"); spec.AddProperty("JunctionColumns", "COL1, COL2, COL3", null, "{+}Join on columns"); spec.AddProperty("PivotColumn", "PIV_COL", null, "{+}Column that contains the values that will become column headers"); spec.AddProperty("MeasureColumn", "VALUE_COL", null, "{+}the value column of the PIVOT operator"); spec.AddProperty("ValueAliasList", "'Val 1' AS VAL_1, 'Val 2' AS VAL_2, 'Val 3' AS VAL_3", null, "{+}List the values that will become the column names of the output table, each value in the list will be transposed into a separate column"); return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("DateColumn", "DATE_", null, "{+}The date column of daily source table or view"); spec.AddProperty("SelectColumns", "*", null, "[*] * or a comma-separated list of select columns - exclude the date column"); spec.AddProperty("RangeStartDateColumn", "START_DATE", null, "{+}Time range Start Date column"); spec.AddProperty("RangeEndDateColumn", "END_DATE", null, "{+}Time range End Date column"); spec.AddProperty("EndDateNext", "0", null, "[*] 0: [START_DATE <= Time Range <= END_DATE]; 1: [START_DATE <= Time Range < END_DATE)"); return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("KeyColumns", "COL1, COL2", null, "{+}The key column or a comma-separated list of key columns - exclude the date column of time point"); spec.AddProperty("SourceDateColumn", "DATE_", null, "{+}Source date column of time point"); spec.AddProperty("AttribColumns", "*", null, "[*] * or a comma-separated list of attribute columns"); spec.AddProperty("DailyView", "T4SQL.VW_ORDINAL_DATE", null, "[*]Time Series base daily source table or view"); spec.AddProperty("DailyDateColumn", "DATE_", null, "[*]The date column of daily source table or view"); return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("SourceFilter", "", null, "[*]Search conditions"); spec.AddProperty("SimpleGroupByColumns", "", null, "[*]Simple group by items, e.g. COL1, COL2, COL3"); spec.AddProperty("GroupingSetsColumns", "(COL5, COL6, COL7) AS 'AGG_A', (COL4, COL5) AS 'AGG_B', () AS 'AGG_TOTAL'", null, "{+}Grouping Set List"); spec.AddProperty("GroupingNameColumn", "AGG_TYPE", null, "[*]Return a new column for identifying the level of grouping"); spec.AddProperty("AggregateExprs", "SUM(COL8) AS SUM_COL8, COUNT(DISTINCT COL9) AS CNT_COL9", null, "{+}Aggregate Function Expressions"); return(spec); }
/// <remarks> /// Method name is protected and has an 'Internal' suffix because the return type is /// the SDK model rather than the model wrapped for PS. See /// <see cref="CreateOrUpdateTemplateSpec(string, string, string, string, string)"/> /// for the method that returns the wrapped model. /// </remarks> protected TemplateSpec CreateOrUpdateTemplateSpecInternal( string resourceGroupName, string templateSpecName, string location, string templateSpecDisplayName = null, string templateSpecDescription = null, Hashtable tags = null, bool onlyApplyTagsOnCreate = false) { var existingTemplateSpec = this.GetAzureSdkTemplateSpec( resourceGroupName, templateSpecName, throwIfNotExists: false ); if (location == null) { if (existingTemplateSpec != null) { location = existingTemplateSpec.Location; } else { // TODO: Use the resource group location throw new PSInvalidOperationException("Location cannot be inferred and must be specified."); } } var templateSpecModel = new TemplateSpec { Location = location, Description = templateSpecDescription ?? existingTemplateSpec?.Description, DisplayName = templateSpecDisplayName ?? existingTemplateSpec?.DisplayName, Tags = existingTemplateSpec?.Tags }; if ((tags != null) && (existingTemplateSpec == null || !onlyApplyTagsOnCreate)) { templateSpecModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, true); } templateSpecModel = TemplateSpecsClient.TemplateSpecs.CreateOrUpdate( resourceGroupName, templateSpecName, templateSpecModel ); return(templateSpecModel); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.ObjectView", null, "{+}The full name of object view"); spec.AddProperty("SourceTable", "schema.SomeTable", null, "{+}Source Table"); spec.AddProperty("SourceFilter", "", null, "[*]Search conditions"); spec.AddProperty("KeyColumns", "Col1, Col2", null, "{+}Specifies a column or a list of columns which is supposed to be a unique key. A composite key (includes two or more columns) must be delimited by commas."); spec.AddProperty("OrderBy", "Col7 DESC, Col8", null, "{+}The ORDER_BY clause determines the sequence in which the rows are assigned their unique ROW_NUMBER within a specified partition."); spec.AddProperty("RowNumberAlias", "ROW$NUMBER", null, "{+}Specifies an alias name for returning the ROW_NUMBER"); spec.AddProperty("CountAlias", "CNT$DUP", null, "[*]Specifies an alias name for returning the COUNT(*) within each partition"); spec.AddProperty("RowidAlias", "ROW$ID", null, "[*]Specifies an alias name for returning the Oracle special pseudo column ROWID (Applies to Oracle only)"); return(spec); }
public async Task Get() { string rgName = Recording.GenerateAssetName("testRg-4-"); ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2); var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; TemplateSpec getTemplateSpec = await rg.GetTemplateSpecs().GetAsync(templateSpecName); AssertValidTemplateSpec(templateSpec, getTemplateSpec); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().GetAsync(null)); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("SourceFilter", "", null, "[*]Search conditions"); spec.AddProperty("NonPivotedColumns", "COL1, COL2, COL3", null, "{+}Non-pivoted columns"); spec.AddProperty("AggregateFunction", "MAX({0})", null, "[*]Aggregation function (pivot is an aggregate operation)"); spec.AddProperty("ValueColumn", "AGG_VAL_COL", null, "{+}Column being aggregated - the value column of the PIVOT operator"); spec.AddProperty("PivotColumn", "PIV_COL", null, "{+}Column that contains the values that will become column headers - the pivot column of the PIVOT operator (pivot_for_clause)"); spec.AddProperty("ValueList", "[Val 1] AS VAL_COL1, [Val 2], Val3", null, "{+}List the values in the PivotColumn that will become the column names of the output table, the aggregations for each value in the pivot_in_clause will be transposed into a separate column"); return(spec); }
public async Task Delete() { string rgName = Recording.GenerateAssetName("testRg-4-"); ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2); var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; await templateSpec.DeleteAsync(); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await templateSpec.GetAsync()); Assert.AreEqual(404, ex.Status); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SourceTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("KeyColumns", "COL1, COL2", null, "{+}The key column or a comma-separated list of key columns - exclude the date column of time point"); spec.AddProperty("AttribColumns", "*", null, "[*] * or a comma-separated list of attribute columns"); spec.AddProperty("DateColumn", "DATE_", null, "{+}Source date column of time point"); spec.AddProperty("RangeStartDateColumn", "START_DATE", null, "{+}Time range Start Date column"); spec.AddProperty("RangeEndDateColumn", "END_DATE", null, "{+}Time range End Date column"); spec.AddProperty("EndDateNext", "0", null, "[*] 0: [START_DATE <= Time Range <= END_DATE]; 1: [START_DATE <= Time Range < END_DATE)"); spec.AddProperty("DefaultEndDate", "2999-12-31", null, "[*]Ultimate END_DATE as the substitute of IS NULL"); return(spec); }
public TemplateSpec GetPropertiesSpec() { TemplateSpec spec = new TemplateSpec(); spec.AddProperty("ObjectView", "schema.VW_ObjViewName", null, "{+}The full name of object view"); spec.AddProperty("SourceView", "schema.SomeTableOrView", null, "{+}Source Table Or View"); spec.AddProperty("KeyColumns", "COL1, COL2", null, "{+}The key column or a comma-separated list of key columns - exclude date-range columns"); spec.AddProperty("RangeStartDateColumn", "START_DATE", null, "{+}Time range Start Date column"); spec.AddProperty("RangeEndDateColumn", "END_DATE", null, "{+}Time range End Date column"); spec.AddProperty("EndDateNext", "0", null, "[*] 0: [START_DATE <= Time Range <= END_DATE]; 1: [START_DATE <= Time Range < END_DATE)"); spec.AddProperty("DefaultEndDate", "", null, "[*]Ultimate END_DATE as the substitute of IS NULL"); spec.AddProperty("InscopeDaysColumn", "INSCOPE_DAYS", null, "[*]The total number of days between the first START_DATE and the last END_DATE"); spec.AddProperty("CheckSumColumn", "CHECK_SUM", null, "[*]SUM total days of every Time Ranges"); return(spec); }
internal PSTemplateSpec(TemplateSpec templateSpec, TemplateSpecVersion[] versionModels = null) { this.Id = templateSpec.Id; this.Type = templateSpec.Type; this.Name = templateSpec.Name; this.Location = templateSpec.Location; this.CreationTime = templateSpec.SystemData.CreatedAt; this.LastModifiedTime = templateSpec.SystemData.LastModifiedAt; this.Description = templateSpec.Description; this.DisplayName = templateSpec.DisplayName; this.Tags = templateSpec.Tags; this.Versions = versionModels? .Select(v => PSTemplateSpecVersion.FromAzureSDKTemplateSpecVersion(v)) .ToArray(); }
public async Task CreateOrUpdate() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-1-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-C-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, templateSpecName, templateSpecData)).Value; Assert.AreEqual(templateSpecName, templateSpec.Data.Name); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, null, templateSpecData)); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, templateSpecName, null)); }
/// <remarks> /// Method name is protected and has an 'Internal' suffix because the return type is /// the SDK model rather than the model wrapped for PS. See /// <see cref="CreateOrUpdateTemplateSpec(string, string, string, string, string)"/> /// for the method that returns the wrapped model. /// </remarks> protected TemplateSpec CreateOrUpdateTemplateSpecInternal( string resourceGroupName, string templateSpecName, string location, string templateSpecDisplayName = null, string templateSpecDescription = null) { var existingTemplateSpec = this.GetAzureSdkTemplateSpec( resourceGroupName, templateSpecName, throwIfNotExists: false ); if (location == null) { if (existingTemplateSpec != null) { location = existingTemplateSpec.Location; } else { // TODO: Use the resource group location throw new PSInvalidOperationException("Location cannot be inferred and must be specified."); } } var templateSpecModel = new TemplateSpec { Location = location, Description = templateSpecDescription ?? existingTemplateSpec?.Description, DisplayName = templateSpecDisplayName ?? existingTemplateSpec?.DisplayName, Tags = existingTemplateSpec?.Tags }; templateSpecModel = TemplateSpecsClient.TemplateSpecs.CreateOrUpdate( resourceGroupName, templateSpecName, templateSpecModel ); return(templateSpecModel); }
private static void AssertValidTemplateSpec(TemplateSpec model, TemplateSpec getResult) { Assert.AreEqual(model.Data.Name, getResult.Data.Name); Assert.AreEqual(model.Data.Id, getResult.Data.Id); Assert.AreEqual(model.Data.Type, getResult.Data.Type); Assert.AreEqual(model.Data.Location, getResult.Data.Location); Assert.AreEqual(model.Data.Tags, getResult.Data.Tags); Assert.AreEqual(model.Data.Description, getResult.Data.Description); Assert.AreEqual(model.Data.DisplayName, getResult.Data.DisplayName); Assert.AreEqual(model.Data.Metadata, getResult.Data.Metadata); Assert.AreEqual(model.Data.Versions.Count, getResult.Data.Versions.Count); foreach (var kv in model.Data.Versions) { var getTemplateSpecVersionInfo = getResult.Data.Versions[kv.Key]; Assert.NotNull(getTemplateSpecVersionInfo); Assert.AreEqual(model.Data.Versions[kv.Key].Description, getResult.Data.Versions[kv.Key].Description); Assert.AreEqual(model.Data.Versions[kv.Key].TimeCreated, getResult.Data.Versions[kv.Key].TimeCreated); Assert.AreEqual(model.Data.Versions[kv.Key].TimeModified, getResult.Data.Versions[kv.Key].TimeModified); } }
public async Task Get() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-3-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(WaitUntil.Completed, templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); TemplateSpecVersion templateSpecVersion = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, templateSpecVersionData)).Value; TemplateSpecVersion getTemplateSpecVersion = await templateSpec.GetTemplateSpecVersions().GetAsync(version); AssertValidTemplateSpecVersion(templateSpecVersion, getTemplateSpecVersion); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await templateSpec.GetTemplateSpecVersions().GetAsync(null)); }
public async Task Delete() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-1-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-C-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(WaitUntil.Completed, templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); TemplateSpecVersion templateSpecVersion = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, templateSpecVersionData)).Value; await templateSpecVersion.DeleteAsync(WaitUntil.Completed); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await templateSpecVersion.GetAsync()); Assert.AreEqual(404, ex.Status); }
public async Task ListBySubscription() { string rgName = Recording.GenerateAssetName("testRg-3-"); ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2); var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-L-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; int count = 0; await foreach (var tempTemplateSpec in Client.DefaultSubscription.GetTemplateSpecsAsync()) { if (tempTemplateSpec.Data.Id == templateSpec.Data.Id) { count++; } } Assert.AreEqual(count, 1); }
public async Task List() { string rgName = Recording.GenerateAssetName("testRg-2-"); ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2); var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-L-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); _ = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(version, templateSpecVersionData)).Value; int count = 0; await foreach (var tempTemplateSpecVersion in templateSpec.GetTemplateSpecVersions().GetAllAsync()) { count++; } Assert.AreEqual(count, 1); }
public void CanCrudTemplateSpec() { using (var context = MockContext.Start(this.GetType())) { var client = context.GetServiceClient <TemplateSpecsClient>(); var resourceGroupClient = context.GetServiceClient <ResourceManagementClient>(); // Create our test resource group: var resourceGroupName = $"{TestUtilities.GenerateName("TS-SDKTest-")}-RG"; var resourceGroup = resourceGroupClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup(TestLocation) ); try { var templateSpecName = $"{TestUtilities.GenerateName("TS-SDKTest-")}"; var templateSpecToCreate = new TemplateSpec { Description = "Description of my Template Spec", DisplayName = $"{templateSpecName} (Test)", Location = TestLocation }; var createdTemplateSpec = client.TemplateSpecs.CreateOrUpdate( resourceGroupName, templateSpecName, templateSpecToCreate ); // Validate user specified details: Assert.NotNull(createdTemplateSpec); Assert.Equal(TestLocation, createdTemplateSpec.Location); Assert.Equal(createdTemplateSpec.Name, templateSpecName); Assert.Equal(createdTemplateSpec.Description, templateSpecToCreate.Description); Assert.Equal(createdTemplateSpec.DisplayName, templateSpecToCreate.DisplayName); // Validate readonly properties are present: Assert.NotNull(createdTemplateSpec.Id); Assert.NotNull(createdTemplateSpec.Type); Assert.NotNull(createdTemplateSpec.SystemData?.CreatedAt); Assert.NotNull(createdTemplateSpec.SystemData?.CreatedBy); Assert.NotNull(createdTemplateSpec.SystemData?.CreatedByType); Assert.NotNull(createdTemplateSpec.SystemData?.LastModifiedAt); Assert.NotNull(createdTemplateSpec.SystemData?.LastModifiedBy); Assert.NotNull(createdTemplateSpec.SystemData?.LastModifiedByType); // Make sure our object returned from GET is equal to the one which was returned // from the creation: var templateSpecFromGet = client.TemplateSpecs.Get(resourceGroupName, templateSpecName); Assert.Equal( JsonConvert.SerializeObject(createdTemplateSpec), JsonConvert.SerializeObject(templateSpecFromGet) ); // Validate we can perform an update on the existing template spec: var templateSpecUpdate = JsonConvert.DeserializeObject <TemplateSpec>( JsonConvert.SerializeObject(templateSpecToCreate) ); templateSpecUpdate.Description = "This is an updated description"; var updatedTemplateSpec = client.TemplateSpecs.CreateOrUpdate( resourceGroupName, templateSpecName, templateSpecUpdate ); updatedTemplateSpec.Description.Equals(templateSpecUpdate.Description); // Validate we can get the template spec from a List at the resource group level: var listAtResourceGroupResult = client.TemplateSpecs.ListByResourceGroup(resourceGroupName); Assert.NotEmpty(listAtResourceGroupResult); var templateSpecFromList = listAtResourceGroupResult.FirstOrDefault( ts => ts.Name.Equals(templateSpecName) ); Assert.NotNull(templateSpecFromList); // Validate we can get the template spec from a List at the subscription level: var listAtSubscriptionResult = client.TemplateSpecs.ListBySubscription(); Assert.NotEmpty(listAtSubscriptionResult); templateSpecFromList = listAtResourceGroupResult.FirstOrDefault( ts => ts.Name.Equals(templateSpecName) ); Assert.NotNull(templateSpecFromList); // Now delete the template spec and make sure it is no longer retrievable: client.TemplateSpecs.Delete(resourceGroupName, templateSpecName); Assert.ThrowsAny <Exception>(() => client.TemplateSpecs.Get(resourceGroupName, templateSpecName)); } finally { resourceGroupClient.ResourceGroups.Delete(resourceGroupName); } } }
public void CanCrudSimpleTemplateSpecVersion() { using (var context = MockContext.Start(this.GetType())) { var client = context.GetServiceClient <TemplateSpecsClient>(); var resourceGroupClient = context.GetServiceClient <ResourceManagementClient>(); // Create our test resource group: var resourceGroupName = $"{TestUtilities.GenerateName("TS-SDKTest-")}-RG"; var resourceGroup = resourceGroupClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup(TestLocation) ); try { // Create the template spec: var templateSpecName = $"{TestUtilities.GenerateName("TS-SDKTest-")}"; var templateSpecToCreate = new TemplateSpec { Location = TestLocation }; var createdTemplateSpec = client.TemplateSpecs.CreateOrUpdate( resourceGroupName, templateSpecName, templateSpecToCreate ); Assert.NotNull(createdTemplateSpec); // Now create a simple template spec version: var templateSpecVersionToCreate = new TemplateSpecVersion { Description = "My first version", Location = TestLocation, Template = JObject.Parse( File.ReadAllText( Path.Combine("ScenarioTests", "simple-storage-account.json") ) ) }; const string versionName = "v1"; var createdTemplateSpecVersion = client.TemplateSpecVersions.CreateOrUpdate( resourceGroupName, templateSpecName, "v1", templateSpecVersionToCreate ); Assert.NotNull(createdTemplateSpecVersion); // Validate user specified details: Assert.Equal(TestLocation, createdTemplateSpecVersion.Location); Assert.Equal(createdTemplateSpecVersion.Name, versionName); Assert.Equal(createdTemplateSpecVersion.Description, templateSpecVersionToCreate.Description); Assert.Equal(createdTemplateSpecVersion.Template?.ToString(), templateSpecVersionToCreate.Template.ToString()); // Validate readonly properties are present: Assert.NotNull(createdTemplateSpecVersion.Id); Assert.NotNull(createdTemplateSpecVersion.Type); Assert.NotNull(createdTemplateSpecVersion.SystemData?.CreatedAt); Assert.NotNull(createdTemplateSpecVersion.SystemData?.CreatedBy); Assert.NotNull(createdTemplateSpecVersion.SystemData?.CreatedByType); Assert.NotNull(createdTemplateSpecVersion.SystemData?.LastModifiedAt); Assert.NotNull(createdTemplateSpecVersion.SystemData?.LastModifiedBy); Assert.NotNull(createdTemplateSpecVersion.SystemData?.LastModifiedByType); // Make sure our object returned from GET is equal to the one which was returned // from the creation: var templateSpecVersionFromGet = client.TemplateSpecVersions.Get(resourceGroupName, templateSpecName, versionName); Assert.Equal( JsonConvert.SerializeObject(createdTemplateSpecVersion), JsonConvert.SerializeObject(templateSpecVersionFromGet) ); // Validate we can perform an update on the existing version: var templateSpecVersionUpdate = JsonConvert.DeserializeObject <TemplateSpecVersion>( JsonConvert.SerializeObject(templateSpecVersionToCreate) ); templateSpecVersionUpdate.Description = "This is an updated description"; var updatedTemplateSpecVersion = client.TemplateSpecVersions.CreateOrUpdate( resourceGroupName, templateSpecName, versionName, templateSpecVersionUpdate ); updatedTemplateSpecVersion.Description.Equals(templateSpecVersionUpdate.Description); // Validate we can get the version when listing versions on the template spec: var listVersionsResult = client.TemplateSpecVersions.List(resourceGroupName, templateSpecName); Assert.Equal(1, listVersionsResult?.Count()); var versionFromList = listVersionsResult.FirstOrDefault( tsv => tsv.Name.Equals(versionName) ); Assert.NotNull(versionFromList); // Now delete the template spec and make sure the version is no longer retrievable: client.TemplateSpecs.Delete(resourceGroupName, templateSpecName); Assert.ThrowsAny <Exception>( () => client.TemplateSpecVersions.Get(resourceGroupName, templateSpecName, versionName) ); } finally { resourceGroupClient.ResourceGroups.Delete(resourceGroupName); } } }
/// <summary> /// Creates or updates a Template Spec. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='templateSpecName'> /// Name of the Template Spec. /// </param> /// <param name='templateSpec'> /// Template Spec supplied to the operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <TemplateSpec> CreateOrUpdateAsync(this ITemplateSpecsOperations operations, string resourceGroupName, string templateSpecName, TemplateSpec templateSpec, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, templateSpecName, templateSpec, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates or updates a Template Spec. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='templateSpecName'> /// Name of the Template Spec. /// </param> /// <param name='templateSpec'> /// Template Spec supplied to the operation. /// </param> public static TemplateSpec CreateOrUpdate(this ITemplateSpecsOperations operations, string resourceGroupName, string templateSpecName, TemplateSpec templateSpec) { return(operations.CreateOrUpdateAsync(resourceGroupName, templateSpecName, templateSpec).GetAwaiter().GetResult()); }
internal static PSTemplateSpec FromAzureSDKTemplateSpec(TemplateSpec templateSpec) { return(templateSpec != null ? new PSTemplateSpec(templateSpec) : null); }