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

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

                AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
            }
        }
        public void EnableAzureMemcacheRoleProcessUsingNonCacheWorkerRole()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string workerRoleName = "WorkerRole";
                string webRoleName = "WebRole";
                string expected = string.Format(Resources.NotCacheWorkerRole, workerRoleName);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName };
                addNodeWorkerCmdlet.ExecuteCmdlet();

                Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, workerRoleName, rootPath));
            }
        }
        public void EnableAzureMemcacheWithNoCacheWorkerRolesFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string webRoleName = "WebRole";
                string expectedMessage = string.Format(Resources.NoCacheWorkerRoles);

                addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
                addNodeWebCmdlet.ExecuteCmdlet();
                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.CacheRuntimeVersion = "1.8.0";

                Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, null, rootPath), expectedMessage);
            }
        }
        public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string serviceName = "AzureService";
                string rootPath = files.CreateNewService(serviceName);
                string cacheRoleName = "CacheWorkerRole";
                string workerRoleName = "WorkerRole";
                string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort);

                addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName };
                addNodeWorkerCmdlet.ExecuteCmdlet();
                addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
                mockCommandRuntime.ResetPipelines();
                enableCacheCmdlet.PassThru = true;
                enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath);

                WorkerRole workerRole = CloudServiceTesting.GetWorkerRole(rootPath, workerRoleName);

                AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue);

                AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole));
                AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand);

                AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint,
                    new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort });

                LocalStore localStore = new LocalStore
                {
                    name = Resources.CacheDiagnosticStoreName,
                    cleanOnRoleRecycle = false
                };

                AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources);

                DefConfigurationSetting diagnosticLevel = new DefConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName };
                AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings);

                ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, CloudServiceTesting.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings);
                AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, CloudServiceTesting.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings);

                string workerConfigPath = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config");
                string workerCloudConfig = File.ReadAllText(workerConfigPath);
                Assert.IsTrue(workerCloudConfig.Contains("configSections"));
                Assert.IsTrue(workerCloudConfig.Contains("dataCacheClients"));

                Assert.AreEqual<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
                Assert.AreEqual<string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName));
            }
        }