public NetworkTestClient()
        {
            undoContext = UndoContext.Current;
            undoContext.Start(4);

            networkClient = TestBase.GetServiceClient<NetworkManagementClient>();

            testOperations = new List<TestOperation>();
        }
        public void ListServiceTierAdvisors()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                Sql2ScenarioHelper.RunServerTestInEnvironment(
                    handler,
                    "12.0",
                    (sqlClient, resGroupName, server) =>
                {
                    var response = sqlClient.ServiceTierAdvisors.List(resGroupName, server.Name, "AdventureWorks2012");
                    TestUtilities.ValidateOperationResponse(response, HttpStatusCode.OK);
                    Assert.Equal(1, response.ServiceTierAdvisors.Count);
                    Assert.Equal("current", response.ServiceTierAdvisors[0].Name);
                    Assert.Equal("Web", response.ServiceTierAdvisors[0].Properties.CurrentServiceLevelObjective);
                    Assert.Equal("Basic", response.ServiceTierAdvisors[0].Properties.UsageBasedRecommendationServiceLevelObjective);
                    Assert.Equal(4, response.ServiceTierAdvisors[0].Properties.ServiceLevelObjectiveUsageMetrics.Count);
                    Assert.Equal("Basic", response.ServiceTierAdvisors[0].Properties.ServiceLevelObjectiveUsageMetrics[0].ServiceLevelObjective);
                });
            }
        }
示例#3
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            //HttpMockServer.Matcher = new PermissiveRecordMatcher();
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("Microsoft.Resources", null);
            d.Add("Microsoft.Features", null);
            d.Add("Microsoft.Authorization", null);
            var providersToIgnore = new Dictionary <string, string>();

            providersToIgnore.Add("Microsoft.Azure.Graph.RBAC.GraphRbacManagementClient", "1.42-previewInternal");
            providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
            // Enable undo functionality as well as mock recording
            using (UndoContext context = UndoContext.Current)
            {
                // Configure recordings
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                helper.SetupEnvironment();

                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.RMStorageDataPlaneModule,
                                    helper.GetRMModulePath(@"AzureRM.Insights.psd1"),
                                    helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
                                    "AzureRM.Storage.ps1",
                                    "AzureRM.Resources.ps1");
                helper.RunPowerShellTest(scripts);
            }
        }
示例#4
0
        public void FilteredListUsersTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = (new GraphTestBase()).GraphClient;

                var usersNoFilter = client.User.List(null, null);
                Assert.NotNull(usersNoFilter);
                Assert.NotNull(usersNoFilter.StatusCode == HttpStatusCode.OK);
                Assert.NotNull(usersNoFilter.Users);
                Assert.NotEqual(0, usersNoFilter.Users.Count());

                var usersByName = client.User.List(null, usersNoFilter.Users.ElementAt(1).DisplayName);
                Assert.NotNull(usersByName);
                Assert.NotNull(usersByName.StatusCode == HttpStatusCode.OK);
                Assert.NotNull(usersByName.Users);
                Assert.Equal(1, usersByName.Users.Count());

                Assert.Equal(
                    usersNoFilter.Users.ElementAt(1).ObjectId,
                    usersByName.Users.ElementAt(0).ObjectId);
            }
        }
示例#5
0
        public void ObjectsByObjectIdsTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = (new GraphTestBase()).GraphClient;

                var groups = client.Group.List(null, null);
                Assert.NotNull(groups);
                Assert.NotNull(groups.StatusCode == HttpStatusCode.OK);

                var users = client.User.List(null, null);
                Assert.NotNull(users);
                Assert.NotNull(users.StatusCode == HttpStatusCode.OK);

                var objectByObject = client.Objects.GetObjectsByObjectIds(
                    new GetObjectsParameters
                {
                    Ids = new List <string>
                    {
                        groups.Groups.ElementAt(0).ObjectId,
                        users.Users.ElementAt(1).ObjectId,
                        groups.Groups.ElementAt(2).ObjectId
                    },
                    Types = new List <string>
                    {
                        "StubDirectoryObject"
                    }
                });

                Assert.NotNull(objectByObject);
                Assert.NotNull(objectByObject.StatusCode == HttpStatusCode.OK);
                Assert.NotNull(objectByObject.AADObject);
                Assert.Equal(3, objectByObject.AADObject.Count());
            }
        }
