Example #1
0
        public void OperationsTest()
        {
            string executingAssemblyPath = typeof(PowerBIDedicated.Tests.ScenarioTests.CapacityOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetDedicatedServicesClient(context);

                DedicatedCapacity testCapacity = PowerBIDedicatedTestUtilities.GetDefaultDedicatedResource();

                try
                {
                    // Create a test capacity
                    var resultOperationsList = client.Operations.List();

                    // validate the opertaions result
                    Assert.Equal(16, resultOperationsList.Count());

                    var opertationsPageLink      = "https://api-dogfood.resources.windows-int.net/providers/Microsoft.PowerBIDedicated/operations?api-version=2017-10-01";
                    var resultOperationsNextPage = client.Operations.ListNext(opertationsPageLink);

                    // validate the opertaions result
                    Assert.Equal(16, resultOperationsNextPage.Count());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
        public static DedicatedCapacity GetDefaultDedicatedResource()
        {
            DedicatedCapacity defaultCapacity = new DedicatedCapacity
            {
                Location       = DefaultLocation,
                Tags           = DefaultTags,
                Sku            = DefaultSku,
                Administration = new DedicatedCapacityAdministrators(DefaultAdministrators),
            };

            return(defaultCapacity);
        }
Example #3
0
 /// <inheritdoc/>
 public async Task <AzureOperationResponse <DedicatedCapacity> > CreateWithHttpMessagesAsync(string resourceGroupName, string dedicatedCapacityName, DedicatedCapacity capacityParameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await innerCapacityOperations
            .CreateWithHttpMessagesAsync(resourceGroupName, dedicatedCapacityName, capacityParameters, customHeaders, cancellationToken)
            .ConfigureAwait(false));
 }
 /// <summary>
 /// Provisions the specified Dedicated capacity based on the configuration
 /// specified in the request.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the Azure Resource group of which a given PowerBIDedicated
 /// capacity is part. This name must be at least 1 character in length, and no
 /// more than 90.
 /// </param>
 /// <param name='dedicatedCapacityName'>
 /// The name of the Dedicated capacity. It must be a minimum of 3 characters,
 /// and a maximum of 63.
 /// </param>
 /// <param name='capacityParameters'>
 /// Contains the information used to provision the Dedicated capacity.
 /// </param>
 public static DedicatedCapacity Create(this ICapacitiesOperations operations, string resourceGroupName, string dedicatedCapacityName, DedicatedCapacity capacityParameters)
 {
     return(operations.CreateAsync(resourceGroupName, dedicatedCapacityName, capacityParameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Provisions the specified Dedicated capacity based on the configuration
 /// specified in the request.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the Azure Resource group of which a given PowerBIDedicated
 /// capacity is part. This name must be at least 1 character in length, and no
 /// more than 90.
 /// </param>
 /// <param name='dedicatedCapacityName'>
 /// The name of the Dedicated capacity. It must be a minimum of 3 characters,
 /// and a maximum of 63.
 /// </param>
 /// <param name='capacityParameters'>
 /// Contains the information used to provision the Dedicated capacity.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DedicatedCapacity> BeginCreateAsync(this ICapacitiesOperations operations, string resourceGroupName, string dedicatedCapacityName, DedicatedCapacity capacityParameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, dedicatedCapacityName, capacityParameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Example #6
0
        public void CreateGetUpdateDeleteTest()
        {
            string executingAssemblyPath = typeof(PowerBIDedicated.Tests.ScenarioTests.CapacityOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetDedicatedServicesClient(context);

                DedicatedCapacity testCapacity = PowerBIDedicatedTestUtilities.GetDefaultDedicatedResource();
                DedicatedCapacity resultCreate = null;
                try
                {
                    // Create a test capacity
                    resultCreate =
                        client.Capacities.Create(
                            PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                            PowerBIDedicatedTestUtilities.DefaultCapacityName,
                            testCapacity);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the capacity and ensure that all the values are properly set.
                var resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // validate the capacity creation process
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultCapacityName, resultGet.Name);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.Administration.Members.Count);
                Assert.Equal("Microsoft.PowerBIDedicated/capacities", resultGet.Type);

                // Confirm that the capacity creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // Update the capacity and confirm the updates make it in.
                Dictionary <string, string> updatedTags = new Dictionary <string, string>
                {
                    { "updated1", "value1" }
                };

                var updatedAdministrators = PowerBIDedicatedTestUtilities.DefaultAdministrators;
                updatedAdministrators.Add("*****@*****.**");

                DedicatedCapacityUpdateParameters updateParameters = new DedicatedCapacityUpdateParameters()
                {
                    Sku            = resultGet.Sku,
                    Tags           = updatedTags,
                    Administration = new DedicatedCapacityAdministrators(updatedAdministrators),
                };

                DedicatedCapacity resultUpdate = null;
                try
                {
                    resultUpdate =
                        client.Capacities.Update(
                            PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                            PowerBIDedicatedTestUtilities.DefaultCapacityName,
                            updateParameters);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultUpdate.ProvisioningState);
                Assert.Equal("Succeeded", resultUpdate.State);

                // get the capacity and ensure that all the values are properly set.
                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // validate the capacity creation process
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultCapacityName, resultGet.Name);
                Assert.Equal(1, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("updated1"));
                Assert.Equal(3, resultGet.Administration.Members.Count);

                // Create another capacity and ensure that list account returns both
                var secondCapacity = PowerBIDedicatedTestUtilities.DefaultCapacityName + '2';
                resultCreate = client.Capacities.Create(
                    PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                    secondCapacity,
                    testCapacity);

                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                var listResponse = client.Capacities.List();

                // Assert that there are at least two capacities in the list
                Assert.True(listResponse.Count() >= 2);

                // now list by resource group:
                listResponse = client.Capacities.ListByResourceGroup(PowerBIDedicatedTestUtilities.DefaultResourceGroup);

                // Assert that there are at least two capacities in the list
                Assert.True(listResponse.Count() >= 2);

                // Suspend the capacity and confirm that it is deleted.
                client.Capacities.Suspend(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                // get the capacity and ensure that all the values are properly set.
                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                Assert.Equal("Paused", resultGet.ProvisioningState);
                Assert.Equal("Paused", resultGet.State);

                // Suspend the capacity and confirm that it is deleted.
                client.Capacities.Resume(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                // get the capacity and ensure that all the values are properly set.
                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                Assert.Equal("Succeeded", resultGet.ProvisioningState);
                Assert.Equal("Succeeded", resultGet.State);

                // Delete the servcapacityer and confirm that it is deleted.
                client.Capacities.Delete(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                // delete the capacity again and make sure it continues to result in a successful code.
                client.Capacities.Delete(PowerBIDedicatedTestUtilities.DefaultResourceGroup, secondCapacity);

                // delete the capacity with its old name, which should also succeed.
                client.Capacities.Delete(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // test that the capacity is gone
                // now list by resource group:
                listResponse = client.Capacities.ListByResourceGroup(PowerBIDedicatedTestUtilities.DefaultResourceGroup);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() >= 0);
            }
        }
Example #7
0
        public void ScaleUpTest()
        {
            string executingAssemblyPath = typeof(PowerBIDedicated.Tests.ScenarioTests.CapacityOperationsTests).GetTypeInfo().Assembly.Location;

            HttpMockServer.RecordsDirectory = Path.Combine(Path.GetDirectoryName(executingAssemblyPath), "SessionRecords");

            using (var context = MockContext.Start(this.GetType()))
            {
                var client = this.GetDedicatedServicesClient(context);

                DedicatedCapacity testCapacity = PowerBIDedicatedTestUtilities.GetDefaultDedicatedResource();

                SkuEnumerationForNewResourceResult skusListForNew = client.Capacities.ListSkus();
                testCapacity.Sku = skusListForNew.Value.Where(val => val.Name == "A1").First();
                if (testCapacity.Sku == null)
                {
                    skusListForNew.Value.First();
                }

                DedicatedCapacity resultCreate = null;
                try
                {
                    // Create a test capacity
                    resultCreate =
                        client.Capacities.Create(
                            PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                            PowerBIDedicatedTestUtilities.DefaultCapacityName,
                            testCapacity);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Assert.Equal("Succeeded", resultCreate.ProvisioningState);
                Assert.Equal("Succeeded", resultCreate.State);

                // get the capacity and ensure that all the values are properly set.
                var resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // validate the capacity creation process
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultCapacityName, resultGet.Name);
                Assert.Equal(testCapacity.Sku.Name, resultGet.Sku.Name);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.Administration.Members.Count);

                // Confirm that the capacity creation did succeed
                Assert.True(resultGet.ProvisioningState == "Succeeded");
                Assert.True(resultGet.State == "Succeeded");

                // Scale up the capacity and verify
                SkuEnumerationForExistingResourceResult skusListForExisting = client.Capacities.ListSkusForCapacity(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);
                ResourceSku newSku = skusListForExisting.Value.Where(detail => detail.Sku.Name != testCapacity.Sku.Name && detail.Sku.Name.StartsWith("A")).First().Sku;

                DedicatedCapacityUpdateParameters updateParameters = new DedicatedCapacityUpdateParameters()
                {
                    Sku = newSku
                };

                var resultUpdate = client.Capacities.Update(
                    PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                    PowerBIDedicatedTestUtilities.DefaultCapacityName,
                    updateParameters);

                Assert.Equal("Succeeded", resultUpdate.ProvisioningState);
                Assert.Equal("Succeeded", resultUpdate.State);

                // Suspend the capacity
                client.Capacities.Suspend(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // get the capacity and ensure that all the values are properly set.
                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                Assert.Equal("Paused", resultGet.ProvisioningState);
                Assert.Equal("Paused", resultGet.State);

                updateParameters = new DedicatedCapacityUpdateParameters()
                {
                    Sku = testCapacity.Sku
                };

                resultUpdate = client.Capacities.Update(
                    PowerBIDedicatedTestUtilities.DefaultResourceGroup,
                    PowerBIDedicatedTestUtilities.DefaultCapacityName,
                    updateParameters);

                Assert.Equal("Paused", resultUpdate.ProvisioningState);
                Assert.Equal("Paused", resultUpdate.State);

                // get the capacity and ensure that all the values are properly set.
                resultGet = client.Capacities.GetDetails(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);

                // validate the capacity creation process
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultLocation, resultGet.Location);
                Assert.Equal(PowerBIDedicatedTestUtilities.DefaultCapacityName, resultGet.Name);
                Assert.Equal(testCapacity.Sku.Name, resultGet.Sku.Name);
                Assert.Equal(2, resultGet.Tags.Count);
                Assert.True(resultGet.Tags.ContainsKey("key1"));
                Assert.Equal(2, resultGet.Administration.Members.Count);

                // delete the capacity with its old name, which should also succeed.
                client.Capacities.Delete(PowerBIDedicatedTestUtilities.DefaultResourceGroup, PowerBIDedicatedTestUtilities.DefaultCapacityName);
            }
        }
        public PSPowerBIEmbeddedCapacity CreateOrUpdateCapacity(
            string resourceGroupName,
            string capacityName,
            string location,
            string skuName         = null,
            Hashtable customTags   = null,
            string[] administrator = null,
            PSPowerBIEmbeddedCapacity existingCapacity = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByCapacity(capacityName);
            }

            var tags = (customTags != null)
                ? TagsConversionHelper.CreateTagDictionary(customTags, true)
                : null;

            var adminList = new List <string>();

            if (administrator != null && !string.IsNullOrEmpty(administrator[0]))
            {
                adminList.AddRange(administrator.ToList());
                if (adminList.Count == 0)
                {
                    adminList.Add(_currentUser);
                }
            }

            DedicatedCapacity newOrUpdatedCapacity = null;

            if (existingCapacity != null)
            {
                var updateParameters = new DedicatedCapacityUpdateParameters()
                {
                    Sku  = skuName == null ? null : GetResourceSkuFromName(skuName),
                    Tags = tags,
                };

                if (adminList.Count > 0)
                {
                    updateParameters.Administration = new DedicatedCapacityAdministrators(adminList);
                }

                newOrUpdatedCapacity = _client.Capacities.Update(resourceGroupName, capacityName, updateParameters);
            }
            else
            {
                newOrUpdatedCapacity = _client.Capacities.Create(
                    resourceGroupName,
                    capacityName,
                    new DedicatedCapacity()
                {
                    Administration = new DedicatedCapacityAdministrators(adminList),
                    Location       = location,
                    Sku            = GetResourceSkuFromName(skuName),
                    Tags           = tags
                });
            }

            return(new PSPowerBIEmbeddedCapacity(newOrUpdatedCapacity));
        }
 public PSPowerBIEmbeddedCapacity(DedicatedCapacity capacity)
 {
     _capacity = capacity;
 }