Пример #1
0
        public void UpdateWebRoleServiceDefinitionTest()
        {
            var doc = new XmlDocument();

            doc.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<ServiceDefinition name=""Azure1"" xmlns=""http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"" schemaVersion=""2014-01.2.3"">
  <WorkerRole name=""WorkerProject"" vmsize=""Small"" />
  <WebRole name=""WebProject"" />
</ServiceDefinition>");

            NodejsProject.UpdateServiceDefinition(doc, "Web", "WebProject");

            AreEqual(@"<?xml version=""1.0"" encoding=""utf-8""?>
<ServiceDefinition name=""Azure1"" xmlns=""http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"" schemaVersion=""2014-01.2.3"">
  <WorkerRole name=""WorkerProject"" vmsize=""Small"" />
  <WebRole name=""WebProject"">
    <Startup>
      <Task commandLine=""setup_web.cmd &gt; log.txt"" executionContext=""elevated"" taskType=""simple"">
        <Environment>
          <Variable name=""EMULATED"">
            <RoleInstanceValue xpath=""/RoleEnvironment/Deployment/@emulated"" />
          </Variable>
          <Variable name=""RUNTIMEID"" value=""node"" />
          <Variable name=""RUNTIMEURL"" value=""http://az413943.vo.msecnd.net/node/0.10.21.exe;http://nodertncu.blob.core.windows.net/iisnode/0.1.21.exe"" />
        </Environment>
      </Task>
    </Startup>
  </WebRole>
</ServiceDefinition>", doc);
        }
Пример #2
0
        private static void CloudProjectTest(string roleType, bool openServiceDefinition)
        {
            Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType);

            using (var app = new VisualStudioApp())
                using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef")))
                {
                    app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3);

                    var ccproj = app.Dte.Solution.Projects.Cast <EnvDTE.Project>().FirstOrDefault(p => p.Name == "CloudProject");
                    Assert.IsNotNull(ccproj);

                    if (openServiceDefinition)
                    {
                        var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open();
                        wnd.Activate();
                        app.OnDispose(() => wnd.Close());
                    }

                    IVsHierarchy hier;
                    var          sln = app.GetService <IVsSolution>(typeof(SVsSolution));
                    ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier));

                    app.ServiceProvider.GetUIThread().Invoke(() =>
                                                             NodejsProject.UpdateServiceDefinition(
                                                                 hier,
                                                                 roleType,
                                                                 roleType + "Role1",
                                                                 new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)app.Dte)
                                                                 )
                                                             );

                    var doc = new XmlDocument();
                    for (int retries = 5; retries > 0; --retries)
                    {
                        try
                        {
                            doc.Load(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"));
                            break;
                        }
                        catch (IOException ex)
                        {
                            Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex);
                        }
                        catch (XmlException)
                        {
                            var copyTo = TestData.GetPath(@"TestData\CloudProject\CloudProject\" + Path.GetRandomFileName());
                            File.Copy(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"), copyTo);
                            Console.WriteLine("Copied file to " + copyTo);
                            throw;
                        }
                        Thread.Sleep(100);
                    }
                    var ns = new XmlNamespaceManager(doc.NameTable);
                    ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition");
                    doc.Save(Console.Out);

                    var nav = doc.CreateNavigator();
                    if (roleType == "Web")
                    {
                        Assert.IsNotNull(nav.SelectSingleNode(
                                             "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='setup_web.cmd > log.txt']",
                                             ns
                                             ));
                    }
                    else if (roleType == "Worker")
                    {
                        Assert.IsNotNull(nav.SelectSingleNode(
                                             "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='setup_worker.cmd > log.txt']",
                                             ns
                                             ));
                        Assert.IsNotNull(nav.SelectSingleNode(
                                             "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='node.cmd .\\server.js']",
                                             ns
                                             ));
                    }
                }
        }