A createUiDefinition.json tesztelési esetei

Ez a cikk a createUiDefinition.json fájlok sablontesztelési eszközkészletével futtatott teszteket ismerteti. A példák közé tartoznak azok a tesztnevek és kódminták, amelyek sikeresek vagy sikertelenek .

Az eszközkészlet tartalmazza az Azure Resource Manager-sablonok (ARM-sablonok) tesztelési eseteit, valamint az azuredeploy.json vagy maintemplate.json nevű fő sablonfájlokat. Ha a könyvtár tartalmaz egy createUiDefinition.json fájlt, a rendszer bizonyos teszteket futtat a felhasználói felület vezérlőihez. A tesztek futtatásával vagy egy adott teszt futtatásával kapcsolatos további információkért lásd: Tesztparaméterek.

A createUiDefinition.json fájl egyéni felhasználói felületi (UI) vezérlőket hoz létre elemek és függvények használatával.

Annak ellenőrzése, hogy a sablonparaméter engedélyezi-e az értékeket

Teszt neve: Az engedélyezett értékeknek ténylegesen engedélyezve kell lenniük

Ez a teszt ellenőrzi, hogy a createUiDefinition.json összes vezérlőjének értékei engedélyezve vannak-e a fő sablon paramétereiben. A paraméterek név szerint vannak leképezve a fő sablon és a createUiDefinition.json fájl között.

A fő sablon paraméterének el kell fogadnia a vezérlő értékeit allowedValues. A teszt azt is ellenőrzi, hogy a vezérlőre hivatkozik-e a createUiDefinition.jsonoutputs szakaszban.

Ez a teszt ellenőrzi a fő sablont és a createUiDefinition.json fájlt. A createUiDefinition.json fájlra egy példa látható a fő sablon példái után.

Az alábbi példa meghiúsul, mert a fő sablon paraméterneve combo nem egyezik a vezérlő paraméternevével comboBox.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "combo": {
      "type": "string",
      "defaultValue": "two"
    }
  },
  "resources": [],
  "outputs": {
    "comboBoxOutput": {
      "type": "string",
      "value": "[parameters('combo')]"
    }
  }
}

Az alábbi példa meghiúsul, mert a fő sablon paramétertípusa int nem fogadja el a vezérlő string értékét. És ha egy fő sablon paramétere meghatároz egy defaultValue értéket, annak érvényesnek value kell lennie a vezérlőben allowedValues.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "comboBox": {
      "type": "int",
      "defaultValue": 4
    }
  },
  "resources": [],
  "outputs": {
    "comboBoxOutput": {
      "type": "string",
      "value": "[parameters('combo')]"
    }
  }
}

Az alábbi példa azért halad át , mert a fő sablon paraméterneve megegyezik a vezérlő paraméternevével. A sablon paramétertípusa pedig egystring, a vezérlőben allowedValuesmegadott paraméterreldefaultValue.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "comboBox": {
      "type": "string",
      "defaultValue": "two"
    }
  },
  "resources": [],
  "outputs": {
    "comboBoxOutput": {
      "type": "string",
      "value": "[parameters('comboBox')]"
    }
  }
}

A példához tartozó createUiDefinition.json fájl:

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [],
    "steps": [
      {
        "name": "demoComboBox",
        "label": "demoComboBoxLabel",
        "elements": [
          {
            "name": "comboBox",
            "type": "Microsoft.Common.DropDown",
            "label": "Example drop down",
            "defaultValue": "Value two",
            "toolTip": "This is a tool tip",
            "constraints": {
              "allowedValues": [
                {
                  "label": "Value one",
                  "description": "The value to select for option 1.",
                  "value": "one"
                },
                {
                  "label": "Value two",
                  "description": "The value to select for option 2.",
                  "value": "two"
                }
              ],
              "required": true
            },
            "visible": true
          }
        ]
      }
    ],
    "outputs": {
      "comboBox": "[steps('demoComboBox').comboBox]"
    }
  }
}

