internal static ManagedInstanceEncryptionProtectorListResult DeserializeManagedInstanceEncryptionProtectorListResult(JsonElement element)
        {
            Optional <IReadOnlyList <ManagedInstanceEncryptionProtectorData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ManagedInstanceEncryptionProtectorData> array = new List <ManagedInstanceEncryptionProtectorData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ManagedInstanceEncryptionProtectorData.DeserializeManagedInstanceEncryptionProtectorData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new ManagedInstanceEncryptionProtectorListResult(Optional.ToList(value), nextLink.Value));
        }
        ManagedInstanceEncryptionProtector IOperationSource <ManagedInstanceEncryptionProtector> .CreateResult(Response response, CancellationToken cancellationToken)
        {
            using var document = JsonDocument.Parse(response.ContentStream);
            var data = ManagedInstanceEncryptionProtectorData.DeserializeManagedInstanceEncryptionProtectorData(document.RootElement);

            return(new ManagedInstanceEncryptionProtector(_armClient, data));
        }
        public async Task ManagedInstanceEncryptionProtectorApiTests()
        {
            // Create Managed Instance
            string managedInstanceName      = Recording.GenerateAssetName("managed-instance-");
            string networkSecurityGroupName = Recording.GenerateAssetName("network-security-group-");
            string routeTableName           = Recording.GenerateAssetName("route-table-");
            string vnetName        = Recording.GenerateAssetName("vnet-");
            var    managedInstance = await CreateDefaultManagedInstance(managedInstanceName, networkSecurityGroupName, routeTableName, vnetName, Location.WestUS2, _resourceGroup);

            Assert.IsNotNull(managedInstance.Data);

            string encryptionProtectorName = "current";
            var    collection = managedInstance.GetManagedInstanceEncryptionProtectors();

            // 1.CreateOrUpdata
            ManagedInstanceEncryptionProtectorData data = new ManagedInstanceEncryptionProtectorData()
            {
                ServerKeyName       = "ServiceManaged",
                ServerKeyType       = "ServiceManaged",
                AutoRotationEnabled = false,
            };
            var encryption = await collection.CreateOrUpdateAsync(encryptionProtectorName, data);

            Assert.IsNotNull(encryption.Value.Data);
            Assert.AreEqual(encryptionProtectorName, encryption.Value.Data.Name);
            Assert.AreEqual("ServiceManaged", encryption.Value.Data.ServerKeyName);
            Assert.AreEqual("ServiceManaged", encryption.Value.Data.ServerKeyType.ToString());
            Assert.AreEqual(false, encryption.Value.Data.AutoRotationEnabled);

            // 2.CheckIfExist
            Assert.IsTrue(collection.CheckIfExists(encryptionProtectorName));

            // 3.Get
            var getEncryption = await collection.GetAsync(encryptionProtectorName);

            Assert.IsNotNull(encryption.Value.Data);
            Assert.AreEqual(encryptionProtectorName, getEncryption.Value.Data.Name);
            Assert.AreEqual("ServiceManaged", getEncryption.Value.Data.ServerKeyName);
            Assert.AreEqual("ServiceManaged", getEncryption.Value.Data.ServerKeyType.ToString());
            Assert.AreEqual(false, getEncryption.Value.Data.AutoRotationEnabled);

            // 4.GetAll
            var list = await collection.GetAllAsync().ToEnumerableAsync();

            Assert.IsNotEmpty(list);
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(encryptionProtectorName, list.FirstOrDefault().Data.Name);
        }