示例#6
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                var modules = new List <string>
                {
                    "Resources\\DiagnosticsExtension\\DiagnosticsExtensionTests.ps1",
                    "Resources\\ServiceManagement\\Common.ps1",
                    "Common.ps1",
                    @"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Azure.psd1",
                    @"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\AzurePreview.psd1",
                    @"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\PIR.psd1"
                };

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(modules.ToArray());

                helper.RunPowerShellTest(scripts);
            }
        }
        public void ListGetJobsTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var      client      = GetServiceClient <BackupServicesManagementClient>();
                DateTime startTime   = new DateTime(2015, 6, 24, 15, 25, 9, DateTimeKind.Utc);
                DateTime endTime     = new DateTime(2015, 8, 13, 15, 25, 9, DateTimeKind.Utc);
                var      queryParams = new CSMJobQueryObject()
                {
                    StartTime = startTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    EndTime   = endTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    Operation = "Register"
                };

                var response = client.Job.ListAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, queryParams, GetCustomRequestHeaders()).Result.List.Value;

                Assert.NotNull(response);
                foreach (var job in response)
                {
                    ValidateJobResponse(job);
                }
            }
        }
示例#8
0
        public void ListZonesWithListNext()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone"), TestUtilities.GenerateName("hydratestdnszone") };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.List(resourceGroup.Name, new ZoneListParameters {
                    Top = "1"
                });

                Assert.NotNull(listresponse.NextLink);

                listresponse = dnsClient.Zones.ListNext(listresponse.NextLink);

                Assert.Equal(1, listresponse.Zones.Count);

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
示例#9
0
        public void EnumerateProtectedItemsUnderVault()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                List <ReplicationProtectedItem> itemsList = new List <ReplicationProtectedItem>();

                var protectedItemsResponse = client.ReplicationProtectedItem.ListAll(
                    null,
                    null,
                    RequestHeaders);
                itemsList.AddRange(protectedItemsResponse.ReplicationProtectedItems);
                while (protectedItemsResponse.NextLink != null)
                {
                    protectedItemsResponse = client.ReplicationProtectedItem.ListAllNext(
                        protectedItemsResponse.NextLink,
                        RequestHeaders);

                    itemsList.AddRange(protectedItemsResponse.ReplicationProtectedItems);
                }
            }
        }
示例#10
0
        public void CreateVMwareAzureV2Profile()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var    client     = GetSiteRecoveryClient(CustomHttpHandler);
                string policyName = "Hitesh-VMwareAzureV2-Profile";
                VMwareAzureV2PolicyInput input = new VMwareAzureV2PolicyInput
                {
                    AppConsistentFrequencyInMinutes   = 15,
                    CrashConsistentFrequencyInMinutes = 15,
                    MultiVmSyncStatus               = "Disable",
                    RecoveryPointHistory            = 15,
                    RecoveryPointThresholdInMinutes = 30
                };

                CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties()
                {
                    ProviderSpecificInput = input
                };

                CreatePolicyInput policyInput = new CreatePolicyInput()
                {
                    Properties = createInputProp
                };

                var response = client.Policies.Create(policyName, policyInput, RequestHeaders);
                Assert.NotNull(response);
                Assert.Equal(response.Status, OperationStatus.Succeeded);

                var policyResponse = response as CreatePolicyOperationResponse;
                Assert.NotNull(policyResponse);
                Assert.NotNull(policyResponse.Policy);
                Assert.Equal(policyResponse.Policy.Name, policyName);
            }
        }
示例#11
0
        public void RoleDefinitionsListWithFilterTests()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = testContext.GetAuthorizationManagementClient();

                Assert.NotNull(client);
                Assert.NotNull(client.HttpClient);

                var ownerRoleDefinition = client.RoleDefinitions.ListWithFilters(
                    new ListDefinitionFilterParameters
                {
                    RoleName = "Owner"
                });

                Assert.NotNull(ownerRoleDefinition);
                Assert.NotNull(ownerRoleDefinition.RoleDefinitions);
                Assert.Equal(1, ownerRoleDefinition.RoleDefinitions.Count);

                // Passsing name as null
                var allRoleDefinition = client.RoleDefinitions.ListWithFilters(
                    new ListDefinitionFilterParameters
                {
                    RoleName = null
                });

                var allRoleDefinitionsByList = client.RoleDefinitions.List();

                Assert.NotNull(allRoleDefinition);
                Assert.NotNull(allRoleDefinition.RoleDefinitions);
                Assert.Equal(allRoleDefinitionsByList.RoleDefinitions.Count, allRoleDefinition.RoleDefinitions.Count);

                Assert.Throws <ArgumentNullException>(() => client.RoleDefinitions.ListWithFilters(null));
            }
        }
        protected Collection <T> RunPowerShellTest <T>(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));
                List <string>          modules         = null;
                Collection <PSObject>  pipeLineObjects = null;
                Collection <T>         result          = new Collection <T>();
                EnvironmentSetupHelper helper          = new EnvironmentSetupHelper();

                modules = Directory.GetFiles(@"..\..\Scripts".AsAbsoluteLocation(), "*.ps1").ToList();
                helper.SetupSomeOfManagementClients();
                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());

                pipeLineObjects = helper.RunPowerShellTest(scripts);
                foreach (PSObject obj in pipeLineObjects)
                {
                    T item = LanguagePrimitives.ConvertTo <T>(obj);
                    result.Add(item);
                }
                return(result);
            }
        }