A kimeneti vezérlőknek létezniük kell

Teszt neve: A kimenetekben lévő vezérlőknek létezniük kell

A szakaszban használt outputs vezérlőknek a createUiDefinition.json fájl más részén található elemben kell lenniük. A fájlban outputs hivatkozott névnek meg kell egyeznie a vagy steps[]a fájlban basics[] használt névvel.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "nameDoesNotMatchOutput",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]"
    }
  }
}

A tulajdonságoknak értékeket kell tartalmazniuk

Teszt neve: A CreateUIDefinition nem rendelkezhet üres elemekkel

A tulajdonságoknak értékeket kell tartalmazniuk. A kötelező tulajdonságoknak érvényes értékeket kell használniuk. Az üres nem kötelező tulajdonságokat el kell távolítani. A teszt üres , vagy "steps": []defaultValueértéket tesz lehetővé"basics": [].

A következő példa meghiúsul , mert labela , placeholderés toolTip üres.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "",
        "placeholder": "",
        "defaultValue": "",
        "toolTip": ""
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Az alábbi példa azért halad át , mert label és toolTip értékekkel rendelkezik, és placeholder el lett távolítva.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "defaultValue": "",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Érvényes séma és verzió használata

Teszt neve: A CreateUIDefinitionnek sémával kell rendelkeznie

A createUiDefinition.json fájlnak tartalmaznia kell egy tulajdonságot $schema , és érvényes $schema és version. A és a $schemaversion verziószámának egyeznie kell.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.9.9-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.9.9-preview"
}

Az alábbi példa azért megy át , mert a legújabb $schema és versiona verziót használja.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview"
}

Ne rejtse el a hitelesítő adatok megerősítését

Teszt neve: A hitelesítő adatok megerősítése nem rejthető el

Ez a teszt ellenőrzi, hogy a rendszer megerősíti-e a Microsoft.Common.PasswordBox vagy a Microsoft.Compute.CredentialsCombo hitelesítő adatait. A hideConfirmation tulajdonságot úgy kell beállítani, false hogy a megerősítés látható legyen.

Az alábbi példa meghiúsul, mert hideConfirmation a következő: true.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "credentials",
        "type": "Microsoft.Compute.CredentialsCombo",
        "label": {
          "password": "Password",
          "confirmPassword": "Confirm password"
        },
        "toolTip": {
          "password": "Type your credentials"
        },
        "constraints": {
          "required": true,
          "customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
          "customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
        },
        "options": {
          "hideConfirmation": true
        },
        "osPlatform": "Windows",
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "credentials": "[basics('credentials')]"
    }
  }
}

Az alábbi példa azért halad át, mert hideConfirmation : false.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "credentials",
        "type": "Microsoft.Compute.CredentialsCombo",
        "label": {
          "password": "Password",
          "confirmPassword": "Confirm password"
        },
        "toolTip": {
          "password": "Type your credentials"
        },
        "constraints": {
          "required": true,
          "customPasswordRegex": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{12,}$",
          "customValidationMessage": "The password must be alphanumeric, contain at least 12 characters, and have at least 1 letter and 1 number."
        },
        "options": {
          "hideConfirmation": false
        },
        "osPlatform": "Windows",
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "credentials": "[basics('credentials')]"
    }
  }
}

A megfelelő kezelő használata

Teszt neve: A kezelőnek helyesnek kell lennie

Használja Microsoft.Azure.CreateUIDef a vagy Microsoft.Compute.MultiVm a createUiDefinition.json fájlt.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.",
  "version": "0.1.2-preview"
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview"
}

Meglévő erőforrások elrejtése

Teszt neve: A HideExistinget helyesen kell kezelni

Ha hideExisting értékre false van állítva vagy nincs megadva, outputs akkor a és newOrExistinga értéket kell tartalmazniaresourceGroup. Az alapértelmezett értéke hideExisting a következő: false.

