PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ServiceManagement/Services/Commands.Test/CloudService/Development/EnableAzureMemcacheRoleTests.cs

https://gitlab.com/jslee1/azure-powershell
C# | 441 lines | 338 code | 69 blank | 34 comment | 0 complexity | 07bbec7baab1165281d93ab46d0e37c8 MD5 | raw file
  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. using System;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Management.Automation;
  18. using Microsoft.WindowsAzure.Commands.CloudService.Development;
  19. using Microsoft.WindowsAzure.Commands.CloudService.Development.Scaffolding;
  20. using Microsoft.WindowsAzure.Commands.Common;
  21. using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
  22. using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
  23. using Microsoft.WindowsAzure.Commands.Utilities.CloudService;
  24. using Microsoft.WindowsAzure.Commands.Utilities.CloudService.AzureTools;
  25. using Microsoft.WindowsAzure.Commands.Utilities.Common;
  26. using Microsoft.WindowsAzure.Commands.Utilities.Common.XmlSchema.ServiceConfigurationSchema;
  27. using Microsoft.WindowsAzure.Commands.Utilities.Common.XmlSchema.ServiceDefinitionSchema;
  28. using Microsoft.WindowsAzure.Commands.Utilities.Properties;
  29. using Microsoft.WindowsAzure.Commands.ScenarioTest;
  30. using Xunit;
  31. namespace Microsoft.WindowsAzure.Commands.Test.CloudService.Development.Tests
  32. {
  33. using ConfigConfigurationSetting = Commands.Utilities.Common.XmlSchema.ServiceConfigurationSchema.ConfigurationSetting;
  34. using DefinitionConfigurationSetting = Commands.Utilities.Common.XmlSchema.ServiceDefinitionSchema.ConfigurationSetting;
  35. using TestResources = Commands.Common.Test.Properties.Resources;
  36. using Microsoft.Azure.Common.Authentication;
  37. public class EnableAzureMemcacheRoleTests : TestBase
  38. {
  39. private MockCommandRuntime mockCommandRuntime;
  40. private AddAzureNodeWebRoleCommand addNodeWebCmdlet;
  41. private AddAzureNodeWorkerRoleCommand addNodeWorkerCmdlet;
  42. private AddAzureCacheWorkerRoleCommand addCacheRoleCmdlet;
  43. private EnableAzureMemcacheRoleCommand enableCacheCmdlet;
  44. public EnableAzureMemcacheRoleTests()
  45. {
  46. AzureTool.IgnoreMissingSDKError = true;
  47. AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir;
  48. mockCommandRuntime = new MockCommandRuntime();
  49. enableCacheCmdlet = new EnableAzureMemcacheRoleCommand();
  50. addCacheRoleCmdlet = new AddAzureCacheWorkerRoleCommand();
  51. addCacheRoleCmdlet.CommandRuntime = mockCommandRuntime;
  52. enableCacheCmdlet.CommandRuntime = mockCommandRuntime;
  53. }
  54. [Fact]
  55. [Trait(Category.AcceptanceType, Category.CheckIn)]
  56. public void EnableAzureMemcacheRoleProcess()
  57. {
  58. using (FileSystemHelper files = new FileSystemHelper(this))
  59. {
  60. string serviceName = "AzureService";
  61. string rootPath = files.CreateNewService(serviceName);
  62. string cacheRoleName = "WorkerRole";
  63. string webRoleName = "WebRole";
  64. string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);
  65. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  66. addNodeWebCmdlet.ExecuteCmdlet();
  67. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  68. mockCommandRuntime.ResetPipelines();
  69. enableCacheCmdlet.PassThru = true;
  70. enableCacheCmdlet.CacheRuntimeVersion = "2.5.0";
  71. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);
  72. AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
  73. }
  74. }
  75. /// <summary>
  76. /// Verify that enabling cache on worker role will pass.
  77. /// </summary>
  78. [Fact]
  79. [Trait(Category.AcceptanceType, Category.CheckIn)]
  80. public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess()
  81. {
  82. using (FileSystemHelper files = new FileSystemHelper(this))
  83. {
  84. string serviceName = "AzureService";
  85. string rootPath = files.CreateNewService(serviceName);
  86. string cacheRoleName = "CacheWorkerRole";
  87. string workerRoleName = "WorkerRole";
  88. string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort);
  89. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName };
  90. addNodeWorkerCmdlet.ExecuteCmdlet();
  91. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  92. mockCommandRuntime.ResetPipelines();
  93. enableCacheCmdlet.PassThru = true;
  94. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath);
  95. WorkerRole workerRole = AzureAssert.GetWorkerRole(rootPath, workerRoleName);
  96. AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue);
  97. AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole));
  98. AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand);
  99. AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint,
  100. new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort });
  101. LocalStore localStore = new LocalStore
  102. {
  103. name = Resources.CacheDiagnosticStoreName,
  104. cleanOnRoleRecycle = false
  105. };
  106. AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources);
  107. DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName };
  108. AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings);
  109. ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
  110. AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings);
  111. AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, AzureAssert.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings);
  112. string workerConfigPath = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config");
  113. string workerCloudConfig = File.ReadAllText(workerConfigPath);
  114. Assert.True(workerCloudConfig.Contains("configSections"));
  115. Assert.True(workerCloudConfig.Contains("dataCacheClients"));
  116. Assert.Equal<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
  117. Assert.Equal<string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName));
  118. }
  119. }
  120. /// <summary>
  121. /// Verify that enabling cache with non-existing cache worker role will fail.
  122. /// </summary>
  123. [Fact]
  124. [Trait(Category.AcceptanceType, Category.CheckIn)]
  125. public void EnableAzureMemcacheRoleProcessCacheRoleDoesNotExistFail()
  126. {
  127. using (FileSystemHelper files = new FileSystemHelper(this))
  128. {
  129. string serviceName = "AzureService";
  130. string rootPath = files.CreateNewService(serviceName);
  131. string cacheRoleName = "WorkerRole";
  132. string webRoleName = "WebRole";
  133. string expected = string.Format(Resources.RoleNotFoundMessage, cacheRoleName);
  134. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  135. addNodeWebCmdlet.ExecuteCmdlet();
  136. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
  137. }
  138. }
  139. /// <summary>
  140. /// Verify that enabling cache with non-existing role to enable on will fail.
  141. /// </summary>
  142. [Fact]
  143. [Trait(Category.AcceptanceType, Category.CheckIn)]
  144. public void EnableAzureMemcacheRoleProcessRoleDoesNotExistFail()
  145. {
  146. using (FileSystemHelper files = new FileSystemHelper(this))
  147. {
  148. string serviceName = "AzureService";
  149. string rootPath = files.CreateNewService(serviceName);
  150. string cacheRoleName = "WorkerRole";
  151. string webRoleName = "WebRole";
  152. string expected = string.Format(Resources.RoleNotFoundMessage, webRoleName);
  153. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  154. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
  155. }
  156. }
  157. /// <summary>
  158. /// Verify that enabling cache using same cache worker role on role with cache will fail.
  159. /// </summary>
  160. [Fact]
  161. [Trait(Category.AcceptanceType, Category.CheckIn)]
  162. public void EnableAzureMemcacheRoleProcessAlreadyEnabledFail()
  163. {
  164. using (FileSystemHelper files = new FileSystemHelper(this))
  165. {
  166. string serviceName = "AzureService";
  167. string rootPath = files.CreateNewService(serviceName);
  168. string cacheRoleName = "WorkerRole";
  169. string webRoleName = "WebRole";
  170. string expected = string.Format(Resources.CacheAlreadyEnabledMessage, webRoleName);
  171. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  172. addNodeWebCmdlet.ExecuteCmdlet();
  173. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  174. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);
  175. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
  176. }
  177. }
  178. /// <summary>
  179. /// Verify that enabling cache using different cache worker role on role with cache will fail.
  180. /// </summary>
  181. [Fact]
  182. [Trait(Category.AcceptanceType, Category.CheckIn)]
  183. public void EnableAzureMemcacheRoleProcessAlreadyEnabledNewCacheRoleFail()
  184. {
  185. using (FileSystemHelper files = new FileSystemHelper(this))
  186. {
  187. string serviceName = "AzureService";
  188. string rootPath = files.CreateNewService(serviceName);
  189. string cacheRoleName = "WorkerRole";
  190. string newCacheRoleName = "NewCacheWorkerRole";
  191. string webRoleName = "WebRole";
  192. string expected = string.Format(Resources.CacheAlreadyEnabledMessage, webRoleName);
  193. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  194. addNodeWebCmdlet.ExecuteCmdlet();
  195. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  196. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath);
  197. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(newCacheRoleName, 1, rootPath);
  198. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, cacheRoleName, rootPath));
  199. }
  200. }
  201. /// <summary>
  202. /// Verify that enabling cache using non-cache worker role will fail.
  203. /// </summary>
  204. [Fact]
  205. [Trait(Category.AcceptanceType, Category.CheckIn)]
  206. public void EnableAzureMemcacheRoleProcessUsingNonCacheWorkerRole()
  207. {
  208. using (FileSystemHelper files = new FileSystemHelper(this))
  209. {
  210. string serviceName = "AzureService";
  211. string rootPath = files.CreateNewService(serviceName);
  212. string workerRoleName = "WorkerRole";
  213. string webRoleName = "WebRole";
  214. string expected = string.Format(Resources.NotCacheWorkerRole, workerRoleName);
  215. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  216. addNodeWebCmdlet.ExecuteCmdlet();
  217. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName };
  218. addNodeWorkerCmdlet.ExecuteCmdlet();
  219. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, workerRoleName, rootPath));
  220. }
  221. }
  222. [Fact]
  223. [Trait(Category.AcceptanceType, Category.CheckIn)]
  224. public void EnableAzureMemcacheRoleProcessWithDefaultRoleName()
  225. {
  226. using (FileSystemHelper files = new FileSystemHelper(this))
  227. {
  228. string originalDirectory = Directory.GetCurrentDirectory();
  229. string serviceName = "AzureService";
  230. string rootPath = files.CreateNewService(serviceName);
  231. string webRoleName = "WebRole";
  232. string cacheRoleName = "WorkerRole";
  233. string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);
  234. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  235. addNodeWebCmdlet.ExecuteCmdlet();
  236. Directory.SetCurrentDirectory(Path.Combine(rootPath, webRoleName));
  237. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  238. mockCommandRuntime.ResetPipelines();
  239. enableCacheCmdlet.PassThru = true;
  240. enableCacheCmdlet.CacheRuntimeVersion = "2.5.0";
  241. enableCacheCmdlet.RoleName = string.Empty;
  242. enableCacheCmdlet.CacheWorkerRoleName = cacheRoleName;
  243. enableCacheCmdlet.ExecuteCmdlet();
  244. AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
  245. Directory.SetCurrentDirectory(originalDirectory);
  246. }
  247. }
  248. private void AssertCachingEnabled(
  249. FileSystemHelper files,
  250. string serviceName,
  251. string rootPath,
  252. string webRoleName,
  253. string expectedMessage)
  254. {
  255. WebRole webRole = AzureAssert.GetWebRole(rootPath, webRoleName);
  256. RoleSettings roleSettings = AzureAssert.GetCloudRole(rootPath, webRoleName);
  257. AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue);
  258. Assert.Equal<string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name);
  259. Assert.Equal<string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value);
  260. Assert.Equal<string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name);
  261. Assert.Equal<string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath);
  262. Assert.Equal<string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name);
  263. Assert.Equal<string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value);
  264. Assert.Equal(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand)));
  265. AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole));
  266. AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand);
  267. AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint,
  268. new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort });
  269. LocalStore localStore = new LocalStore
  270. {
  271. name = Resources.CacheDiagnosticStoreName,
  272. cleanOnRoleRecycle = false
  273. };
  274. AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources);
  275. DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName };
  276. AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings);
  277. ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
  278. AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings);
  279. AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig));
  280. AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName));
  281. Assert.Equal<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
  282. Assert.Equal<string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName));
  283. }
  284. private static void AssertWebConfig(string webCloudConfigPath)
  285. {
  286. string webCloudCloudConfigContents = FileUtilities.DataStore.ReadFileAsText(webCloudConfigPath);
  287. Assert.True(webCloudCloudConfigContents.Contains("configSections"));
  288. Assert.True(webCloudCloudConfigContents.Contains("dataCacheClients"));
  289. }
  290. /// <summary>
  291. /// Verify that enabling cache with non-existing cache worker role will fail.
  292. /// </summary>
  293. [Fact]
  294. [Trait(Category.AcceptanceType, Category.CheckIn)]
  295. public void EnableAzureMemcacheRoleProcessOnCacheWorkerRoleFail()
  296. {
  297. using (FileSystemHelper files = new FileSystemHelper(this))
  298. {
  299. string serviceName = "AzureService";
  300. string rootPath = files.CreateNewService(serviceName);
  301. string cacheRoleName = "WorkerRole";
  302. string expected = string.Format(Resources.InvalidCacheRoleName, cacheRoleName);
  303. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  304. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(cacheRoleName, cacheRoleName, rootPath));
  305. }
  306. }
  307. [Fact]
  308. [Trait(Category.AcceptanceType, Category.CheckIn)]
  309. public void EnableAzureMemcacheWithoutCacheWorkerRoleName()
  310. {
  311. using (FileSystemHelper files = new FileSystemHelper(this))
  312. {
  313. string serviceName = "AzureService";
  314. string rootPath = files.CreateNewService(serviceName);
  315. string cacheRoleName = "WorkerRole";
  316. string webRoleName = "WebRole";
  317. string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);
  318. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  319. addNodeWebCmdlet.ExecuteCmdlet();
  320. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  321. mockCommandRuntime.ResetPipelines();
  322. enableCacheCmdlet.PassThru = true;
  323. enableCacheCmdlet.CacheRuntimeVersion = "2.5.0";
  324. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, null, rootPath);
  325. AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
  326. }
  327. }
  328. [Fact]
  329. [Trait(Category.AcceptanceType, Category.CheckIn)]
  330. public void EnableAzureMemcacheWithoutCacheWorkerRoleNameAndServiceHasMultipleWorkerRoles()
  331. {
  332. using (FileSystemHelper files = new FileSystemHelper(this))
  333. {
  334. string serviceName = "AzureService";
  335. string rootPath = files.CreateNewService(serviceName);
  336. string cacheRoleName = "CacheWorkerRole";
  337. string webRoleName = "WebRole";
  338. string expectedMessage = string.Format(Resources.EnableMemcacheMessage, webRoleName, cacheRoleName, Resources.MemcacheEndpointPort);
  339. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  340. addNodeWebCmdlet.ExecuteCmdlet();
  341. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
  342. addNodeWorkerCmdlet.ExecuteCmdlet();
  343. addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
  344. mockCommandRuntime.ResetPipelines();
  345. enableCacheCmdlet.PassThru = true;
  346. enableCacheCmdlet.CacheRuntimeVersion = "2.5.0";
  347. enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, null, rootPath);
  348. AssertCachingEnabled(files, serviceName, rootPath, webRoleName, expectedMessage);
  349. }
  350. }
  351. [Fact]
  352. [Trait(Category.AcceptanceType, Category.CheckIn)]
  353. public void EnableAzureMemcacheWithNoCacheWorkerRolesFail()
  354. {
  355. using (FileSystemHelper files = new FileSystemHelper(this))
  356. {
  357. string serviceName = "AzureService";
  358. string rootPath = files.CreateNewService(serviceName);
  359. string webRoleName = "WebRole";
  360. string expectedMessage = string.Format(Resources.NoCacheWorkerRoles);
  361. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRoleName };
  362. addNodeWebCmdlet.ExecuteCmdlet();
  363. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" };
  364. addNodeWorkerCmdlet.ExecuteCmdlet();
  365. mockCommandRuntime.ResetPipelines();
  366. enableCacheCmdlet.PassThru = true;
  367. enableCacheCmdlet.CacheRuntimeVersion = "2.5.0";
  368. Testing.AssertThrows<Exception>(() => enableCacheCmdlet.EnableAzureMemcacheRoleProcess(webRoleName, null, rootPath), expectedMessage);
  369. }
  370. }
  371. }
  372. }