public void RemoveAzureServiceProcessTest()
        {
            SimpleServiceManagement channel = new SimpleServiceManagement();
            bool serviceDeleted = false;
            bool deploymentDeleted = false;
            channel.GetDeploymentBySlotThunk = ar =>
            {
                if (deploymentDeleted) throw new EndpointNotFoundException();
                return new Deployment(serviceName, ArgumentConstants.Slots[Slot.Production], DeploymentStatus.Suspended);
            };
            channel.DeleteHostedServiceThunk = ar => serviceDeleted = true;
            channel.DeleteDeploymentBySlotThunk = ar =>
            {
                deploymentDeleted = true;
            };

            using (FileSystemHelper files = new FileSystemHelper(this))
            {

                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                var removeAzureServiceCommand = new RemoveAzureServiceCommand(channel);
                removeAzureServiceCommand.ShareChannel = true;
                removeAzureServiceCommand.RemoveAzureServiceProcess(service.Paths.RootPath, string.Empty, serviceName);
                Assert.IsTrue(deploymentDeleted);
                Assert.IsTrue(serviceDeleted);
            }
        }
        public void AddAzureWebRoleWillRecreateDeploymentSettings()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WebRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreate, rootPath, roleName);
                string settingsFilePath = Path.Combine(rootPath, Resources.SettingsFileName);
                string originalDirectory = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(rootPath);
                File.Delete(settingsFilePath);
                Assert.IsFalse(File.Exists(settingsFilePath));
                addWebCmdlet = new AddAzureWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = roleName };

                addWebCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, "AzureService", roleName), Path.Combine(Resources.GeneralScaffolding, Resources.WebRole));
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);
                Assert.IsTrue(File.Exists(settingsFilePath));

                Directory.SetCurrentDirectory(originalDirectory);
            }
        }
        public void AddNewCacheWorkerRoleSuccessful()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string rootPath = Path.Combine(files.RootPath, "AzureService");
                string roleName = "WorkerRole";
                int expectedInstanceCount = 10;
                newServiceCmdlet.NewAzureServiceProcess(files.RootPath, "AzureService");
                WorkerRole cacheWorkerRole = addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(roleName, expectedInstanceCount, rootPath);

                AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, "AzureService", "WorkerRole"), Path.Combine(Resources.GeneralScaffolding, Resources.WorkerRole));

                AzureAssert.WorkerRoleImportsExists(new Import { moduleName = Resources.CachingModuleName }, cacheWorkerRole);

                AzureAssert.LocalResourcesLocalStoreExists(new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false },
                    cacheWorkerRole.LocalResources);

                Assert.IsNull(cacheWorkerRole.Endpoints.InputEndpoint);

                AssertConfigExists(Testing.GetCloudRole(rootPath, roleName));
                AssertConfigExists(Testing.GetLocalRole(rootPath, roleName), Resources.EmulatorConnectionString);

                PSObject actualOutput = mockCommandRuntime.OutputPipeline[1] as PSObject;
                Assert.AreEqual<string>(roleName, actualOutput.Members[Parameters.CacheWorkerRoleName].Value.ToString());
                Assert.AreEqual<int>(expectedInstanceCount, int.Parse(actualOutput.Members[Parameters.Instances].Value.ToString()));
            }
        }
        public void SetDeploymentStatusProcessDeploymentDoesNotExistTest()
        {
            SimpleServiceManagement channel = new SimpleServiceManagement();
            string newStatus = DeploymentStatus.Running;
            string resultMessage;
            string expectedMessage = string.Format(Resources.ServiceSlotDoesNotExist, serviceName, slot);
            bool statusUpdated = false;
            channel.UpdateDeploymentStatusBySlotThunk = ar =>
            {
                statusUpdated = true;
                channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus);
            };
            channel.GetDeploymentBySlotThunk = ar => { throw new EndpointNotFoundException(); };

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                var deploymentManager = new DeploymentStatusManager(channel);
                deploymentManager.ShareChannel = true;
                resultMessage = deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName);

                Assert.IsFalse(statusUpdated);
                Assert.AreEqual<string>(expectedMessage, resultMessage);
            }
        }
 public void SetAzureInstancesProcessTestsEmptyRoleNameFail()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         AzureService service = new AzureService(files.RootPath, serviceName, null);
         Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, string.Empty, 10), string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.RoleName));
     }
 }
 public void GetNextPortAllNull()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         int expectedPort = int.Parse(Resources.DefaultWebPort);
         AzureService service = new AzureService(files.RootPath, serviceName, null);
         int nextPort = service.Components.GetNextPort();
         Assert.AreEqual<int>(expectedPort, nextPort);
     }
 }
        public void SetAzureInstancesProcessNegativeRoleInstanceFail()
        {
            string roleName = "WebRole1";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, roleName, -1), string.Format(Resources.InvalidInstancesCount, roleName));
            }
        }
 public void NewAzureServiceWithInvalidNames()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         foreach (string name in TestData.Data.InvalidServiceNames)
         {
             cmdlet.ServiceName = name;
             Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet());
         }
     }
 }
 public void GetNextPortNodeWebRoleNull()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         int expectedPort = int.Parse(Resources.DefaultPort);
         AzureService service = new AzureService(files.RootPath, serviceName, null);
         service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath);
         service = new AzureService(service.Paths.RootPath, null);
         int nextPort = service.Components.GetNextPort();
         Assert.AreEqual<int>(expectedPort, nextPort);
     }
 }
        public void NewAzureRoleTemplateWithOutputPath()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string outputPath = files.RootPath;
                addTemplateCmdlet = new NewAzureRoleTemplateCommand() { Worker = true, CommandRuntime = mockCommandRuntime, Output = outputPath };

                addTemplateCmdlet.ExecuteCmdlet();

                Assert.AreEqual<string>(outputPath, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.Path));
                Testing.AssertDirectoryIdentical(Path.Combine(Resources.GeneralScaffolding, RoleType.WorkerRole.ToString()), outputPath);
            }
        }