Ilyen vezérlőtípusok hideExisting például a Microsoft.Storage.StorageAccountSelector, a Microsoft.Network.PublicIpAddressCombo vagy a Microsoft.Network.VirtualNetworkCombo.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "storage",
        "type": "Microsoft.Storage.StorageAccountSelector",
        "label": "Storage account",
        "toolTip": "This is a demo storage account",
        "defaultValue": {
          "name": "storageaccount01",
          "type": "Premium_LRS"
        },
        "options": {
          "hideExisting": false
        },
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "storage",
        "type": "Microsoft.Storage.StorageAccountSelector",
        "label": "Storage account",
        "toolTip": "This is a demo storage account",
        "defaultValue": {
          "name": "storageaccount01",
          "type": "Premium_LRS"
        },
        "options": {
          "hideExisting": false
        },
        "visible": false
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "resourceGroup": "[basics('storage').resourceGroup]",
      "newOrExisting": "[basics('storage').newOrExisting]"
    }
  }
}

Hely használata a kimenetekben

Teszt neve: A helynek a kimenetekben kell lennie

A outputs szakasznak tartalmaznia kell egy helyet a location függvénnyel.

Az alábbi példa meghiúsul, mert outputs nem tartalmaz helyet.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]",
      "location": "[location()]"
    }
  }
}

Vezérlőkimenetek belefoglalása sablonparaméterekbe

Teszt neve: A kimeneteknek jelen kell lenniük a sablonparaméterekben

A teszt ellenőrzi, hogy a createUiDefinition.json tartalmaz-e egy szakaszt outputs . A teszt azt is ellenőrzi, hogy ezek outputs a fő sablon parameters szakaszában vannak-e definiálva. A neveknek egyeznie kell, mert a paraméterek név szerint vannak leképezve a createUiDefinition.json és a fő sablon között.

Ez a teszt ellenőrzi a fő sablont és a createUiDefinition.json fájlt. A createUiDefinition.json fájlra egy példa látható a fő sablon példái után.

Az alábbi példa meghiúsul, mert a fő sablon nem tartalmazza a comboBoxcreateUiDefinition.json fájl szakaszában található paramétert outputs .

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [],
  "outputs": {
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

Az alábbi példa azért halad át, mert a fő sablon tartalmazza a paramétert comboBox .

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "comboBox": {
      "type": "string",
      "defaultValue": "two"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [],
  "outputs": {
    "comboBox": {
      "type": "string",
      "value": "[parameters('comboBox')]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

A példához tartozó createUiDefinition.json fájl:

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]",
      "location": "[location()]"
    }
  }
}

Az alapértelmezett nélküli paramétereknek létezniük kell a kimenetekben

Teszt neve: Az alapértelmezett nélküli paramétereknek létezniük kell a CreateUIDefinition alkalmazásban

A fő sablon alapértelmezett érték nélküli paramétereinek létezniük kell a createUiDefinition.json fájl szakaszában outputs .

Ez a teszt ellenőrzi a fő sablont és a createUiDefinition.json fájlt. A vezérlő példái után egy példa látható az azuredeploy.json fájlra.

Az alábbi példa meghiúsul, mert a createUiDefinition.json fájl outputs nem tartalmazza a fő sablon paraméterét comboBox.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]"
    }
  }
}

Az alábbi példa azért megy át, mert a createUiDefinition.json a-t tartalmazza.comboBoxoutputs

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]",
      "location": "[location()]"
    }
  }
}