示例#13
0
        public void TestListUsages()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                EnsureClientsInitialized();

                string imgRefId = GetPlatformOSImage(useWindowsImage: true);
                // Create resource group
                var            rgName             = TestUtilities.GenerateName(TestPrefix);
                string         storageAccountName = TestUtilities.GenerateName(TestPrefix);
                string         asName             = TestUtilities.GenerateName("as");
                VirtualMachine inputVM;

                try
                {
                    // Create Storage Account, so that both the VMs can share it
                    var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                    var vm1 = CreateVM(rgName, asName, storageAccountOutput, imgRefId, out inputVM);

                    // List Usages, and do weak validation to assure that some usages were returned.
                    var luResponse = m_CrpClient.Usage.List(vm1.Location);

                    ValidateListUsageResponse(luResponse);

                    var lroResponse = m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name);
                    Assert.True(lroResponse.Status != ComputeOperationStatus.Failed);
                }
                finally
                {
                    var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.Delete(rgName);
                    Assert.True(deleteResourceGroupResponse.StatusCode == HttpStatusCode.OK);
                }
            }
        }
        public void ListZones()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                DnsManagementClient dnsClient = ResourceGroupHelper.GetDnsClient();

                var zoneNames = new[] { TestUtilities.GenerateName("hydratestdnszone.com"), TestUtilities.GenerateName("hydratestdnszone.com") };
                ResourceGroupExtended resourceGroup = ResourceGroupHelper.CreateResourceGroup();
                ZoneScenarioTests.CreateZones(dnsClient, resourceGroup, zoneNames);

                ZoneListResponse listresponse = dnsClient.Zones.ListZonesInResourceGroup(resourceGroup.Name, new ZoneListParameters());

                Assert.NotNull(listresponse);
                Assert.Equal(2, listresponse.Zones.Count);
                Assert.True(
                    listresponse.Zones.Any(zoneReturned => string.Equals(zoneNames[0], zoneReturned.Name)) &&
                    listresponse.Zones.Any(zoneReturned => string.Equals(zoneNames[1], zoneReturned.Name)) &&
                    listresponse.Zones.All(zoneReturned => string.Equals(resourceGroup.Name, zoneReturned.Properties.ParentResourceGroupName)),
                    "The response of the List request does not meet expectations.");

                ZoneScenarioTests.DeleteZones(dnsClient, resourceGroup, zoneNames);
            }
        }
示例#15
0
        public void CreateListAndDeleteSubscriptionTag()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string tagName = TestUtilities.GenerateName("csmtg");

                var client       = GetResourceManagementClient(handler);
                var createResult = client.Tags.CreateOrUpdate(tagName);

                Assert.Equal(tagName, createResult.Tag.Name);

                var listResult = client.Tags.List();
                Assert.True(listResult.Tags.Count > 0);

                client.Tags.Delete(tagName);
            }
        }
示例#16
0
        public void ListResourceGroupsWithTagNameAndValueFilter()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                string groupName = TestUtilities.GenerateName("csmrg");
                string tagName   = TestUtilities.GenerateName("csmtn");
                string tagValue  = TestUtilities.GenerateName("csmtv");
                var    client    = GetResourceManagementClient(handler);

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup
                {
                    Location = DefaultLocation,
                    Tags     = new Dictionary <string, string> {
                        { tagName, tagValue }
                    }
                });

                var listResult = client.ResourceGroups.List(new ResourceGroupListParameters
                {
                    TagName  = tagName,
                    TagValue = tagValue
                });

                foreach (var group in listResult.ResourceGroups)
                {
                    Assert.True(group.Tags.Keys.Contains(tagName));
                    Assert.Equal(tagValue, group.Tags[tagName]);
                }
            }
        }
示例#17
0
        public void ValidateBadDeployment()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.Created
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetResourceManagementClient(handler);

                string groupName      = TestUtilities.GenerateName("csmrg");
                string deploymentName = TestUtilities.GenerateName("csmd");
                var    parameters     = new Deployment
                {
                    Properties = new DeploymentProperties()
                    {
                        TemplateLink = new TemplateLink
                        {
                            Uri = new Uri(BadTemplateUri),
                        },
                        Parameters =
                            @"{ 'siteName': {'value': 'mctest0101'},'hostingPlanName': {'value': 'mctest0101'},'siteMode': {'value': 'Limited'},'computeMode': {'value': 'Shared'},'siteLocation': {'value': 'North Europe'},'sku': {'value': 'Free'},'workerSize': {'value': '0'}}",
                        Mode = DeploymentMode.Incremental,
                    }
                };

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = "West Europe"
                });
                var result = client.Deployments.Validate(groupName, deploymentName, parameters);
                Assert.False(result.IsValid);
                Assert.Equal("InvalidTemplate", result.Error.Code);
            }
        }
        protected void RunPowerShellTest(params string[] scripts)
        {
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("Microsoft.Authorization", null);
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);

            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.GetRMModulePath(@"AzureRM.OperationalInsights.psd1"));

                helper.RunPowerShellTest(scripts);
            }
        }