Example #11
0
        public void CreateLocalPackageWithNodeWorkerRoleTest()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string standardOutput;
                string standardError;
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath);
                service.CreatePackage(DevEnv.Local, out standardOutput, out standardError);

                AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WorkerRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole));
            }
        }
        public void SetAzureServiceProjectTestsLocationEmptyFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => setServiceProjectCmdlet.SetAzureServiceProjectProcess(string.Empty, null, null, null, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Location"));
            }
        }
        public void AddAzurePythonWebRoleProcess()
        {
            var pyInstall = AddAzureDjangoWebRoleCommand.FindPythonInterpreterPath();
            if (pyInstall == null)
            {
                Assert.Inconclusive("Python is not installed on this machine and therefore the Python tests cannot be run");
                return;
            }

            string stdOut, stdErr;
            ProcessHelper.StartAndWaitForProcess(
                    new ProcessStartInfo(
                        Path.Combine(pyInstall, "python.exe"),
                        String.Format("-m django.bin.django-admin")
                    ),
                    out stdOut,
                    out stdErr
            );

            if (stdOut.IndexOf("django-admin.py") == -1)
            {
                Assert.Inconclusive("Django is not installed on this machine and therefore the Python tests cannot be run");
                return;
            }

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WebRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                addPythonWebCmdlet = new AddAzureDjangoWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime };
                addPythonWebCmdlet.CommandRuntime = mockCommandRuntime;
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreatePython, rootPath, roleName);
                mockCommandRuntime.ResetPipelines();

                addPythonWebCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(rootPath, roleName), Path.Combine(Resources.PythonScaffolding, Resources.WebRole));
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);
                Assert.IsTrue(Directory.Exists(Path.Combine(rootPath, roleName, roleName)));
                Assert.IsTrue(File.Exists(Path.Combine(rootPath, roleName, roleName, "manage.py")));
                Assert.IsTrue(Directory.Exists(Path.Combine(rootPath, roleName, roleName, roleName)));
                Assert.IsTrue(File.Exists(Path.Combine(rootPath, roleName, roleName, roleName, "__init__.py")));
                Assert.IsTrue(File.Exists(Path.Combine(rootPath, roleName, roleName, roleName, "settings.py")));
                Assert.IsTrue(File.Exists(Path.Combine(rootPath, roleName, roleName, roleName, "urls.py")));
                Assert.IsTrue(File.Exists(Path.Combine(rootPath, roleName, roleName, roleName, "wsgi.py")));
            }
        }
        public void InvalidStorageAccountName()
        {
            // Create a temp directory that we'll use to "publish" our service
            using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true })
            {
                // Import our default publish settings
                files.CreateAzureSdkDirectoryAndImportPublishSettings();

                string serviceName = null;
                Testing.AssertThrows<ArgumentException>(() =>
                    ServiceSettings.LoadDefault(null, null, null, null, "I HAVE INVALID CHARACTERS !@#$%", null, null, out serviceName));
                Testing.AssertThrows<ArgumentException>(() =>
                    ServiceSettings.LoadDefault(null, null, null, null, "ihavevalidcharsbutimjustwaytooooooooooooooooooooooooooooooooooooooooolong", null, null, out serviceName));
            }
        }
        public void AddNewCacheWorkerRoleDoesNotHaveAnyRuntime()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string rootPath = Path.Combine(files.RootPath, "AzureService");
                string roleName = "WorkerRole";
                int expectedInstanceCount = 10;
                newServiceCmdlet.NewAzureServiceProcess(files.RootPath, "AzureService");

                WorkerRole cacheWorkerRole = addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(roleName, expectedInstanceCount, rootPath);

                Variable runtimeId = Array.Find<Variable>(cacheWorkerRole.Startup.Task[0].Environment, v => v.name.Equals(Resources.RuntimeTypeKey));
                Assert.AreEqual<string>(string.Empty, runtimeId.value);
            }
        }
        public void TestGetRuntimes()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string manifest = RuntimePackageHelper.GetTestManifest(files);
                CloudRuntimeCollection runtimes;
                CloudRuntimeCollection.CreateCloudRuntimeCollection(LocationName.NorthCentralUS, out runtimes, manifest);

                cmdlet.GetAzureRuntimesProcess(string.Empty, manifest);

                List<CloudRuntimePackage> actual = mockCommandRuntime.OutputPipeline[0] as List<CloudRuntimePackage>;

                Assert.AreEqual<int>(runtimes.Count, actual.Count);
                Assert.IsTrue(runtimes.All<CloudRuntimePackage>(p => actual.Any<CloudRuntimePackage>(p2 => p2.PackageUri.Equals(p.PackageUri))));
            }
        }
        public void SanitizeServiceNameForStorageAccountName()
        {
            // Create a temp directory that we'll use to "publish" our service
            using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true })
            {
                // Import our default publish settings
                files.CreateAzureSdkDirectoryAndImportPublishSettings();

                string serviceName = null;
                ServiceSettings settings = ServiceSettings.LoadDefault(null, null, null, null, null, "My-Custom-Service!", null, out serviceName);
                Assert.AreEqual("myx2dcustomx2dservicex21", settings.StorageAccountName);

                settings = ServiceSettings.LoadDefault(null, null, null, null, null, "MyCustomServiceIsWayTooooooooooooooooooooooooLong", null, out serviceName);
                Assert.AreEqual("mycustomserviceiswaytooo", settings.StorageAccountName);
            }
        }
        public void AddAzureNodeWorkerRoleProcess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WorkerRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime };
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreateNode, rootPath, roleName);

                addNodeWorkerCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(rootPath, roleName), Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole));
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);
            }
        }
        public void SetAzureVMSizeProcessTestsCaseInsensitiveVMSizeSize()
        {
            string newRoleVMSize = "ExTraLaRge";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                string roleName = "WebRole1";
                service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new AzureService(service.Paths.RootPath, null);

                Assert.AreEqual<string>(newRoleVMSize.ToLower(), service.Components.Definition.WebRole[0].vmsize.ToString().ToLower());
                Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.AreEqual<string>(roleName, roleSettings.name);

            }
        }
 public void TestSetAzureRuntimeInvalidRuntimeType()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         AzureService service = new AzureService(files.RootPath, serviceName, null);
         string roleName = "WebRole1";
         service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
         RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "noide", "0.8.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
         RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnoide", "0.9.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
         VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "node", "*");
         VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "*");
         Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString());
         Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[1]).Members[Parameters.RoleName].Value.ToString());
         Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName));
         Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[1]).TypeNames.Contains(typeof(RoleSettings).FullName));
         Assert.AreEqual<string>(roleName, roleSettings1.name);
         Assert.AreEqual<string>(roleName, roleSettings2.name);
     }
 }
