예제 #1
0
        private void StartEmulatorCommonTest(ComputeEmulatorMode mode)
        {
            // Setup
            string testEmulatorFolder = @"C:\sample-path";
            string testPackagePath = @"c:\sample-path\local_package.csx";
            string testConfigPath = @"c:\sample-path\ServiceConfiguration.Local.cscfg";
            string expectedCsrunCommand = testEmulatorFolder + @"\" + Resources.CsRunExe;
            string expectedComputeArguments = Resources.CsRunStartComputeEmulatorArg;
            string expectedRemoveAllDeploymentsArgument = Resources.CsRunRemoveAllDeploymentsArg;
            string expectedAzureProjectArgument = string.Format("/run:\"{0}\";\"{1}\" {2} /useiisexpress",
                testPackagePath, testConfigPath, Resources.CsRunLanuchBrowserArg);
            if (mode== ComputeEmulatorMode.Full)
            {
                expectedComputeArguments += " " + Resources.CsRunFullEmulatorArg;
                expectedAzureProjectArgument += " " + Resources.CsRunFullEmulatorArg;
            }

            string testRoleUrl = "http://127.0.0.1:8080/";
            int testDeploymentId = 58;
            string testOutput = string.Format("Started: deployment23({0}) Role is running at " + testRoleUrl + ".", testDeploymentId.ToString());
            string expectedRoleRunningMessage = string.Format(Resources.EmulatorRoleRunningMessage, testRoleUrl) + System.Environment.NewLine; 

            CsRun csRun = new CsRun(testEmulatorFolder);
            Mock<ProcessHelper> commandRunner = new Mock<ProcessHelper>();
            commandRunner.Setup(p => p.StartAndWaitForProcess(expectedCsrunCommand, expectedComputeArguments));
            commandRunner.Setup(p => p.StartAndWaitForProcess(expectedCsrunCommand, expectedRemoveAllDeploymentsArgument));
            commandRunner.Setup(p => p.StartAndWaitForProcess(expectedCsrunCommand, expectedAzureProjectArgument))
                .Callback(() => { commandRunner.Object.StandardOutput = testOutput; });

            // Execute
            csRun.CommandRunner = commandRunner.Object;
            
            csRun.StartEmulator(testPackagePath, testConfigPath, true, mode);

            // Assert
            commandRunner.VerifyAll();
            Assert.Equal(csRun.DeploymentId, testDeploymentId);
            Assert.Equal(csRun.RoleInformation, expectedRoleRunningMessage);
        }
        public void StopEmulators(out string warning)
        {
            var runTool = new CsRun(AzureTool.GetComputeEmulatorDirectory());
            runTool.StopComputeEmulator();

            var storageEmulator = new StorageEmulator(AzureTool.GetStorageEmulatorDirectory());
            storageEmulator.Stop();
            //for now, errors related with storage emulator are treated as non-fatal
            warning = storageEmulator.Error;
        }
        /// <summary>
        /// Starts azure emulator for this service.
        /// </summary>
        /// <remarks>This methods removes all deployments already in the emulator.</remarks>
        /// <param name="launchBrowser">Switch to control opening a browser for web roles.</param>
        /// <param name="mode"></param>
        /// <param name="roleInformation"></param>
        /// <param name="warning"></param>
        public void StartEmulators(bool launchBrowser, ComputeEmulatorMode mode , out string roleInformation, out string warning)
        {
            var runTool = new CsRun(AzureTool.GetComputeEmulatorDirectory());
            runTool.StartEmulator(Paths.LocalPackage, Paths.LocalConfiguration, launchBrowser, mode);

            roleInformation = runTool.RoleInformation;

            var storageEmulator = new StorageEmulator(AzureTool.GetStorageEmulatorDirectory());
            storageEmulator.Start();

            //for now, errors related with storage emulator are treated as non-fatal
            warning = storageEmulator.Error;
        }