示例#19
0
        public ProfileScenarioTests()
        {
            // Cleanup
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                try
                {
                    ProfileListResponse listResponse = trafficManagerClient.Profiles.ListAll();

                    foreach (Profile profile in listResponse.Profiles)
                    {
                        string resourceGroup = TrafficManagerHelper.ExtractResourceGroupFromId(profile.Id);
                        trafficManagerClient.Profiles.Delete(resourceGroup, profile.Name);
                    }
                }
                catch (Exception)
                {
                    // TODO: (alguerra) Remove after we fix bug on list operation
                }
            }
        }
        public void ListDatabasesExpanded()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                Sql2ScenarioHelper.RunServerTestInEnvironment(
                    handler,
                    "12.0",
                    (sqlClient, resGroupName, server) =>
                {
                    var response = sqlClient.Databases.ListExpanded(resGroupName, server.Name, "upgradeHint,serviceTierAdvisors");
                    TestUtilities.ValidateOperationResponse(response, HttpStatusCode.OK);
                    Assert.Equal(12, response.Databases.Count);
                    Assert.Equal("AutoScaleSterlingTest4", response.Databases[0].Name);
                    Assert.Equal("S2", response.Databases[0].Properties.UpgradeHint.TargetServiceLevelObjective);
                    Assert.Equal(1, response.Databases[0].Properties.ServiceTierAdvisors.Count);
                    Assert.Equal("S3", response.Databases[0].Properties.ServiceTierAdvisors[0].Properties.UsageBasedRecommendationServiceLevelObjective);
                    Assert.Equal(4, response.Databases[0].Properties.ServiceTierAdvisors[0].Properties.ServiceLevelObjectiveUsageMetrics.Count);
                });
            }
        }
