public void AdvancedProvisioning()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
            string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix);

            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);

            AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall, imageName);
            AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall, imageName);
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
            AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/", null, null);

            PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
            PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
            PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
            pass = true;
        }
        public void AdvancedProvisioning()
        {
            string newAzureVM1Name = Utilities.GetUniqueShortName("PSTestVM");
            string newAzureVM2Name = Utilities.GetUniqueShortName("PSTestVM");

            string newAzureSvcName = Utilities.GetUniqueShortName("PSTestService");
            vmPowershellCmdlets.NewAzureService(newAzureSvcName, newAzureSvcName, locationName);

            AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, VMSizeInfo.ExtraSmall, imageName);
            AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, VMSizeInfo.ExtraSmall, imageName);
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, "p@ssw0rd");
            AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/");

            PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
            PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
            PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

            //PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            PersistentVM[] VMs = { persistentVM1};
            vmPowershellCmdlets.NewAzureVM(newAzureSvcName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, newAzureSvcName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, newAzureSvcName);

            vmPowershellCmdlets.RemoveAzureService(newAzureSvcName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, newAzureSvcName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, newAzureSvcName));
        }
        public void AdvancedProvisioning()
        {
            ServiceManagementCmdletTestHelper vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();
            vmPowershellCmdlets.ImportAzurePublishSettingsFile();
            string imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "MSFT", "testvmimage" }, false);
            string locationName = vmPowershellCmdlets.GetAzureLocationName(new[] { Resource.Location }, false);

            string newAzureVM1Name = Utilities.GetUniqueShortName("PSTestVM");
            string newAzureVM2Name = Utilities.GetUniqueShortName("PSTestVM");

            string newAzureSvcName = Utilities.GetUniqueShortName("PSTestService");
            vmPowershellCmdlets.NewAzureService(newAzureSvcName, newAzureSvcName, locationName);

            AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, VMSizeInfo.ExtraSmall, imageName);
            AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, VMSizeInfo.ExtraSmall, imageName);
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, "p@ssw0rd");
            AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(ProtocolInfo.tcp, 80, 80, "web", "lbweb", 80, ProtocolInfo.http, @"/");

            PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
            PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
            PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            vmPowershellCmdlets.NewAzureVM(newAzureSvcName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, newAzureSvcName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, newAzureSvcName);
            /* RemoveAzureService doesn't work */
            //vmPowershellCmdlets.RemoveAzureService(newAzureSvcName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, newAzureSvcName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, newAzureSvcName));
        }
        public void AddEndPointACLsWithNewDeployment()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string newAzureVM1Name = Utilities.GetUniqueShortName(vmNamePrefix);
            string newAzureVM2Name = Utilities.GetUniqueShortName(vmNamePrefix);
            if (string.IsNullOrEmpty(imageName))
                imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "Windows", "testvmimage" }, false);

            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);

            NetworkAclObject aclObj = vmPowershellCmdlets.NewAzureAclConfig();
            vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 100, ACLAction.Permit, "172.0.0.0/8", "notes1");
            vmPowershellCmdlets.SetAzureAclConfig(SetACLConfig.AddRule, aclObj, 200, ACLAction.Deny, "10.0.0.0/8", "notes2");

            AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(newAzureVM1Name, InstanceSize.ExtraSmall, imageName);
            AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(newAzureVM2Name, InstanceSize.ExtraSmall, imageName);
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);
            AddAzureDataDiskConfig azureDataDiskConfigInfo = new AddAzureDataDiskConfig(DiskCreateOption.CreateNew, 50, "datadisk1", 0);
            AzureEndPointConfigInfo azureEndPointConfigInfo = new AzureEndPointConfigInfo(AzureEndPointConfigInfo.ParameterSet.DefaultProbe, ProtocolInfo.tcp, 80, 80, "web", "lbweb", aclObj, true);

            PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);
            PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig, azureDataDiskConfigInfo, azureEndPointConfigInfo);

            PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);
            PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

            PersistentVM[] VMs = { persistentVM1, persistentVM2 };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM1Name, serviceName);
            vmPowershellCmdlets.RemoveAzureVM(newAzureVM2Name, serviceName);

            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM1Name, serviceName));
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVM2Name, serviceName));
            pass = true;
        }
        public void AzureDnsTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            string dnsName = "OpenDns1";
            string ipAddress = "208.67.222.222";

            try
            {
                vmPowershellCmdlets.NewAzureService(serviceName, locationName);

                DnsServer dns = vmPowershellCmdlets.NewAzureDns(dnsName, ipAddress);

                AzureVMConfigInfo azureVMConfigInfo = new AzureVMConfigInfo(vmName, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password);

                PersistentVMConfigInfo persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);

                PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);

                vmPowershellCmdlets.NewAzureVM(serviceName, new []{vm}, null, new[]{dns}, null, null, null, null);

                Assert.IsTrue(Verify.AzureDns(vmPowershellCmdlets.GetAzureDeployment(serviceName).DnsSettings, dns));
                pass = true;

            }
            catch (Exception e)
            {
                pass = false;
                Console.WriteLine("Exception occurred: {0}", e.ToString());
                throw;
            }
        }
        public void AzureCertificateSettingTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Create a certificate
            string cerFileName = Convert.ToString(TestContext.DataRow["cerFileName"]);
            X509Certificate2 certCreated = Utilities.CreateCertificate(password);
            byte[] certData2 = certCreated.Export(X509ContentType.Cert);
            File.WriteAllBytes(cerFileName, certData2);

            // Install the .cer file to local machine.
            StoreLocation certStoreLocation = StoreLocation.CurrentUser;
            StoreName certStoreName = StoreName.My;
            X509Certificate2 installedCert = Utilities.InstallCert(cerFileName, certStoreLocation, certStoreName);

            PSObject certToUpload = vmPowershellCmdlets.RunPSScript(
                String.Format("Get-Item cert:\\{0}\\{1}\\{2}", certStoreLocation.ToString(), certStoreName.ToString(), installedCert.Thumbprint))[0];

            try
            {
                vmPowershellCmdlets.NewAzureService(serviceName, locationName);
                vmPowershellCmdlets.AddAzureCertificate(serviceName, certToUpload);

                CertificateSettingList certList = new CertificateSettingList();
                certList.Add(vmPowershellCmdlets.NewAzureCertificateSetting(certStoreName.ToString(), installedCert.Thumbprint));

                AzureVMConfigInfo azureVMConfigInfo = new AzureVMConfigInfo(vmName, InstanceSize.Small, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, certList, username, password);

                PersistentVMConfigInfo persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);

                PersistentVM vm = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo);

                vmPowershellCmdlets.NewAzureVM(serviceName, new[] { vm });

                PersistentVMRoleContext result = vmPowershellCmdlets.GetAzureVM(vmName, serviceName);

                Console.WriteLine("{0} is created", result.Name);

                pass = true;
            }
            catch (Exception e)
            {
                pass = false;
                Assert.Fail(e.ToString());
            }
            finally
            {
                Utilities.UninstallCert(installedCert, certStoreLocation, certStoreName);
            }
        }
        public void CaptureImagingExportingImportingVMConfig()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            // Create a unique VM name
            string newAzureVMName = Utilities.GetUniqueShortName("PSTestVM");
            Console.WriteLine("VM Name: {0}", newAzureVMName);

            // Create a unique Service Name
            vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
            Console.WriteLine("Service Name: {0}", serviceName);

            // starting the test.

            AzureVMConfigInfo azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, InstanceSize.Small, imageName); // parameters for New-AzureVMConfig (-Name -InstanceSize -ImageName)
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, username, password); // parameters for Add-AzureProvisioningConfig (-Windows -Password)
            PersistentVMConfigInfo persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
            PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVMConfig & Add-AzureProvisioningConfig

            PersistentVM[] VMs = { persistentVM };
            vmPowershellCmdlets.NewAzureVM(serviceName, VMs); // New-AzureVM
            Console.WriteLine("The VM is successfully created: {0}", persistentVM.RoleName);
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
            Assert.AreEqual(vmRoleCtxt.Name, persistentVM.RoleName, true);

            vmPowershellCmdlets.StopAzureVM(newAzureVMName, serviceName); // Stop-AzureVM
            for (int i = 0; i < 3; i++)
            {
                vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName);
                if (vmRoleCtxt.InstanceStatus == "StoppedVM")
                    break;
                else
                {
                    Console.WriteLine("The status of the VM {0} : {1}", persistentVM.RoleName, vmRoleCtxt.InstanceStatus);
                    Thread.Sleep(120000);
                }
            }
            Assert.AreEqual(vmRoleCtxt.InstanceStatus, "StoppedVM", true);

            //TODO
            // RDP

            //TODO:
            // Run sysprep and shutdown

            // Check the status of VM
            //PersistentVMRoleContext vmRoleCtxt2 = vmPowershellCmdlets.GetAzureVM(newAzureVMName, newAzureSvcName); // Get-AzureVM -Name
            //Assert.AreEqual(newAzureVMName, vmRoleCtxt2.Name, true);  //

            // Save-AzureVMImage
            //string newImageName = "newImage";
            //string newImageLabel = "newImageLabel";
            //string postAction = "Delete";

            // Save-AzureVMImage -ServiceName -Name -NewImageName -NewImageLabel -PostCaptureAction
            //vmPowershellCmdlets.SaveAzureVMImage(newAzureSvcName, newAzureVMName, newImageName, newImageLabel, postAction);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(persistentVM.RoleName, serviceName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, serviceName));
        }
        internal PersistentVM GetPersistentVM(PersistentVMConfigInfo configInfo)
        {
            PersistentVM vm = null;

            if (null != configInfo)
            {
                if (configInfo.VmConfig != null)
                {
                    vm = SetNewAzureVMConfig(configInfo.VmConfig);
                }

                if (configInfo.ProvConfig != null)
                {
                    configInfo.ProvConfig.Vm = vm;
                    vm = SetProvisioningConfig(configInfo.ProvConfig);
                }

                if (configInfo.DiskConfig != null)
                {
                    configInfo.DiskConfig.Vm = vm;
                    vm = AddAzureDataDisk(configInfo.DiskConfig);
                }

                if (configInfo.EndPointConfig != null)
                {
                    configInfo.EndPointConfig.Vm = vm;
                    vm = SetAzureEndPoint(configInfo.EndPointConfig);
                }
            }

            return vm;
        }
        public void CaptureImagingExportingImportingVMConfig()
        {
            ServiceManagementCmdletTestHelper vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();
            vmPowershellCmdlets.ImportAzurePublishSettingsFile(); // Import-AzurePublishSettingsFile
            var defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName); // Set-AzureSubscription
            Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName);

            //
            string imageName = vmPowershellCmdlets.GetAzureVMImageName(new[] { "MSFT", "testvmimage" }, false); // Get-AzureVMImage
            Console.WriteLine("Image Name: {0}", imageName);

            string locationName = vmPowershellCmdlets.GetAzureLocationName(new[] { Resource.Location }, false); // Get-AzureLocation
            Console.WriteLine("Location Name: {0}", locationName);

            // Create a unique VM name
            string newAzureVMName = Utilities.GetUniqueShortName("PSTestVM");
            Console.WriteLine("VM Name: {0}", newAzureVMName);

            // Create a unique Service Name
            string newAzureSvcName = Utilities.GetUniqueShortName("PSTestService");
            vmPowershellCmdlets.NewAzureService(newAzureSvcName, newAzureSvcName, locationName);
            Console.WriteLine("VM Service Name: {0}", newAzureSvcName);

            // starting the test.

            AzureVMConfigInfo azureVMConfigInfo = new AzureVMConfigInfo(newAzureVMName, VMSizeInfo.Small, imageName); // parameters for New-AzureVMConfig (-Name -InstanceSize -ImageName)
            AzureProvisioningConfigInfo azureProvisioningConfig = new AzureProvisioningConfigInfo(OS.Windows, "p@ssw0rd"); // parameters for Add-AzureProvisioningConfig (-Windows -Password)
            PersistentVMConfigInfo persistentVMConfigInfo = new PersistentVMConfigInfo(azureVMConfigInfo, azureProvisioningConfig, null, null);
            PersistentVM persistentVM = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo); // New-AzureVMConfig & Add-AzureProvisioningConfig

            PersistentVM[] VMs = { persistentVM };
            vmPowershellCmdlets.NewAzureVM(newAzureSvcName, VMs); // New-AzureVM
            Console.WriteLine("The VM is successfully created: {0}", persistentVM.RoleName);
            PersistentVMRoleContext vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, newAzureSvcName);
            Assert.AreEqual(vmRoleCtxt.Name, persistentVM.RoleName, true);

            vmPowershellCmdlets.StopAzureVM(newAzureVMName, newAzureSvcName); // Stop-AzureVM
            for (int i = 0; i < 3; i++)
            {
                vmRoleCtxt = vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, newAzureSvcName);
                if (vmRoleCtxt.InstanceStatus == "StoppedVM")
                    break;
                else
                {
                    Console.WriteLine("The status of the VM {0} : {1}", persistentVM.RoleName, vmRoleCtxt.InstanceStatus);
                    Thread.Sleep(120000);
                }
            }
            Assert.AreEqual(vmRoleCtxt.InstanceStatus, "StoppedVM", true);

            //TODO
            // RDP

            //TODO:
            // Run sysprep and shutdown

            // Check the status of VM
            //PersistentVMRoleContext vmRoleCtxt2 = vmPowershellCmdlets.GetAzureVM(newAzureVMName, newAzureSvcName); // Get-AzureVM -Name
            //Assert.AreEqual(newAzureVMName, vmRoleCtxt2.Name, true);  //

            // Save-AzureVMImage
            //string newImageName = "newImage";
            //string newImageLabel = "newImageLabel";
            //string postAction = "Delete";

            // Save-AzureVMImage -ServiceName -Name -NewImageName -NewImageLabel -PostCaptureAction
            //vmPowershellCmdlets.SaveAzureVMImage(newAzureSvcName, newAzureVMName, newImageName, newImageLabel, postAction);

            // Cleanup
            vmPowershellCmdlets.RemoveAzureVM(persistentVM.RoleName, newAzureSvcName);
            Assert.AreEqual(null, vmPowershellCmdlets.GetAzureVM(persistentVM.RoleName, newAzureSvcName));
        }
        public void StopAzureVMStayProvisionedTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                // starting the test.
                AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(vmName1, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig1 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig1, null, null);
                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);

                AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(vmName2, InstanceSize.Small, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig2 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig2, null, null);
                PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

                PersistentVM[] VMs = { persistentVM1, persistentVM2 };
                vmPowershellCmdlets.NewAzureVM(svcName, VMs);
                Console.WriteLine("The VM is successfully created: {0}", vmName1);
                Console.WriteLine("The VM is successfully created: {0}", vmName2);

                WaitForStartingState(svcName, vmName1);
                vmPowershellCmdlets.StopAzureVM(vmName1, svcName, true); // Stop-AzureVM -StayProvisioned against VM1
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                // Stop-AzureVM -StayProvisioned against VM2
                vmPowershellCmdlets.RunPSScript(string.Format("{0} -ServiceName {1} -Name {2} | {3} -StayProvisioned",
                    Utilities.GetAzureVMCmdletName, svcName, vmName2, Utilities.StopAzureVMCmdletName));

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string [] {stoppedProvisionedState}));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string [] {stoppedProvisionedState}));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
                {
                    vmPowershellCmdlets.RemoveAzureService(svcName);
                }
            }
        }
        public void StopAzureVMOnStoppedVMTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                // starting the test.
                AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(vmName1, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig1 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig1, null, null);
                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);

                PersistentVM[] VMs = { persistentVM1 };
                vmPowershellCmdlets.NewAzureVM(svcName, VMs);
                Console.WriteLine("The VM is successfully created: {0}", vmName1);

                WaitForStartingState(svcName, vmName1);

                // Stop the VM with StayProvisioned
                vmPowershellCmdlets.StopAzureVM(vmName1, svcName, true);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                // Try to stop it again.  Should not change the state.
                vmPowershellCmdlets.StopAzureVM(vmName1, svcName, true);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                try
                {
                    // Try to stop without any option.  Should fail with a warning message.
                    vmPowershellCmdlets.StopAzureVM(vmName1, svcName);
                    Assert.Fail();
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    else
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                // Stop the VM with Force option.   Should deallocate the VM.
                vmPowershellCmdlets.StopAzureVM(vmName1, svcName, false, true);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedDeallocatedState }));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
                {
                    vmPowershellCmdlets.RemoveAzureService(svcName);
                }
            }
        }
        public void RestartAzureVMTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                DateTime prevTime = DateTime.Now;

                // starting the test.
                AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(vmName1, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig1 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig1, null, null);
                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);

                PersistentVM[] VMs = { persistentVM1 };

                Utilities.RecordTimeTaken(ref prevTime);
                vmPowershellCmdlets.NewAzureVM(svcName, VMs);
                Utilities.RecordTimeTaken(ref prevTime);

                Console.WriteLine("The VM is successfully created: {0}", vmName1);

                WaitForStartingState(svcName, vmName1);

                Console.WriteLine(vmPowershellCmdlets.GetAzureVM(vmName1, svcName).InstanceStatus);

                Utilities.RecordTimeTaken(ref prevTime);
                vmPowershellCmdlets.StopAzureVM(vmName1, svcName, true);
                Utilities.RecordTimeTaken(ref prevTime);

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                Utilities.RecordTimeTaken(ref prevTime);
                vmPowershellCmdlets.StartAzureVM(vmName1, svcName);
                Utilities.RecordTimeTaken(ref prevTime);

                WaitForReadyState(svcName, vmName1);
                Utilities.RecordTimeTaken(ref prevTime);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { readyState }));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
                {
                    vmPowershellCmdlets.RemoveAzureService(svcName);
                }
            }
        }
        public void StopAzureVMsDeprovisonedTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                // starting the test.
                AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(vmName1, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig1 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig1, null, null);
                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);

                AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(vmName2, InstanceSize.Small, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig2 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig2, null, null);
                PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

                PersistentVM[] VMs = { persistentVM1, persistentVM2 };
                vmPowershellCmdlets.NewAzureVM(svcName, VMs);
                Console.WriteLine("The VM is successfully created: {0}", vmName1);
                Console.WriteLine("The VM is successfully created: {0}", vmName2);

                WaitForReadyState(svcName, vmName1);
                WaitForReadyState(svcName, vmName2);

                // Stop and deallocate the VMs
                vmPowershellCmdlets.StopAzureVM("*", svcName, false, true);

                WaitForStoppedState(svcName, vmName1);
                WaitForStoppedState(svcName, vmName2);

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedDeallocatedState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { stoppedDeallocatedState }));

                // Start the VMs
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.StartAzureVM("*", svcName), "HTTP Status Code: 409", 10, 60);
                //StartAzureVMs("*", svcName);

                WaitForStartedState(svcName, vmName1);
                WaitForStartedState(svcName, vmName2);

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { readyState, provisioningState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { readyState, provisioningState }));

                try
                {
                    // Try to Stop and deallocate VM2 without Force.  Should fail and give a warning message.
                    vmPowershellCmdlets.StopAzureVM("*", svcName);
                    Assert.Fail();
                }
                catch (Exception e)
                {
                    if (e is AssertFailedException)
                    {
                        throw;
                    }
                    else
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { readyState, provisioningState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { readyState, provisioningState }));

                // Stop and deallocate VMs
                vmPowershellCmdlets.StopAzureVM("*", svcName, false, true);

                WaitForStoppedState(svcName, vmName1);
                WaitForStoppedState(svcName, vmName2);

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedDeallocatedState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { stoppedDeallocatedState }));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
                {
                    vmPowershellCmdlets.RemoveAzureService(svcName);
                }
            }
        }
        public void RestartAzureVMsTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            try
            {
                DateTime prevTime = DateTime.Now;

                // Configure VM1
                AzureVMConfigInfo azureVMConfigInfo1 = new AzureVMConfigInfo(vmName1, InstanceSize.ExtraSmall, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig1 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo1 = new PersistentVMConfigInfo(azureVMConfigInfo1, azureProvisioningConfig1, null, null);
                PersistentVM persistentVM1 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo1);

                // Configure VM2
                AzureVMConfigInfo azureVMConfigInfo2 = new AzureVMConfigInfo(vmName2, InstanceSize.Small, imageName);
                AzureProvisioningConfigInfo azureProvisioningConfig2 = new AzureProvisioningConfigInfo(OS.Windows, username, password);
                PersistentVMConfigInfo persistentVMConfigInfo2 = new PersistentVMConfigInfo(azureVMConfigInfo2, azureProvisioningConfig2, null, null);
                PersistentVM persistentVM2 = vmPowershellCmdlets.GetPersistentVM(persistentVMConfigInfo2);

                PersistentVM[] VMs = { persistentVM1, persistentVM2 };

                Utilities.RecordTimeTaken(ref prevTime);
                vmPowershellCmdlets.NewAzureVM(svcName, VMs);
                Utilities.RecordTimeTaken(ref prevTime);

                Console.WriteLine("The VM is successfully created: {0}", vmName1);
                Console.WriteLine("The VM is successfully created: {0}", vmName2);

                WaitForReadyState(svcName, vmName1);
                WaitForReadyState(svcName, vmName2);

                Console.WriteLine(vmPowershellCmdlets.GetAzureVM(vmName1, svcName).InstanceStatus);
                Console.WriteLine(vmPowershellCmdlets.GetAzureVM(vmName2, svcName).InstanceStatus);

                // Stop VM1 one only using wildcard name
                string vm1WildcardName = vmName1.Replace(prefixVMName, "*");
                Utilities.RecordTimeTaken(ref prevTime);
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.StopAzureVM(vm1WildcardName, svcName, true, true), "HTTP Status Code: 409", 10, 60);
                //StopAzureVMs(vm1WildcardName, svcName, true, true);
                Utilities.RecordTimeTaken(ref prevTime);

                WaitForStoppedState(svcName, vmName1);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));

                // Start VM1 one only using wildcard name
                Utilities.RecordTimeTaken(ref prevTime);
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.StartAzureVM(vm1WildcardName, svcName), "HTTP Status Code: 409", 10, 60);
                //StartAzureVMs(vm1WildcardName, svcName);
                Utilities.RecordTimeTaken(ref prevTime);

                WaitForReadyState(svcName, vmName1);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { readyState }));

                // Stop all VM's
                Utilities.RecordTimeTaken(ref prevTime);
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.StopAzureVM("*", svcName, true, true), "HTTP Status Code: 409", 10, 60);
                //StopAzureVMs("*", svcName, true, true);
                Utilities.RecordTimeTaken(ref prevTime);

                WaitForStoppedState(svcName, vmName1);
                WaitForStoppedState(svcName, vmName2);

                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { stoppedProvisionedState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { stoppedProvisionedState }));

                //Start all VM's
                Utilities.RecordTimeTaken(ref prevTime);
                Utilities.RetryActionUntilSuccess(() => vmPowershellCmdlets.StartAzureVM("*", svcName), "HTTP Status Code: 409", 10, 60);
                //StartAzureVMs("*", svcName);
                Utilities.RecordTimeTaken(ref prevTime);

                WaitForReadyState(svcName, vmName1);
                WaitForReadyState(svcName, vmName2);

                Utilities.RecordTimeTaken(ref prevTime);
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName1, new string[] { readyState }));
                Assert.IsTrue(CheckRoleInstanceState(svcName, vmName2, new string[] { readyState }));

                pass = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                if ((cleanupIfPassed && pass) || (cleanupIfFailed && !pass))
                {
                    vmPowershellCmdlets.RemoveAzureService(svcName);
                }
            }
        }