A példához tartozó azuredeploy.json fájl. A comboBox paraméternek nincs alapértelmezett értéke.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "comboBox": {
      "type": "string"
    },
    "location": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "comboBox": {
      "type": "string",
      "value": "[parameters('comboBox')]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

Biztonságos paraméter használata jelszómezővel

Teszt neve: Jelszó-szövegmezőket kell használni a jelszóparaméterekhez

Ez a teszt ellenőrzi, hogy a Microsoft.Common.PasswordBox elem definiálva van-e a fő sablonban parameters és a createUiDefinition.jsonoutputs fájlban. A jelszómezőhöz tartozó fő sablon paramétertípusának vagy secureObjectértéknek kell lenniesecureString.

Ez a teszt ellenőrzi a fő sablont és a createUiDefinition.json fájlt. A createUiDefinition.json fájlra egy példa látható a fő sablon példái után.

Az alábbi példa meghiúsul, mert a fő sablon paramétere passwordBox egy string.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "passwordBox": {
      "type": "string"
    },
    "location": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

Az alábbi példa azért halad át , mert a fő sablon paramétere passwordBox egy secureString.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "passwordBox": {
      "type": "secureString"
    },
    "location": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

A példához tartozó createUiDefinition.json fájl:

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "passwordBox",
        "type": "Microsoft.Common.PasswordBox",
        "label": {
          "password": "Password",
          "confirmPassword": "Confirm password"
        },
        "toolTip": "Type a password"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "passwordBox": "[basics('passwordBox')]"
    }
  }
}

A jelszómező minimális hosszt igényel

Teszt neve: A PasswordBoxesnek minimális hosszúságúnak kell lennie

A teszt ellenőrzi, hogy a Microsoft.Common.PasswordBox elem legalább 12 karaktert igénylő karaktert regex használ-econstraints.

Az alábbi példa meghiúsul, mert nincs constraints.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "passwordBox",
        "type": "Microsoft.Common.PasswordBox",
        "label": {
          "password": "Password",
          "confirmPassword": "Confirm password"
        },
        "toolTip": "Type a password"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "passwordBox": "[basics('passwordBox')]"
    }
  }
}

Az alábbi példa azért megy át, mert a regex karakternek legalább 12 karakterre van szüksége.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "passwordBox",
        "type": "Microsoft.Common.PasswordBox",
        "label": {
          "password": "Password",
          "confirmPassword": "Confirm password"
        },
        "toolTip": "Type a password",
        "constraints": {
          "required": true,
          "regex": "^[a-zA-Z0-9]{12,}$",
          "validationMessage": "Password must be at least 12 characters long, contain only numbers and letters"
        }
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "passwordBox": "[basics('passwordBox')]"
    }
  }
}

A szövegdoboznak érvényesítést kell használnia

Teszt neve: A szövegdobozok jól formázottak

Az ellenőrzés és a szövegmezők használatával ellenőrizzeconstraints, hogy a és messagea értéket tartalmazza-eregex.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "textBox",
        "type": "Microsoft.Common.TextBox",
        "label": "Text box",
        "toolTip": "Type 1-30 alphanumeric characters",
        "placeholder": "Type your text here",
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "textBox": "[basics('textBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "textBox",
        "type": "Microsoft.Common.TextBox",
        "label": "Text box",
        "toolTip": "Type 1-30 alphanumeric characters",
        "placeholder": "Type your text here",
        "constraints": {
          "required": true,
          "validations": [
            {
              "regex": "^[a-z0-9A-Z]{1,30}$",
              "message": "Only 1-30 characters alphanumeric characters are allowed."
            }
          ]
        },
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "textBox": "[basics('textBox')]"
    }
  }
}

Az elemleírásnak értékkel kell rendelkeznie

Teszt neve: Az elemleírásoknak jelen kell lenniük

Ez a teszt ellenőrzi, hogy a toolTip tulajdonság létezik-e, és tartalmaz-e értéket.

Az alábbi példa sikertelen.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": ""
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "comboBox": "[basics('comboBox')]"
    }
  }
}

Ne állítson be alapértelmezett felhasználónevet

Teszt neve: A felhasználóneveknek nem szabad alapértelmezettnek lennie