示例#21
0
        public void RemoveServer()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                FabricListResponse responseServers = client.Fabrics.List(RequestHeaders);

                FabricResponse response = client.Fabrics.Get(responseServers.Fabrics[0].Name, RequestHeaders);

                foreach (Fabric fabric in responseServers.Fabrics)
                {
                    var dras = client.RecoveryServicesProvider.List(fabric.Name, RequestHeaders).RecoveryServicesProviders;

                    var removeServerResponse = client.RecoveryServicesProvider.Delete(fabric.Name, dras[0].Name, RequestHeaders);
                }

                Assert.NotNull(response.Fabric);
                Assert.NotNull(response.Fabric.Name);
                Assert.NotNull(response.Fabric.Id);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
        public void ListRestorePointsTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName   = TestUtilities.GenerateName("csm-sql-backup");
                string resGroupName = TestUtilities.GenerateName("csm-rg-backup");

                string serverLocation = "Japan East";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Constants for Azure SQL Data Warehouse database creation.
                var    defaultDatabaseSize = 250L * 1024L * 1024L * 1024L;                  // 250 GB
                Guid   dwSlo           = new Guid("4E63CB0E-91B9-46FD-B05C-51FDD2367618 "); // DW100
                var    databaseName    = TestUtilities.GenerateName("csm-sql-backup-dwdb");
                string databaseEdition = "DataWarehouse";

                // Constants for Azure SQL standard database creation.
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                var    standardDatabaseName        = TestUtilities.GenerateName("csm-sql-backup-db");
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Create database test.

                    // Create data warehouse database
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = defaultDatabaseSize,
                            Edition      = databaseEdition,
                            RequestedServiceObjectiveId = dwSlo,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    // Create standard database
                    createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            MaxSizeBytes = standardDefaultDatabaseSize,
                            Edition      = standardDatabaseEdition,
                            RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                    //////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get restore points for data warehouse database.

                    RestorePointListResponse restorePointsListResponse = sqlClient.DatabaseBackup.ListRestorePoints(resGroupName, serverName, databaseName);

                    // Creating a data warehouse database should not have any discrete restore points right after.
                    TestUtilities.ValidateOperationResponse(restorePointsListResponse, HttpStatusCode.OK);
                    ValidateRestorePointListResponse(restorePointsListResponse, true, 0);
                    ///////////////////////////////////////////////////////////////////////

                    //////////////////////////////////////////////////////////////////////
                    // Get restore points for standard database.

                    restorePointsListResponse = sqlClient.DatabaseBackup.ListRestorePoints(resGroupName, serverName, standardDatabaseName);

                    TestUtilities.ValidateOperationResponse(restorePointsListResponse, HttpStatusCode.OK);
                    ValidateRestorePointListResponse(restorePointsListResponse, false, 1);
                    ///////////////////////////////////////////////////////////////////////
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
        public void ListGeoBackupsTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Use a preconfigured runner server/db in order to test this
                // Create a resource group/server/db with the following details prior to running this test
                // If first run on a live cluster, wait several hours for the geo pair to be created

                string serverName           = "csm-sql-backup-geo31415seasia";
                string resGroupName         = "csm-rg-backup-geo31415seasia";
                string serverLocation       = "Southeast Asia";
                string standardDatabaseName = "csm-sql-backup-geo-db31415";
                string adminLogin           = "******";
                string adminPass            = "******";
                string version = "12.0";
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                });

                var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        MaxSizeBytes = standardDefaultDatabaseSize,
                        Edition      = standardDatabaseEdition,
                        RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                    },
                });

                GeoBackupListResponse geoBackups = sqlClient.DatabaseBackup.ListGeoBackups(resGroupName, serverName);

                Assert.True(geoBackups.GeoBackups.Count >= 1);

                var geoRestoreDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName + "_georestored", new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        SourceDatabaseId = geoBackups.GeoBackups[0].Id,
                        CreateMode       = "Recovery"
                    }
                });

                TestUtilities.ValidateOperationResponse(geoRestoreDbResponse, HttpStatusCode.Created);
            }
        }
        public void ListDeletedDatabaseBackupTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server creation.
                string serverName   = "csm-sql-backup31415";
                string resGroupName = "csm-rg-backup31415";

                string serverLocation = "North Europe";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Constants for Azure SQL standard database creation.
                var    standardDefaultDatabaseSize = 1L * 1024L * 1024L * 1024L; // 1 GB
                var    standardDatabaseName        = "csm-sql-backup-db31415";
                string standardDatabaseEdition     = "Standard";

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                //////////////////////////////////////////////////////////////////////
                // Create server for test.
                var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new ServerCreateOrUpdateProperties()
                    {
                        AdministratorLogin         = adminLogin,
                        AdministratorLoginPassword = adminPass,
                        Version = version,
                    }
                });

                // Verify the the response from the service contains the right information
                TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                //////////////////////////////////////////////////////////////////////

                // Create standard database
                var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName, new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        MaxSizeBytes = standardDefaultDatabaseSize,
                        Edition      = standardDatabaseEdition,
                        RequestedServiceObjectiveId = SqlConstants.DbSloS0,
                    },
                });

                TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                //////////////////////////////////////////////////////////////////////

                // If first run on a live cluster, wait 10 minutes for backup to be taken (set a breakpoint to stop execution here)
                var deleteDbResponse = sqlClient.Databases.Delete(resGroupName, serverName, standardDatabaseName);

                TestUtilities.ValidateOperationResponse(deleteDbResponse, HttpStatusCode.OK);

                DeletedDatabaseBackupListResponse deletedDatabaseBackups = sqlClient.DatabaseBackup.ListDeletedDatabaseBackups(resGroupName, serverName);

                Assert.True(deletedDatabaseBackups.DeletedDatabaseBackups.Count > 0);

                var restoreDroppedDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, standardDatabaseName + "_restored", new DatabaseCreateOrUpdateParameters()
                {
                    Location   = serverLocation,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        SourceDatabaseId   = deletedDatabaseBackups.DeletedDatabaseBackups[0].Id,
                        RestorePointInTime = deletedDatabaseBackups.DeletedDatabaseBackups[0].Properties.DeletionDate,
                        CreateMode         = "Restore"
                    }
                });

                TestUtilities.ValidateOperationResponse(restoreDroppedDbResponse, HttpStatusCode.Created);
            }
        }
