PageRenderTime 31ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/src/ServiceManagement/Services/Commands.Test/CloudService/Utilities/AzureServiceTests.cs

https://gitlab.com/jslee1/azure-powershell
C# | 631 lines | 524 code | 75 blank | 32 comment | 43 complexity | 0d5dc14bc08ca707e62de68ced725a7f 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 Microsoft.WindowsAzure.Commands.ScenarioTest;
  18. using Xunit;
  19. using Microsoft.WindowsAzure.Commands.CloudService.Development;
  20. using Microsoft.WindowsAzure.Commands.CloudService.Development.Scaffolding;
  21. using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
  22. using Microsoft.WindowsAzure.Commands.Test.Utilities.CloudService;
  23. using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
  24. using Microsoft.WindowsAzure.Commands.Utilities.CloudService;
  25. using Microsoft.WindowsAzure.Commands.Utilities.CloudService.AzureTools;
  26. using Microsoft.WindowsAzure.Commands.Utilities.Common;
  27. using Microsoft.WindowsAzure.Commands.Utilities.Properties;
  28. using Microsoft.WindowsAzure.Commands.Common;
  29. using Microsoft.Azure.Commands.Common.Authentication;
  30. namespace Microsoft.WindowsAzure.Commands.Test.CloudService.Utilities
  31. {
  32. public class AzureServiceTests: SMTestBase
  33. {
  34. private const string serviceName = "AzureService";
  35. private MockCommandRuntime mockCommandRuntime;
  36. private AddAzureNodeWebRoleCommand addNodeWebCmdlet;
  37. private AddAzureNodeWorkerRoleCommand addNodeWorkerCmdlet;
  38. /// <summary>
  39. /// This method handles most possible cases that user can do to create role
  40. /// </summary>
  41. /// <param name="webRole">Count of web roles to add</param>
  42. /// <param name="workerRole">Count of worker role to add</param>
  43. /// <param name="addWebBeforeWorker">Decides in what order to add roles. There are three options, note that value between brackets is the value to pass:
  44. /// 1. Web then, interleaving (0): interleave adding and start by adding web role first.
  45. /// 2. Worker then, interleaving (1): interleave adding and start by adding worker role first.
  46. /// 3. Web then worker (2): add all web roles then worker roles.
  47. /// 4. Worker then web (3): add all worker roles then web roles.
  48. /// By default this parameter is set to 0
  49. /// </param>
  50. private void AddNodeRoleTest(int webRole, int workerRole, int order = 0)
  51. {
  52. using (FileSystemHelper files = new FileSystemHelper(this))
  53. {
  54. AzureServiceWrapper wrappedService = new AzureServiceWrapper(files.RootPath, serviceName, null);
  55. CloudServiceProject service = new CloudServiceProject(Path.Combine(files.RootPath, serviceName), null);
  56. WebRoleInfo[] webRoles = null;
  57. if (webRole > 0)
  58. {
  59. webRoles = new WebRoleInfo[webRole];
  60. for (int i = 0; i < webRoles.Length; i++)
  61. {
  62. webRoles[i] = new WebRoleInfo(string.Format("{0}{1}", Resources.WebRole, i + 1), 1);
  63. }
  64. }
  65. WorkerRoleInfo[] workerRoles = null;
  66. if (workerRole > 0)
  67. {
  68. workerRoles = new WorkerRoleInfo[workerRole];
  69. for (int i = 0; i < workerRoles.Length; i++)
  70. {
  71. workerRoles[i] = new WorkerRoleInfo(string.Format("{0}{1}", Resources.WorkerRole, i + 1), 1);
  72. }
  73. }
  74. RoleInfo[] roles = (webRole + workerRole > 0) ? new RoleInfo[webRole + workerRole] : null;
  75. if (order == 0)
  76. {
  77. for (int i = 0, w = 0, wo = 0; i < webRole + workerRole; )
  78. {
  79. if (w++ < webRole) roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
  80. if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath);
  81. }
  82. }
  83. else if (order == 1)
  84. {
  85. for (int i = 0, w = 0, wo = 0; i < webRole + workerRole; )
  86. {
  87. if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath);
  88. if (w++ < webRole) roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
  89. }
  90. }
  91. else if (order == 2)
  92. {
  93. wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, webRole, workerRole);
  94. webRoles.CopyTo(roles, 0);
  95. Array.Copy(workerRoles, 0, roles, webRole, workerRoles.Length);
  96. }
  97. else if (order == 3)
  98. {
  99. wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, 0, workerRole);
  100. workerRoles.CopyTo(roles, 0);
  101. wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, webRole, 0);
  102. Array.Copy(webRoles, 0, roles, workerRole, webRoles.Length);
  103. }
  104. else
  105. {
  106. throw new ArgumentException("value for order parameter is unknown");
  107. }
  108. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, webRoles: webRoles, workerRoles: workerRoles, webScaff: Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, workerScaff: Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, roles: roles);
  109. }
  110. }
  111. private void AddPHPRoleTest(int webRole, int workerRole, int order = 0)
  112. {
  113. using (FileSystemHelper files = new FileSystemHelper(this))
  114. {
  115. AzureServiceWrapper wrappedService = new AzureServiceWrapper(files.RootPath, serviceName, null);
  116. CloudServiceProject service = new CloudServiceProject(Path.Combine(files.RootPath, serviceName), null);
  117. WebRoleInfo[] webRoles = null;
  118. if (webRole > 0)
  119. {
  120. webRoles = new WebRoleInfo[webRole];
  121. for (int i = 0; i < webRoles.Length; i++)
  122. {
  123. webRoles[i] = new WebRoleInfo(string.Format("{0}{1}", Resources.WebRole, i + 1), 1);
  124. }
  125. }
  126. WorkerRoleInfo[] workerRoles = null;
  127. if (workerRole > 0)
  128. {
  129. workerRoles = new WorkerRoleInfo[workerRole];
  130. for (int i = 0; i < workerRoles.Length; i++)
  131. {
  132. workerRoles[i] = new WorkerRoleInfo(string.Format("{0}{1}", Resources.WorkerRole, i + 1), 1);
  133. }
  134. }
  135. RoleInfo[] roles = (webRole + workerRole > 0) ? new RoleInfo[webRole + workerRole] : null;
  136. if (order == 0)
  137. {
  138. for (int i = 0, w = 0, wo = 0; i < webRole + workerRole; )
  139. {
  140. if (w++ < webRole) roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath);
  141. if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath);
  142. }
  143. }
  144. else if (order == 1)
  145. {
  146. for (int i = 0, w = 0, wo = 0; i < webRole + workerRole; )
  147. {
  148. if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath);
  149. if (w++ < webRole) roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath);
  150. }
  151. }
  152. else if (order == 2)
  153. {
  154. wrappedService.AddRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, webRole, workerRole);
  155. webRoles.CopyTo(roles, 0);
  156. Array.Copy(workerRoles, 0, roles, webRole, workerRoles.Length);
  157. }
  158. else if (order == 3)
  159. {
  160. wrappedService.AddRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, 0, workerRole);
  161. workerRoles.CopyTo(roles, 0);
  162. wrappedService.AddRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, webRole, 0);
  163. Array.Copy(webRoles, 0, roles, workerRole, webRoles.Length);
  164. }
  165. else
  166. {
  167. throw new ArgumentException("value for order parameter is unknown");
  168. }
  169. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, webRoles: webRoles, workerRoles: workerRoles, webScaff: Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, workerScaff: Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, roles: roles);
  170. }
  171. }
  172. public AzureServiceTests()
  173. {
  174. AzureTool.IgnoreMissingSDKError = true;
  175. AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir;
  176. mockCommandRuntime = new MockCommandRuntime();
  177. }
  178. [Fact]
  179. [Trait(Category.AcceptanceType, Category.CheckIn)]
  180. public void AzureServiceCreateNew()
  181. {
  182. using (FileSystemHelper files = new FileSystemHelper(this))
  183. {
  184. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  185. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName);
  186. }
  187. }
  188. [Fact]
  189. [Trait(Category.AcceptanceType, Category.CheckIn)]
  190. public void AzureServiceCreateNewEmptyParentDirectoryFail()
  191. {
  192. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(string.Empty, serviceName, null), string.Format(Resources.InvalidOrEmptyArgumentMessage, "service parent directory"));
  193. }
  194. [Fact]
  195. [Trait(Category.AcceptanceType, Category.CheckIn)]
  196. public void AzureServiceCreateNewNullParentDirectoryFail()
  197. {
  198. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(null, serviceName, null), string.Format(Resources.InvalidOrEmptyArgumentMessage, "service parent directory"));
  199. }
  200. [Fact]
  201. [Trait(Category.AcceptanceType, Category.CheckIn)]
  202. public void AzureServiceCreateNewInvalidParentDirectoryFail()
  203. {
  204. foreach (string invalidName in Test.Utilities.Common.Data.InvalidFileName)
  205. {
  206. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(string.Empty, serviceName, null), string.Format(Resources.InvalidOrEmptyArgumentMessage, "service parent directory"));
  207. }
  208. }
  209. [Fact]
  210. [Trait(Category.AcceptanceType, Category.CheckIn)]
  211. public void AzureServiceCreateNewDoesNotExistParentDirectoryFail()
  212. {
  213. Testing.AssertThrows<FileNotFoundException>(() => new CloudServiceProject("DoesNotExist", serviceName, null), string.Format(Resources.PathDoesNotExistForElement, Resources.ServiceParentDirectory, "DoesNotExist"));
  214. }
  215. [Fact]
  216. [Trait(Category.AcceptanceType, Category.CheckIn)]
  217. public void AzureServiceCreateNewEmptyServiceNameFail()
  218. {
  219. using (FileSystemHelper files = new FileSystemHelper(this))
  220. {
  221. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, string.Empty, null), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Name"));
  222. }
  223. }
  224. [Fact]
  225. [Trait(Category.AcceptanceType, Category.CheckIn)]
  226. public void AzureServiceCreateNewNullServiceNameFail()
  227. {
  228. using (FileSystemHelper files = new FileSystemHelper(this))
  229. {
  230. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, null, null), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Name"));
  231. }
  232. }
  233. [Fact]
  234. [Trait(Category.AcceptanceType, Category.CheckIn)]
  235. public void AzureServiceCreateNewInvalidServiceNameFail()
  236. {
  237. foreach (string invalidFileName in Test.Utilities.Common.Data.InvalidFileName)
  238. {
  239. using (FileSystemHelper files = new FileSystemHelper(this))
  240. {
  241. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, invalidFileName, null), string.Format(Resources.InvalidFileName, "Name"));
  242. }
  243. }
  244. }
  245. [Fact]
  246. [Trait(Category.AcceptanceType, Category.CheckIn)]
  247. public void AzureServiceCreateNewInvalidDnsServiceNameFail()
  248. {
  249. char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
  250. foreach (string invalidDnsName in Test.Utilities.Common.Data.InvalidServiceNames)
  251. {
  252. using (FileSystemHelper files = new FileSystemHelper(this))
  253. {
  254. // This case is handled in AzureServiceCreateNewInvalidDnsServiceNameFail test
  255. //
  256. if (invalidFileNameChars.Any(c => invalidFileNameChars.Contains<char>(c))) continue;
  257. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, invalidDnsName, null), string.Format(Resources.InvalidDnsName, invalidDnsName, "Name"));
  258. }
  259. }
  260. }
  261. [Fact]
  262. [Trait(Category.AcceptanceType, Category.CheckIn)]
  263. public void AzureServiceCreateNewExistingServiceFail()
  264. {
  265. using (FileSystemHelper files = new FileSystemHelper(this))
  266. {
  267. new CloudServiceProject(files.RootPath, serviceName, null);
  268. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, serviceName, null), string.Format(Resources.ServiceAlreadyExistsOnDisk, serviceName, Path.Combine(files.RootPath, serviceName)));
  269. }
  270. }
  271. [Fact]
  272. [Trait(Category.AcceptanceType, Category.CheckIn)]
  273. public void AzureNodeServiceLoadExistingSimpleService()
  274. {
  275. AddNodeRoleTest(0, 0, 0);
  276. }
  277. [Fact]
  278. [Trait(Category.AcceptanceType, Category.CheckIn)]
  279. public void AzureNodeServiceLoadExistingOneWebRoleService()
  280. {
  281. AddNodeRoleTest(1, 0, 0);
  282. }
  283. [Fact]
  284. [Trait(Category.AcceptanceType, Category.CheckIn)]
  285. public void AzureNodeServiceLoadExistingOneWorkerRoleService()
  286. {
  287. AddNodeRoleTest(0, 1, 0);
  288. }
  289. [Fact]
  290. [Trait(Category.AcceptanceType, Category.CheckIn)]
  291. public void AzureNodeServiceLoadExistingMultipleWebRolesService()
  292. {
  293. AddNodeRoleTest(5, 0, 0);
  294. }
  295. [Fact]
  296. [Trait(Category.AcceptanceType, Category.CheckIn)]
  297. public void AzureNodeServiceLoadExistingMultipleWorkerRolesService()
  298. {
  299. AddNodeRoleTest(0, 5, 0);
  300. }
  301. [Fact]
  302. [Trait(Category.AcceptanceType, Category.CheckIn)]
  303. public void AzureNodeServiceLoadExistingMultipleWebAndOneWorkerRolesService()
  304. {
  305. int order = 0;
  306. AddNodeRoleTest(3, 4, order++);
  307. AddNodeRoleTest(2, 4, order++);
  308. AddNodeRoleTest(4, 2, order++);
  309. AddNodeRoleTest(3, 5, order++);
  310. }
  311. [Fact]
  312. [Trait(Category.AcceptanceType, Category.CheckIn)]
  313. public void AzurePHPServiceLoadExistingSimpleService()
  314. {
  315. AddPHPRoleTest(0, 0, 0);
  316. }
  317. [Fact]
  318. [Trait(Category.AcceptanceType, Category.CheckIn)]
  319. public void AzurePHPServiceLoadExistingOneWebRoleService()
  320. {
  321. AddPHPRoleTest(1, 0, 0);
  322. }
  323. [Fact]
  324. [Trait(Category.AcceptanceType, Category.CheckIn)]
  325. public void AzurePHPServiceLoadExistingOneWorkerRoleService()
  326. {
  327. AddPHPRoleTest(0, 1, 0);
  328. }
  329. [Fact]
  330. [Trait(Category.AcceptanceType, Category.CheckIn)]
  331. public void AzurePHPServiceLoadExistingMultipleWebRolesService()
  332. {
  333. AddPHPRoleTest(5, 0, 0);
  334. }
  335. [Fact]
  336. [Trait(Category.AcceptanceType, Category.CheckIn)]
  337. public void AzurePHPServiceLoadExistingMultipleWorkerRolesService()
  338. {
  339. AddPHPRoleTest(0, 5, 0);
  340. }
  341. [Fact]
  342. [Trait(Category.AcceptanceType, Category.CheckIn)]
  343. public void AzurePHPServiceLoadExistingMultipleWebAndOneWorkerRolesService()
  344. {
  345. int order = 0;
  346. AddPHPRoleTest(3, 4, order++);
  347. AddPHPRoleTest(2, 4, order++);
  348. AddPHPRoleTest(4, 2, order++);
  349. AddPHPRoleTest(3, 5, order++);
  350. }
  351. [Fact]
  352. [Trait(Category.AcceptanceType, Category.CheckIn)]
  353. public void AzureServiceAddNewNodeWebRoleTest()
  354. {
  355. using (FileSystemHelper files = new FileSystemHelper(this))
  356. {
  357. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  358. RoleInfo webRole = service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, "MyWebRole", 10);
  359. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, webRoles: new WebRoleInfo[] { (WebRoleInfo)webRole }, webScaff: Path.Combine(Resources.NodeScaffolding, Resources.WebRole), roles: new RoleInfo[] { webRole });
  360. }
  361. }
  362. [Fact]
  363. [Trait(Category.AcceptanceType, Category.CheckIn)]
  364. public void AzureServiceAddNewPHPWebRoleTest()
  365. {
  366. using (FileSystemHelper files = new FileSystemHelper(this))
  367. {
  368. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  369. RoleInfo webRole = service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "MyWebRole", 10);
  370. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, webRoles: new WebRoleInfo[] { (WebRoleInfo)webRole }, webScaff: Path.Combine(Resources.PHPScaffolding, Resources.WebRole), roles: new RoleInfo[] { webRole });
  371. }
  372. }
  373. [Fact]
  374. [Trait(Category.AcceptanceType, Category.CheckIn)]
  375. public void AzureServiceAddNewNodeWorkerRoleTest()
  376. {
  377. using (FileSystemHelper files = new FileSystemHelper(this))
  378. {
  379. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  380. RoleInfo workerRole = service.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, "MyWorkerRole", 10);
  381. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, workerRoles: new WorkerRoleInfo[] { (WorkerRoleInfo)workerRole }, workerScaff: Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole), roles: new RoleInfo[] { workerRole });
  382. }
  383. }
  384. [Fact]
  385. [Trait(Category.AcceptanceType, Category.CheckIn)]
  386. public void AzureServiceAddNewPHPWorkerRoleTest()
  387. {
  388. using (FileSystemHelper files = new FileSystemHelper(this))
  389. {
  390. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  391. RoleInfo workerRole = service.AddWorkerRole(Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, "MyWorkerRole", 10);
  392. AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, workerRoles: new WorkerRoleInfo[] { (WorkerRoleInfo)workerRole }, workerScaff: Path.Combine(Resources.PHPScaffolding, Resources.WorkerRole), roles: new RoleInfo[] { workerRole });
  393. }
  394. }
  395. [Fact]
  396. [Trait(Category.AcceptanceType, Category.CheckIn)]
  397. public void AzureServiceAddNewNodeWorkerRoleWithWhiteCharFail()
  398. {
  399. using (FileSystemHelper files = new FileSystemHelper(this))
  400. {
  401. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, serviceName, null).AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, "\tRole"), string.Format(Resources.InvalidRoleNameMessage, "\tRole"));
  402. }
  403. }
  404. [Fact]
  405. [Trait(Category.AcceptanceType, Category.CheckIn)]
  406. public void AzureServiceAddNewPHPWorkerRoleWithWhiteCharFail()
  407. {
  408. using (FileSystemHelper files = new FileSystemHelper(this))
  409. {
  410. Testing.AssertThrows<ArgumentException>(() => new CloudServiceProject(files.RootPath, serviceName, null).AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "\tRole"), string.Format(Resources.InvalidRoleNameMessage, "\tRole"));
  411. }
  412. }
  413. [Fact]
  414. [Trait(Category.AcceptanceType, Category.CheckIn)]
  415. public void AzureServiceAddExistingNodeRoleFail()
  416. {
  417. using (FileSystemHelper files = new FileSystemHelper(this))
  418. {
  419. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  420. service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, "WebRole");
  421. Testing.AssertThrows<ArgumentException>(() => service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, "WebRole"), string.Format(Resources.AddRoleMessageRoleExists, "WebRole"));
  422. }
  423. }
  424. [Fact]
  425. [Trait(Category.AcceptanceType, Category.CheckIn)]
  426. public void AzureServiceAddExistingPHPRoleFail()
  427. {
  428. using (FileSystemHelper files = new FileSystemHelper(this))
  429. {
  430. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  431. service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole");
  432. Testing.AssertThrows<ArgumentException>(() => service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole"), string.Format(Resources.AddRoleMessageRoleExists, "WebRole"));
  433. }
  434. }
  435. [Fact]
  436. [Trait(Category.AcceptanceType, Category.CheckIn)]
  437. public void GetServiceNameTest()
  438. {
  439. using (FileSystemHelper files = new FileSystemHelper(this))
  440. {
  441. NewAzureServiceProjectCommand newServiceCmdlet = new NewAzureServiceProjectCommand();
  442. newServiceCmdlet.CommandRuntime = new MockCommandRuntime();
  443. newServiceCmdlet.NewAzureServiceProcess(files.RootPath, serviceName);
  444. Assert.Equal<string>(serviceName, new CloudServiceProject(Path.Combine(files.RootPath, serviceName), null).ServiceName);
  445. }
  446. }
  447. [Fact]
  448. [Trait(Category.AcceptanceType, Category.CheckIn)]
  449. public void ChangeServiceNameTest()
  450. {
  451. string newName = "NodeAppService";
  452. using (FileSystemHelper files = new FileSystemHelper(this))
  453. {
  454. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  455. service.ChangeServiceName(newName, service.Paths);
  456. Assert.Equal<string>(newName, service.Components.CloudConfig.serviceName);
  457. Assert.Equal<string>(newName, service.Components.LocalConfig.serviceName);
  458. Assert.Equal<string>(newName, service.Components.Definition.name);
  459. }
  460. }
  461. [Fact]
  462. [Trait(Category.AcceptanceType, Category.CheckIn)]
  463. public void SetNodeRoleInstancesTest()
  464. {
  465. int newInstances = 10;
  466. using (FileSystemHelper files = new FileSystemHelper(this))
  467. {
  468. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  469. service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, "WebRole", 1);
  470. service.SetRoleInstances(service.Paths, "WebRole", newInstances);
  471. Assert.Equal<int>(service.Components.CloudConfig.Role[0].Instances.count, newInstances);
  472. Assert.Equal<int>(service.Components.LocalConfig.Role[0].Instances.count, newInstances);
  473. }
  474. }
  475. [Fact]
  476. [Trait(Category.AcceptanceType, Category.CheckIn)]
  477. public void SetPHPRoleInstancesTest()
  478. {
  479. int newInstances = 10;
  480. using (FileSystemHelper files = new FileSystemHelper(this))
  481. {
  482. CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
  483. service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole", 1);
  484. service.SetRoleInstances(service.Paths, "WebRole", newInstances);
  485. Assert.Equal<int>(service.Components.CloudConfig.Role[0].Instances.count, newInstances);
  486. Assert.Equal<int>(service.Components.LocalConfig.Role[0].Instances.count, newInstances);
  487. }
  488. }
  489. [Fact]
  490. [Trait(Category.AcceptanceType, Category.CheckIn)]
  491. public void TestResolveRuntimePackageUrls()
  492. {
  493. // Create a temp directory that we'll use to "publish" our service
  494. using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true })
  495. {
  496. // Import our default publish settings
  497. files.CreateAzureSdkDirectoryAndImportPublishSettings();
  498. // Create a new service that we're going to publish
  499. string serviceName = "TEST_SERVICE_NAME";
  500. string rootPath = files.CreateNewService(serviceName);
  501. // Add web and worker roles
  502. string defaultWebRoleName = "WebRoleDefault";
  503. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWebRoleName, Instances = 2 };
  504. addNodeWebCmdlet.ExecuteCmdlet();
  505. string defaultWorkerRoleName = "WorkerRoleDefault";
  506. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWorkerRoleName, Instances = 2 };
  507. addNodeWorkerCmdlet.ExecuteCmdlet();
  508. AddAzureNodeWebRoleCommand matchWebRole = addNodeWebCmdlet;
  509. string matchWebRoleName = "WebRoleExactMatch";
  510. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWebRoleName, Instances = 2 };
  511. addNodeWebCmdlet.ExecuteCmdlet();
  512. AddAzureNodeWorkerRoleCommand matchWorkerRole = addNodeWorkerCmdlet;
  513. string matchWorkerRoleName = "WorkerRoleExactMatch";
  514. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWorkerRoleName, Instances = 2 };
  515. addNodeWorkerCmdlet.ExecuteCmdlet();
  516. AddAzureNodeWebRoleCommand overrideWebRole = addNodeWebCmdlet;
  517. string overrideWebRoleName = "WebRoleOverride";
  518. addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWebRoleName, Instances = 2 };
  519. addNodeWebCmdlet.ExecuteCmdlet();
  520. AddAzureNodeWorkerRoleCommand overrideWorkerRole = addNodeWorkerCmdlet;
  521. string overrideWorkerRoleName = "WorkerRoleOverride";
  522. addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWorkerRoleName, Instances = 2 };
  523. addNodeWorkerCmdlet.ExecuteCmdlet();
  524. string webRole2Name = "WebRole2";
  525. AddAzureNodeWebRoleCommand addAzureWebRole = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRole2Name };
  526. addAzureWebRole.ExecuteCmdlet();
  527. CloudServiceProject testService = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath(@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Services"));
  528. RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWebRoleName, testService.Paths, version: "0.8.2");
  529. RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWorkerRoleName, testService.Paths, version: "0.8.2");
  530. RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWebRoleName, testService.Paths, overrideUrl: "http://OVERRIDE");
  531. RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWorkerRoleName, testService.Paths, overrideUrl: "http://OVERRIDE");
  532. bool exceptionWasThrownOnSettingCacheRole = false;
  533. try
  534. {
  535. string cacheRuntimeVersion = "1.7.0";
  536. testService.AddRoleRuntime(testService.Paths, webRole2Name, Resources.CacheRuntimeValue, cacheRuntimeVersion, RuntimePackageHelper.GetTestManifest(files));
  537. }
  538. catch (NotSupportedException)
  539. {
  540. exceptionWasThrownOnSettingCacheRole = true;
  541. }
  542. Assert.True(exceptionWasThrownOnSettingCacheRole);
  543. testService.Components.Save(testService.Paths);
  544. // Get the publishing process started by creating the package
  545. testService.ResolveRuntimePackageUrls(RuntimePackageHelper.GetTestManifest(files));
  546. CloudServiceProject updatedService = new CloudServiceProject(testService.Paths.RootPath, null);
  547. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWebRoleName, "http://cdn/node/default.exe;http://cdn/iisnode/default.exe", null);
  548. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWorkerRoleName, "http://cdn/node/default.exe", null);
  549. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWorkerRoleName, "http://cdn/node/foo.exe", null);
  550. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWebRoleName, "http://cdn/node/foo.exe;http://cdn/iisnode/default.exe", null);
  551. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWebRoleName, null, "http://OVERRIDE");
  552. RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWorkerRoleName, null, "http://OVERRIDE");
  553. }
  554. }
  555. }
  556. }