Example #21
0
        public void CreateLocalPackageWithOneNodeWebRoleTest()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string standardOutput;
                string standardError;
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                RoleInfo webRoleInfo = service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
                string logsDir = Path.Combine(service.Paths.RootPath, webRoleInfo.Name, "server.js.logs");
                string logFile = Path.Combine(logsDir, "0.txt");
                string targetLogsFile = Path.Combine(service.Paths.LocalPackage, "roles", webRoleInfo.Name, @"approot\server.js.logs\0.txt");
                files.CreateDirectory(logsDir);
                files.CreateEmptyFile(logFile);
                service.CreatePackage(DevEnv.Local, out standardOutput, out standardError);

                AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WebRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WebRole));
                Assert.IsTrue(File.Exists(targetLogsFile));
            }
        }
        public void SetAzureInstancesProcessTestsCaseInsensitive()
        {
            int newRoleInstances = 10;

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                string roleName = "WebRole1";
                service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WeBrolE1", newRoleInstances, service.Paths.RootPath);
                service = new AzureService(service.Paths.RootPath, null);

                Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count);
                Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count);
                Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.AreEqual<int>(newRoleInstances, roleSettings.Instances.count);
                Assert.AreEqual<string>(roleName, roleSettings.name);

            }
        }
        public void EnableAzureMemcacheRoleProcess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "WorkerRole";
                string webRoleName = "WebRole";
                string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.CacheRuntimeVersion = "1.8.0";
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);

                AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
            }
        }