示例#25
0
        public void CrudEndpointsFullCycle()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                TrafficManagerManagementClient trafficManagerClient = TrafficManagerHelper.GetTrafficManagerClient();

                string profileName  = TestUtilities.GenerateName("hydratestwatmv2profile");
                string endpointName = TestUtilities.GenerateName("hydratestwatmv2endpoint");

                ResourceGroupExtended resourceGroup = TrafficManagerHelper.CreateResourceGroup();

                Profile profile = TrafficManagerHelper.GenerateDefaultProfile(profileName);
                profile.Properties.Endpoints = null;

                // Create profile without endpoints
                trafficManagerClient.Profiles.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    new ProfileCreateOrUpdateParameters
                {
                    Profile = profile
                });

                // Create the endpoint
                EndpointCreateOrUpdateResponse createEndpoint = trafficManagerClient.Endpoints.CreateOrUpdate(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName,
                    new EndpointCreateOrUpdateParameters
                {
                    Endpoint = TrafficManagerHelper.GenerateDefaultEndpoint(endpointName)
                });

                Assert.Equal(HttpStatusCode.Created, createEndpoint.StatusCode);

                EndpointGetResponse getEndpoint = trafficManagerClient.Endpoints.Get(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName);

                Assert.Equal(HttpStatusCode.OK, getEndpoint.StatusCode);

                Endpoint endpointToUpdate = getEndpoint.Endpoint;

                string oldTarget = endpointToUpdate.Properties.Target;
                string newTarget = "another." + oldTarget;
                endpointToUpdate.Properties.Target = newTarget;

                // Create the endpoint
                EndpointUpdateResponse updateEndpoint = trafficManagerClient.Endpoints.Update(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName,
                    new EndpointUpdateParameters
                {
                    Endpoint = endpointToUpdate
                });

                Assert.Equal(HttpStatusCode.Created, updateEndpoint.StatusCode);
                Assert.Equal(newTarget, updateEndpoint.Endpoint.Properties.Target);

                AzureOperationResponse deleteResponse = trafficManagerClient.Endpoints.Delete(
                    resourceGroup.Name,
                    profileName,
                    "ExternalEndpoints",
                    endpointName);

                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
            }
        }
        public void JobAccountCRUDTest()
        {
            var handler = new BasicDelegatingHandler();

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                // Management Clients
                var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
                var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

                // Variables for server create
                string serverName     = TestUtilities.GenerateName("csm-sql-jobaccountcrud-server");
                string resGroupName   = TestUtilities.GenerateName("csm-rg-jobaccountcrud");
                string serverLocation = "Southeast Asia";
                string adminLogin     = "******";
                string adminPass      = "******";
                string version        = "12.0";

                // Variables for database create
                string databaseName      = TestUtilities.GenerateName("csm-sql-jobaccountcrud-db");
                string databaseCollation = "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS";
                string databaseEdition   = "Standard";
                long   databaseMaxSize   = 5L * 1024L * 1024L * 1024L; // 5 GB
                Guid   dbSloS1           = SqlConstants.DbSloS1;

                // Variables for job account create
                string jobAccountName = TestUtilities.GenerateName("csm-sql-jobaccountcrud-jobaccount");

                // Create the resource group.
                resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
                {
                    Location = serverLocation,
                });

                try
                {
                    //////////////////////////////////////////////////////////////////////
                    // Create server for test.
                    var createServerResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin         = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });

                    // Verify the the response from the service contains the right information
                    TestUtilities.ValidateOperationResponse(createServerResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create database for test.

                    // Create all options.
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location   = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Collation    = databaseCollation,
                            Edition      = databaseEdition,
                            MaxSizeBytes = databaseMaxSize,
                            RequestedServiceObjectiveId = dbSloS1
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);

                    //////////////////////////////////////////////////////////////////////
                    // Create job account test.

                    var createJobResonse = sqlClient.JobAccounts.CreateOrUpdate(resGroupName, serverName, jobAccountName,
                                                                                new JobAccountCreateOrUpdateParameters
                    {
                        Location   = serverLocation,
                        Properties = new JobAccountCreateOrUpdateProperties
                        {
                            DatabaseId = createDbResponse.Database.Id
                        }
                    });

                    TestUtilities.ValidateOperationResponse(createJobResonse, HttpStatusCode.Created);
                    VerifyJobAccountInformation(createJobResonse.JobAccount, jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Get job account test

                    var getJobAccountResponse = sqlClient.JobAccounts.Get(resGroupName, serverName, jobAccountName);
                    TestUtilities.ValidateOperationResponse(getJobAccountResponse);
                    VerifyJobAccountInformation(getJobAccountResponse.JobAccount, jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // List job account test

                    var listJobAccountResponse = sqlClient.JobAccounts.List(resGroupName, serverName);
                    TestUtilities.ValidateOperationResponse(listJobAccountResponse);
                    Assert.Equal(1, listJobAccountResponse.Count());
                    VerifyJobAccountInformation(listJobAccountResponse.JobAccounts[0], jobAccountName, createDbResponse.Database.Id);

                    //////////////////////////////////////////////////////////////////////
                    // Delete job account test

                    var deleteJobAccountResponse = sqlClient.JobAccounts.Delete(resGroupName, serverName, jobAccountName);
                    TestUtilities.ValidateOperationResponse(deleteJobAccountResponse);
                }
                finally
                {
                    // Clean up the resource group.
                    resClient.ResourceGroups.Delete(resGroupName);
                }
            }
        }