A teszt ellenőrzi, hogy defaultValue van-e készlet a Microsoft.Compute.UserNameTextBox elemhez.

Az alábbi példa meghiúsul, mert a defaultValue meg van adva.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "userNameBox",
        "type": "Microsoft.Compute.UserNameTextBox",
        "label": "User name",
        "defaultValue": "admin",
        "toolTip": "Enter your user name",
        "osPlatform": "Windows"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "userNameBox": "[basics('userNameBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "userNameBox",
        "type": "Microsoft.Compute.UserNameTextBox",
        "label": "User name",
        "toolTip": "Enter your user name",
        "osPlatform": "Windows"
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "userNameBox": "[basics('userNameBox')]"
    }
  }
}

Üzenet használata érvényesítéssel

Teszt neve: Az ellenőrzéseknek üzenetnek kell lenniük

Ez a teszt ellenőrzi, hogy a validationscreateUiDefinition.json fájl bármelyikében szerepel-e egy message.

Az alábbi példa meghiúsul, mert az regex érvényesítés nem rendelkezik message.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "textBox",
        "type": "Microsoft.Common.TextBox",
        "label": "Text box",
        "toolTip": "Type 1-30 alphanumeric characters",
        "placeholder": "Type your text here",
        "constraints": {
          "required": true,
          "validations": [
            {
              "regex": "^[a-z0-9A-Z]{1,30}$"
            }
          ]
        },
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "textBox": "[basics('textBox')]"
    }
  }
}

Az alábbi példa megfelel.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "textBox",
        "type": "Microsoft.Common.TextBox",
        "label": "Text box",
        "toolTip": "Type 1-30 alphanumeric characters",
        "placeholder": "Type your text here",
        "constraints": {
          "required": true,
          "validations": [
            {
              "regex": "^[a-z0-9A-Z]{1,30}$",
              "message": "Only 1-30 characters alphanumeric characters are allowed."
            }
          ]
        },
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "textBox": "[basics('textBox')]"
    }
  }
}

A virtuális gépek méretének egyeznie kell

Teszt neve: A virtuálisgép-méreteknek meg kell egyeznie a sablonnal

Ez a teszt ellenőrzi, hogy a Microsoft.Compute.SizeSelector szerepel-e a createUiDefinition.jsonoutputs fájlban és a fő sablon szakaszában parameters . A fő sablonparamétereknek meg defaultValue kell egyeznie a vezérlő értékével allowedSizes.

Ez a teszt ellenőrzi a fő sablont és a createUiDefinition.json fájlt. A createUiDefinition.json fájlra egy példa látható a fő sablon példái után.

Az alábbi példa meghiúsul, mert a fő sablon defaultValue nem egyezik meg a fájl egyik értékével allowedSizes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string"
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_D9"
    }
  },
  "resources": [],
  "outputs": {
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    },
    "vmSize": {
      "type": "string",
      "value": "[parameters('vmSize')]"
    }
  }
}

Az alábbi példa azért megy át, mert a fő sablon defaultValue értéke megegyezik egy értékkel a fájlban allowedSizes.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string"
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_D3"
    }
  },
  "resources": [],
  "outputs": {
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    },
    "vmSize": {
      "type": "string",
      "value": "[parameters('vmSize')]"
    }
  }
}

A példához tartozó createUiDefinition.json fájl:

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "vmSize",
        "type": "Microsoft.Compute.SizeSelector",
        "label": "VM Size",
        "toolTip": "Select a virtual machine size",
        "recommendedSizes": [
          "Standard_D1"
        ],
        "constraints": {
          "allowedSizes": [
            "Standard_D1",
            "Standard_D2",
            "Standard_D3"
          ]
        },
        "osPlatform": "Windows",
        "visible": true
      }
    ],
    "steps": [],
    "outputs": {
      "location": "[location()]",
      "vmSize": "[basics('vmSize')]"
    }
  }
}

Következő lépések