Ejemplo n.º 1
0
        ManagedDatabase IOperationSource <ManagedDatabase> .CreateResult(Response response, CancellationToken cancellationToken)
        {
            using var document = JsonDocument.Parse(response.ContentStream);
            var data = ManagedDatabaseData.DeserializeManagedDatabaseData(document.RootElement);

            return(new ManagedDatabase(_armClient, data));
        }
        internal static ManagedDatabaseListResult DeserializeManagedDatabaseListResult(JsonElement element)
        {
            Optional <IReadOnlyList <ManagedDatabaseData> > 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 <ManagedDatabaseData> array = new List <ManagedDatabaseData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ManagedDatabaseData.DeserializeManagedDatabaseData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new ManagedDatabaseListResult(Optional.ToList(value), nextLink.Value));
        }
Ejemplo n.º 3
0
        public async Task CreateOrUpdate()
        {
            #region Snippet:Managing_Sql_CreateAManagedDatabases
            ManagedDatabaseCollection managedDatabaseCollection = managedInstance.GetManagedDatabases();

            ManagedDatabaseData data = new ManagedDatabaseData(AzureLocation.WestUS2)
            {
            };
            string databaseName       = "myDatabase";
            var    managedDatabaseLro = await managedDatabaseCollection.CreateOrUpdateAsync(true, databaseName, data);

            ManagedDatabase managedDatabase = managedDatabaseLro.Value;
            #endregion
        }
        public async Task ManagedDatabaseApiTests()
        {
            // 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, AzureLocation.WestUS2, _resourceGroup);

            string databaseName = Recording.GenerateAssetName("mi-database-");
            var    collection   = managedInstance.GetManagedDatabases();

            // 1.CreateOrUpdata
            ManagedDatabaseData data = new ManagedDatabaseData(AzureLocation.WestUS2)
            {
            };
            var database = await collection.CreateOrUpdateAsync(true, databaseName, data);

            Assert.IsNotNull(database.Value.Data);
            Assert.AreEqual(databaseName, database.Value.Data.Name);

            // 2.CheckIfExist
            Assert.IsTrue(await collection.ExistsAsync(databaseName));
            Assert.IsFalse(await collection.ExistsAsync(databaseName + "0"));

            // 3.Get
            var getDatabase = await collection.GetAsync(databaseName);

            Assert.IsNotNull(getDatabase.Value.Data);
            Assert.AreEqual(databaseName, getDatabase.Value.Data.Name);

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

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

            // 5.Delete
            var deleteDatabase = await collection.GetAsync(databaseName);

            await deleteDatabase.Value.DeleteAsync(true);

            list = await collection.GetAllAsync().ToEnumerableAsync();

            Assert.IsEmpty(list);
        }