示例#27
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("Microsoft.Authorization", null);
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);

            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);


                this.csmTestFactory = new CSMTestEnvironmentFactory();


                if (initialize != null)
                {
                    initialize(this.csmTestFactory);
                }


                this.SetupManagementClients();


                this.helper.SetupEnvironment(AzureModule.AzureResourceManager);


                string callingClassName = callingClassType
                                          .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                          .Last();


                this.helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\Common.ps1", "ScenarioTests\\" + callingClassName + ".ps1",
                                         helper.RMProfileModule,
                                         helper.RMResourceModule,
                                         helper.GetRMModulePath("AzureRM.Dns.psd1"));

                try
                {
                    if (scriptBuilder != null)
                    {
                        string[] psScripts = scriptBuilder();


                        if (psScripts != null)
                        {
                            this.helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
示例#28
0
        public void CreateDummyDeploymentProducesOperations()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.Created
            };
            var dictionary = new Dictionary <string, object> {
                { "string", new Dictionary <string, object>()
                  {
                      { "value", "myvalue" },
                  } },
                { "securestring", new Dictionary <string, object>()
                  {
                      { "value", "myvalue" },
                  } },
                { "int", new Dictionary <string, object>()
                  {
                      { "value", 42 },
                  } },
                { "bool", new Dictionary <string, object>()
                  {
                      { "value", true },
                  } }
            };
            var serializedDictionary = JsonConvert.SerializeObject(dictionary, new JsonSerializerSettings
            {
                TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
                TypeNameHandling       = TypeNameHandling.None
            });

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client     = GetResourceManagementClient(handler);
                var parameters = new Deployment
                {
                    Properties = new DeploymentProperties()
                    {
                        TemplateLink = new TemplateLink
                        {
                            Uri = new Uri(DummyTemplateUri)
                        },
                        Parameters = serializedDictionary,
                        Mode       = DeploymentMode.Incremental,
                    }
                };

                string groupName      = TestUtilities.GenerateName("csmrg");
                string deploymentName = TestUtilities.GenerateName("csmd");
                string resourceName   = TestUtilities.GenerateName("csmr");

                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = "West Europe"
                });
                client.Deployments.CreateOrUpdate(groupName, deploymentName, parameters);

                // Wait until deployment completes
                TestUtilities.Wait(30000);
                var operations = client.DeploymentOperations.List(groupName, deploymentName, null);

                Assert.True(operations.Operations.Any());
                Assert.NotNull(operations.Operations[0].Id);
                Assert.NotNull(operations.Operations[0].OperationId);
                Assert.NotNull(operations.Operations[0].Properties);
            }
        }