Example #24
0
        public void ParseTests()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string path = files.CreateEmptyFile("Scaffold.xml");
                File.WriteAllText(path, Properties.Resources.ValidScaffoldXml);

                Scaffold scaffold = Scaffold.Parse(path);

                Assert.AreEqual(scaffold.Files.Count, 6);
                Assert.AreEqual(scaffold.Files[0].PathExpression, "modules\\.*");
                Assert.AreEqual(scaffold.Files[1].Path, @"bin/node123dfx65.exe");
                Assert.AreEqual(scaffold.Files[1].TargetPath, @"/bin/node.exe");
                Assert.AreEqual(scaffold.Files[2].Path, @"bin/iisnode.dll");
                Assert.AreEqual(scaffold.Files[3].Path, @"bin/setup.cmd");
                Assert.AreEqual(scaffold.Files[4].Path, "Web.config");
                Assert.AreEqual(scaffold.Files[4].Rules.Count, 1);
                Assert.AreEqual(scaffold.Files[5].Path, "WebRole.xml");
                Assert.AreEqual(scaffold.Files[5].Copy, false);
                Assert.AreEqual(scaffold.Files[5].Rules.Count, 1);
            }
        }
        public void SetDeploymentStatusProcessTest()
        {
            SimpleServiceManagement channel = new SimpleServiceManagement();
            string newStatus = DeploymentStatus.Running;
            string currentStatus = DeploymentStatus.Suspended;
            bool statusUpdated = false;
            channel.UpdateDeploymentStatusBySlotThunk = ar =>
            {
                statusUpdated = true;
                channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus);
            };
            channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, currentStatus);

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                files.CreateAzureSdkDirectoryAndImportPublishSettings();
                AzureService service = new AzureService(files.RootPath, serviceName, null);
                var startAzureService = new StartAzureService(channel) { ShareChannel = true };
                startAzureService.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName);

                Assert.IsTrue(statusUpdated);
            }
        }
        public void NewAzureServiceSuccessfull()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Setup
                string expectedName = "test";
                string expectedRootPath = Path.Combine(files.RootPath, expectedName);
                string expectedServiceCreatedMessage = string.Format(Resources.NewServiceCreatedMessage, expectedRootPath);
                cmdlet.ServiceName = expectedName;

                // Test
                cmdlet.NewAzureServiceProcess(files.RootPath, expectedName);

                // Assert
                PSObject actualPSObject = mockCommandRuntime.OutputPipeline[0] as PSObject;
                string actualServiceCreatedMessage = mockCommandRuntime.VerboseStream[0];

                Assert.AreEqual<string>(expectedName, actualPSObject.Members[Parameters.ServiceName].Value.ToString());
                Assert.AreEqual<string>(expectedRootPath, actualPSObject.Members[Parameters.RootPath].Value.ToString());
                Assert.AreEqual<string>(expectedServiceCreatedMessage, actualServiceCreatedMessage);
                AzureAssert.AzureServiceExists(expectedRootPath, Resources.GeneralScaffolding, expectedName);
            }
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            foreach (KeyValuePair<Location, string> item in Microsoft.WindowsAzure.Management.CloudService.Model.ArgumentConstants.Locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    mockCommandRuntime = new MockCommandRuntime();
                    setServiceProjectCmdlet.CommandRuntime = mockCommandRuntime;
                    settings.Save(paths.Settings);

                    settings = setServiceProjectCmdlet.SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    Assert.AreEqual<string>(item.Value, settings.Location);
                    ServiceSettings actualOutput = mockCommandRuntime.OutputPipeline[0] as ServiceSettings;
                    Assert.AreEqual<string>(item.Value, settings.Location);
                }
            }
        }
        public void AddAzureWebRoleWithMissingScaffoldXmlFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WebRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreate, rootPath, roleName);
                string originalDirectory = Directory.GetCurrentDirectory();
                string scaffoldingPath = "TemplateMissingScaffoldXml";
                addWebCmdlet = new AddAzureWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = roleName, TemplateFolder = scaffoldingPath };

                Testing.AssertThrows<FileNotFoundException>(() => addWebCmdlet.ExecuteCmdlet());
            }
        }
        public void EnableAzureMemcacheRoleProcessAlreadyEnabledFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "WorkerRole";
                string webRoleName = "WebRole";
                string expected = string.Format(Resources.CacheAlreadyEnabledMessage, webRoleName);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);

                Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
            }
        }
        public void AddAzureWebRoleWithTemplateFolder()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string roleName = "WebRole1";
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string expectedVerboseMessage = string.Format(Resources.AddRoleMessageCreate, rootPath, roleName);
                string originalDirectory = Directory.GetCurrentDirectory();
                string scaffoldingPath = "MyWebTemplateFolder";
                Directory.SetCurrentDirectory(rootPath);
                addWebCmdlet = new AddAzureWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = roleName, TemplateFolder = scaffoldingPath };

                addWebCmdlet.ExecuteCmdlet();

                AzureAssert.ScaffoldingExists(Path.Combine(rootPath, roleName), scaffoldingPath);
                Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).GetVariableValue<string>(Parameters.RoleName));
                Assert.AreEqual<string>(expectedVerboseMessage, mockCommandRuntime.VerboseStream[0]);

                Directory.SetCurrentDirectory(originalDirectory);
            }
        }