示例#29
0
        public void CreateDeploymentAndValidateProperties()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.Created
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var    client       = GetResourceManagementClient(handler);
                string resourceName = TestUtilities.GenerateName("csmr");

                var parameters = new Deployment
                {
                    Properties = new DeploymentProperties()
                    {
                        TemplateLink = new TemplateLink
                        {
                            Uri = new Uri(GoodWebsiteTemplateUri),
                        },
                        Parameters =
                            @"{ 'siteName': {'value': 'mctest0101'},'hostingPlanName': {'value': 'mctest0101'},'siteMode': {'value': 'Limited'},'computeMode': {'value': 'Shared'},'siteLocation': {'value': 'North Europe'},'sku': {'value': 'Free'},'workerSize': {'value': '0'}}",
                        Mode = DeploymentMode.Incremental,
                    }
                };
                string groupName      = TestUtilities.GenerateName("csmrg");
                string deploymentName = TestUtilities.GenerateName("csmd");
                client.ResourceGroups.CreateOrUpdate(groupName, new ResourceGroup {
                    Location = "West Europe"
                });
                var deploymentCreateResult = client.Deployments.CreateOrUpdate(groupName, deploymentName, parameters);

                Assert.NotNull(deploymentCreateResult.Deployment.Id);
                Assert.Equal(deploymentName, deploymentCreateResult.Deployment.Name);

                TestUtilities.Wait(1000);

                var deploymentListResult = client.Deployments.List(groupName, null);
                var deploymentGetResult  = client.Deployments.Get(groupName, deploymentName);

                Assert.NotEmpty(deploymentListResult.Deployments);
                Assert.Equal(deploymentName, deploymentGetResult.Deployment.Name);
                Assert.Equal(deploymentName, deploymentListResult.Deployments[0].Name);
                Assert.Equal(GoodWebsiteTemplateUri, deploymentGetResult.Deployment.Properties.TemplateLink.Uri.AbsoluteUri);
                Assert.Equal(GoodWebsiteTemplateUri, deploymentListResult.Deployments[0].Properties.TemplateLink.Uri.AbsoluteUri);
                Assert.NotNull(deploymentGetResult.Deployment.Properties.ProvisioningState);
                Assert.NotNull(deploymentListResult.Deployments[0].Properties.ProvisioningState);
                Assert.NotNull(deploymentGetResult.Deployment.Properties.CorrelationId);
                Assert.NotNull(deploymentListResult.Deployments[0].Properties.CorrelationId);
                Assert.True(deploymentGetResult.Deployment.Properties.Parameters.Contains("mctest0101"));
                Assert.True(deploymentListResult.Deployments[0].Properties.Parameters.Contains("mctest0101"));

                //stop the deployment
                client.Deployments.Cancel(groupName, deploymentName);
                TestUtilities.Wait(2000);

                //Delete deployment
                Assert.Equal(HttpStatusCode.NoContent, client.Deployments.Delete(groupName, deploymentName).StatusCode);
            }
        }
        public void GetAndSetSiteLimits()
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var webSitesClient  = ResourceGroupHelper.GetWebSitesClient(handler);
                var resourcesClient = ResourceGroupHelper.GetResourcesClient(handler);

                string whpName           = TestUtilities.GenerateName("cswhp");
                string resourceGroupName = TestUtilities.GenerateName("csmrg");

                var    locationName = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");
                string siteName     = TestUtilities.GenerateName("csmws");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = locationName
                });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName, new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name       = whpName,
                        Location   = locationName,
                        Properties = new WebHostingPlanProperties
                        {
                            NumberOfWorkers = 1,
                            WorkerSize      = WorkerSizeOptions.Small
                        }
                    }
                });

                var createResponse = webSitesClient.WebSites.CreateOrUpdate(resourceGroupName, siteName, null, new WebSiteCreateOrUpdateParameters()
                {
                    WebSite = new WebSiteBase()
                    {
                        Name       = siteName,
                        Location   = locationName,
                        Properties = new WebSiteBaseProperties()
                        {
                            ServerFarm = whpName
                        }
                    }
                });

                #region Get/Set Site limits

                var expectedSitelimits = new SiteLimits()
                {
                    MaxDiskSizeInMb  = 512,
                    MaxMemoryInMb    = 1024,
                    MaxPercentageCpu = 70.5
                };
                var parameters = new WebSiteUpdateConfigurationParameters()
                {
                    Location   = locationName,
                    Properties = new WebSiteUpdateConfigurationDetails()
                    {
                        Limits = expectedSitelimits
                    }
                };


                var siteUpdateConfigResponse = webSitesClient.WebSites.UpdateConfiguration(
                    resourceGroupName,
                    siteName,
                    null,
                    parameters);

                Assert.Equal(HttpStatusCode.OK, siteUpdateConfigResponse.StatusCode);

                var siteGetConfigResponse = webSitesClient.WebSites.GetConfiguration(resourceGroupName,
                                                                                     siteName, null, null);

                Assert.NotNull(siteGetConfigResponse);
                Assert.NotNull(siteGetConfigResponse.Resource);
                Assert.NotNull(siteGetConfigResponse.Resource.Properties);
                var limits = siteGetConfigResponse.Resource.Properties.Limits;
                Assert.NotNull(limits);
                Assert.Equal(expectedSitelimits.MaxDiskSizeInMb, limits.MaxDiskSizeInMb);
                Assert.Equal(expectedSitelimits.MaxMemoryInMb, limits.MaxMemoryInMb);
                Assert.Equal(expectedSitelimits.MaxPercentageCpu, limits.MaxPercentageCpu);

                #endregion Get/Set Site limits

                webSitesClient.WebSites.Delete(resourceGroupName, siteName, null, new WebSiteDeleteParameters()
                {
                    DeleteAllSlots = true,
                    DeleteMetrics  = true
                });

                webSitesClient.WebHostingPlans.Delete(resourceGroupName, whpName);
            }
        }
        private void RunWebsiteTestScenario(WebsiteTestDelegate testAction, SkuOptions sku = SkuOptions.Shared)
        {
            var handler = new RecordedDelegatingHandler()
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start(4);
                WebSiteManagementClient  webSitesClient  = ResourceGroupHelper.GetWebSitesClient(handler);
                ResourceManagementClient resourcesClient = ResourceGroupHelper.GetResourcesClient(handler);

                string webSiteName        = TestUtilities.GenerateName("csmws");
                string resourceGroupName  = TestUtilities.GenerateName("csmrg");
                string webHostingPlanName = TestUtilities.GenerateName("csmwhp");
                string location           = ResourceGroupHelper.GetResourceLocation(resourcesClient, "Microsoft.Web/sites");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                webSitesClient.WebHostingPlans.CreateOrUpdate(resourceGroupName,
                                                              new WebHostingPlanCreateOrUpdateParameters
                {
                    WebHostingPlan = new WebHostingPlan
                    {
                        Name       = webHostingPlanName,
                        Location   = location,
                        Properties = new WebHostingPlanProperties()
                        {
                            Sku = sku
                        }
                    }
                });

                var webSite = webSitesClient.WebSites.CreateOrUpdate(resourceGroupName, webSiteName, null, new WebSiteCreateOrUpdateParameters
                {
                    WebSite = new WebSiteBase
                    {
                        Name     = webSiteName,
                        Location = location,
                        Tags     = new Dictionary <string, string> {
                            { "tag1", "value1" }, { "tag2", "" }
                        },
                        Properties = new WebSiteBaseProperties
                        {
                            ServerFarm = webHostingPlanName
                        }
                    }
                });

                Assert.Equal(webSiteName, webSite.WebSite.Name);
                Assert.Equal(webSite.WebSite.Properties.ServerFarm, webHostingPlanName);
                Assert.Equal("value1", webSite.WebSite.Tags["tag1"]);
                Assert.Equal("", webSite.WebSite.Tags["tag2"]);

                testAction(webSiteName, resourceGroupName, webHostingPlanName, location, webSitesClient, resourcesClient);
            }
        }