SelectedAssetGroupInfoTests.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using NUnit.Framework;
  5. using UnityEditor.VersionControl;
  6. using Codice.Client.Commands.WkTree;
  7. using Codice.CM.Common;
  8. using PlasticGui;
  9. using Unity.PlasticSCM.Editor.AssetMenu;
  10. using Unity.PlasticSCM.Tests.Editor.Mock;
  11. using Unity.PlasticSCM.Editor.AssetsOverlays;
  12. using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
  13. namespace Unity.PlasticSCM.Tests.Editor.AssetMenu
  14. {
  15. [TestFixture]
  16. class SelectedAssetGroupInfoTests
  17. {
  18. [Test]
  19. public void TestSelectedCount()
  20. {
  21. try
  22. {
  23. PlasticApiMock apiMock = new PlasticApiMock();
  24. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  25. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  26. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  27. Asset fooAsset = new Asset(fooPath);
  28. Asset barAsset = new Asset(barPath);
  29. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  30. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  31. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  32. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  33. apiMock.SetupGetWorkingBranch(new BranchInfo());
  34. AssetList assetList = new AssetList();
  35. assetList.Add(fooAsset);
  36. assetList.Add(barAsset);
  37. SelectedAssetGroupInfo groupInfo =
  38. SelectedAssetGroupInfo.BuildFromAssetList(
  39. assetList,
  40. new AssetStatusCacheMock());
  41. Assert.AreEqual(2, groupInfo.SelectedCount);
  42. }
  43. finally
  44. {
  45. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  46. }
  47. }
  48. [Test]
  49. public void TestIsCheckedInSelection()
  50. {
  51. try
  52. {
  53. PlasticApiMock apiMock = new PlasticApiMock();
  54. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  55. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  56. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  57. Asset fooAsset = new Asset(fooPath);
  58. Asset barAsset = new Asset(barPath);
  59. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  60. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  61. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  62. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  63. apiMock.SetupGetWorkingBranch(new BranchInfo());
  64. AssetList assetList = new AssetList();
  65. assetList.Add(fooAsset);
  66. assetList.Add(barAsset);
  67. SelectedAssetGroupInfo groupInfo =
  68. SelectedAssetGroupInfo.BuildFromAssetList(
  69. assetList,
  70. new AssetStatusCacheMock());
  71. Assert.IsTrue(groupInfo.IsCheckedInSelection);
  72. }
  73. finally
  74. {
  75. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  76. }
  77. }
  78. [Test]
  79. public void TestIsNotCheckedInSelection()
  80. {
  81. try
  82. {
  83. PlasticApiMock apiMock = new PlasticApiMock();
  84. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  85. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  86. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  87. Asset fooAsset = new Asset(fooPath);
  88. Asset barAsset = new Asset(barPath);
  89. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  90. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.CheckedOut();
  91. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  92. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  93. apiMock.SetupGetWorkingBranch(new BranchInfo());
  94. AssetList assetList = new AssetList();
  95. assetList.Add(fooAsset);
  96. assetList.Add(barAsset);
  97. SelectedAssetGroupInfo groupInfo =
  98. SelectedAssetGroupInfo.BuildFromAssetList(
  99. assetList,
  100. new AssetStatusCacheMock());
  101. Assert.IsFalse(groupInfo.IsCheckedInSelection);
  102. }
  103. finally
  104. {
  105. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  106. }
  107. }
  108. [Test]
  109. public void TestIsControlledSelection()
  110. {
  111. try
  112. {
  113. PlasticApiMock apiMock = new PlasticApiMock();
  114. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  115. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  116. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  117. Asset fooAsset = new Asset(fooPath);
  118. Asset barAsset = new Asset(barPath);
  119. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  120. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  121. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  122. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  123. apiMock.SetupGetWorkingBranch(new BranchInfo());
  124. AssetList assetList = new AssetList();
  125. assetList.Add(fooAsset);
  126. assetList.Add(barAsset);
  127. SelectedAssetGroupInfo groupInfo =
  128. SelectedAssetGroupInfo.BuildFromAssetList(
  129. assetList,
  130. new AssetStatusCacheMock());
  131. Assert.IsTrue(groupInfo.IsControlledSelection);
  132. }
  133. finally
  134. {
  135. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  136. }
  137. }
  138. [Test]
  139. public void TestIsNotControlledSelection()
  140. {
  141. try
  142. {
  143. PlasticApiMock apiMock = new PlasticApiMock();
  144. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  145. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  146. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  147. Asset fooAsset = new Asset(fooPath);
  148. Asset barAsset = new Asset(barPath);
  149. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  150. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  151. apiMock.SetupGetWorkingBranch(new BranchInfo());
  152. AssetList assetList = new AssetList();
  153. assetList.Add(fooAsset);
  154. assetList.Add(barAsset);
  155. SelectedAssetGroupInfo groupInfo =
  156. SelectedAssetGroupInfo.BuildFromAssetList(
  157. assetList,
  158. new AssetStatusCacheMock());
  159. Assert.IsFalse(groupInfo.IsControlledSelection);
  160. }
  161. finally
  162. {
  163. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  164. }
  165. }
  166. [Test]
  167. public void TestHasAnyAddedInSelection()
  168. {
  169. try
  170. {
  171. PlasticApiMock apiMock = new PlasticApiMock();
  172. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  173. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  174. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  175. Asset fooAsset = new Asset(fooPath);
  176. Asset barAsset = new Asset(barPath);
  177. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  178. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Added();
  179. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  180. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  181. apiMock.SetupGetWorkingBranch(new BranchInfo());
  182. AssetList assetList = new AssetList();
  183. assetList.Add(fooAsset);
  184. assetList.Add(barAsset);
  185. SelectedAssetGroupInfo groupInfo =
  186. SelectedAssetGroupInfo.BuildFromAssetList(
  187. assetList,
  188. new AssetStatusCacheMock());
  189. Assert.IsTrue(groupInfo.HasAnyAddedInSelection);
  190. }
  191. finally
  192. {
  193. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  194. }
  195. }
  196. [Test]
  197. public void TestHasAnyNoAddedInSelection()
  198. {
  199. try
  200. {
  201. PlasticApiMock apiMock = new PlasticApiMock();
  202. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  203. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  204. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  205. Asset fooAsset = new Asset(fooPath);
  206. Asset barAsset = new Asset(barPath);
  207. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  208. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  209. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  210. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  211. apiMock.SetupGetWorkingBranch(new BranchInfo());
  212. AssetList assetList = new AssetList();
  213. assetList.Add(fooAsset);
  214. assetList.Add(barAsset);
  215. SelectedAssetGroupInfo groupInfo =
  216. SelectedAssetGroupInfo.BuildFromAssetList(
  217. assetList,
  218. new AssetStatusCacheMock());
  219. Assert.IsFalse(groupInfo.HasAnyAddedInSelection);
  220. }
  221. finally
  222. {
  223. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  224. }
  225. }
  226. [Test]
  227. public void TestIsFileSelection()
  228. {
  229. try
  230. {
  231. PlasticApiMock apiMock = new PlasticApiMock();
  232. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  233. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  234. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  235. Asset fooAsset = new Asset(fooPath);
  236. Asset barAsset = new Asset(barPath);
  237. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  238. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  239. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  240. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  241. apiMock.SetupGetWorkingBranch(new BranchInfo());
  242. AssetList assetList = new AssetList();
  243. assetList.Add(fooAsset);
  244. assetList.Add(barAsset);
  245. SelectedAssetGroupInfo groupInfo =
  246. SelectedAssetGroupInfo.BuildFromAssetList(
  247. assetList,
  248. new AssetStatusCacheMock());
  249. Assert.IsTrue(groupInfo.IsFileSelection);
  250. }
  251. finally
  252. {
  253. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  254. }
  255. }
  256. [Test]
  257. public void TestIsNotFileSelection()
  258. {
  259. string barPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
  260. try
  261. {
  262. PlasticApiMock apiMock = new PlasticApiMock();
  263. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  264. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  265. Directory.CreateDirectory(barPath);
  266. Asset fooAsset = new Asset(fooPath);
  267. Asset barAsset = new Asset(barPath);
  268. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  269. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  270. apiMock.SetupGetWorkingBranch(new BranchInfo());
  271. AssetList assetList = new AssetList();
  272. assetList.Add(fooAsset);
  273. assetList.Add(barAsset);
  274. SelectedAssetGroupInfo groupInfo =
  275. SelectedAssetGroupInfo.BuildFromAssetList(
  276. assetList,
  277. new AssetStatusCacheMock());
  278. Assert.IsFalse(groupInfo.IsFileSelection);
  279. }
  280. finally
  281. {
  282. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  283. if (Directory.Exists(barPath))
  284. Directory.Delete(barPath);
  285. }
  286. }
  287. [Test]
  288. public void TestHasNotAnyLockedRemoteInSelection()
  289. {
  290. try
  291. {
  292. PlasticApiMock apiMock = new PlasticApiMock();
  293. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  294. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  295. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  296. Asset fooAsset = new Asset(fooPath);
  297. Asset barAsset = new Asset(barPath);
  298. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  299. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  300. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  301. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  302. apiMock.SetupGetWorkingBranch(new BranchInfo());
  303. AssetList assetList = new AssetList();
  304. assetList.Add(fooAsset);
  305. assetList.Add(barAsset);
  306. AssetStatusCacheMock assetStatusCache = new AssetStatusCacheMock();
  307. SelectedAssetGroupInfo groupInfo =
  308. SelectedAssetGroupInfo.BuildFromAssetList(
  309. assetList,
  310. assetStatusCache);
  311. Assert.IsFalse(groupInfo.HasAnyRemoteLockedInSelection);
  312. }
  313. finally
  314. {
  315. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  316. }
  317. }
  318. [Test]
  319. public void TestHasAnyLockedRemoteInSelection()
  320. {
  321. try
  322. {
  323. PlasticApiMock apiMock = new PlasticApiMock();
  324. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  325. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  326. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  327. Asset fooAsset = new Asset(fooPath);
  328. Asset barAsset = new Asset(barPath);
  329. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  330. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();
  331. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  332. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  333. apiMock.SetupGetWorkingBranch(new BranchInfo());
  334. AssetList assetList = new AssetList();
  335. assetList.Add(fooAsset);
  336. assetList.Add(barAsset);
  337. AssetStatusCacheMock assetStatusCache = new AssetStatusCacheMock();
  338. assetStatusCache.SetStatus(fooPath, AssetStatus.LockedRemote);
  339. SelectedAssetGroupInfo groupInfo =
  340. SelectedAssetGroupInfo.BuildFromAssetList(
  341. assetList,
  342. assetStatusCache);
  343. Assert.IsTrue(groupInfo.HasAnyRemoteLockedInSelection);
  344. }
  345. finally
  346. {
  347. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  348. }
  349. }
  350. [Test]
  351. public void TestIsCheckedOutSelection()
  352. {
  353. try
  354. {
  355. PlasticApiMock apiMock = new PlasticApiMock();
  356. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  357. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  358. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  359. Asset fooAsset = new Asset(fooPath);
  360. Asset barAsset = new Asset(barPath);
  361. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.CheckedOut();
  362. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.CheckedOut();
  363. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  364. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  365. apiMock.SetupGetWorkingBranch(new BranchInfo());
  366. AssetList assetList = new AssetList();
  367. assetList.Add(fooAsset);
  368. assetList.Add(barAsset);
  369. SelectedAssetGroupInfo groupInfo =
  370. SelectedAssetGroupInfo.BuildFromAssetList(
  371. assetList,
  372. new AssetStatusCacheMock());
  373. Assert.IsTrue(groupInfo.IsCheckedOutSelection);
  374. }
  375. finally
  376. {
  377. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  378. }
  379. }
  380. [Test]
  381. public void TestIsNotCheckedOutSelection()
  382. {
  383. try
  384. {
  385. PlasticApiMock apiMock = new PlasticApiMock();
  386. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  387. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  388. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  389. Asset fooAsset = new Asset(fooPath);
  390. Asset barAsset = new Asset(barPath);
  391. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  392. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.CheckedOut();
  393. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  394. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  395. apiMock.SetupGetWorkingBranch(new BranchInfo());
  396. AssetList assetList = new AssetList();
  397. assetList.Add(fooAsset);
  398. assetList.Add(barAsset);
  399. SelectedAssetGroupInfo groupInfo =
  400. SelectedAssetGroupInfo.BuildFromAssetList(
  401. assetList,
  402. new AssetStatusCacheMock());
  403. Assert.IsFalse(groupInfo.IsCheckedOutSelection);
  404. }
  405. finally
  406. {
  407. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  408. }
  409. }
  410. [Test]
  411. public void TestIsPrivateSelection()
  412. {
  413. try
  414. {
  415. PlasticApiMock apiMock = new PlasticApiMock();
  416. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  417. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  418. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  419. Asset fooAsset = new Asset(fooPath);
  420. Asset barAsset = new Asset(barPath);
  421. apiMock.SetupGetWorkspaceTreeNode(fooPath, null);
  422. apiMock.SetupGetWorkspaceTreeNode(barPath, null);
  423. apiMock.SetupGetWorkingBranch(new BranchInfo());
  424. AssetList assetList = new AssetList();
  425. assetList.Add(fooAsset);
  426. assetList.Add(barAsset);
  427. SelectedAssetGroupInfo groupInfo =
  428. SelectedAssetGroupInfo.BuildFromAssetList(
  429. assetList,
  430. new AssetStatusCacheMock());
  431. Assert.IsTrue(groupInfo.IsPrivateSelection);
  432. }
  433. finally
  434. {
  435. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  436. }
  437. }
  438. [Test]
  439. public void TestIsNotPrivateSelection()
  440. {
  441. try
  442. {
  443. PlasticApiMock apiMock = new PlasticApiMock();
  444. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  445. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  446. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  447. Asset fooAsset = new Asset(fooPath);
  448. Asset barAsset = new Asset(barPath);
  449. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
  450. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  451. apiMock.SetupGetWorkspaceTreeNode(barPath, null);
  452. apiMock.SetupGetWorkingBranch(new BranchInfo());
  453. AssetList assetList = new AssetList();
  454. assetList.Add(fooAsset);
  455. assetList.Add(barAsset);
  456. SelectedAssetGroupInfo groupInfo =
  457. SelectedAssetGroupInfo.BuildFromAssetList(
  458. assetList,
  459. new AssetStatusCacheMock());
  460. Assert.IsFalse(groupInfo.IsPrivateSelection);
  461. }
  462. finally
  463. {
  464. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  465. }
  466. }
  467. [Test]
  468. public void TestIsAddedSelection()
  469. {
  470. try
  471. {
  472. PlasticApiMock apiMock = new PlasticApiMock();
  473. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  474. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  475. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  476. Asset fooAsset = new Asset(fooPath);
  477. Asset barAsset = new Asset(barPath);
  478. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Added();
  479. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Added();
  480. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  481. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  482. apiMock.SetupGetWorkingBranch(new BranchInfo());
  483. AssetList assetList = new AssetList();
  484. assetList.Add(fooAsset);
  485. assetList.Add(barAsset);
  486. SelectedAssetGroupInfo groupInfo =
  487. SelectedAssetGroupInfo.BuildFromAssetList(
  488. assetList,
  489. new AssetStatusCacheMock());
  490. Assert.IsTrue(groupInfo.IsAddedSelection);
  491. }
  492. finally
  493. {
  494. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  495. }
  496. }
  497. [Test]
  498. public void TestIsNotAddedSelection()
  499. {
  500. try
  501. {
  502. PlasticApiMock apiMock = new PlasticApiMock();
  503. PlasticGui.Plastic.InitializeAPIForTesting(apiMock);
  504. string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
  505. string barPath = Path.Combine(Path.GetTempPath(), "bar.c");
  506. Asset fooAsset = new Asset(fooPath);
  507. Asset barAsset = new Asset(barPath);
  508. WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Added();
  509. WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.CheckedOut();
  510. apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
  511. apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
  512. apiMock.SetupGetWorkingBranch(new BranchInfo());
  513. AssetList assetList = new AssetList();
  514. assetList.Add(fooAsset);
  515. assetList.Add(barAsset);
  516. SelectedAssetGroupInfo groupInfo =
  517. SelectedAssetGroupInfo.BuildFromAssetList(
  518. assetList,
  519. new AssetStatusCacheMock());
  520. Assert.IsFalse(groupInfo.IsAddedSelection);
  521. }
  522. finally
  523. {
  524. PlasticGui.Plastic.InitializeAPIForTesting(new PlasticAPI());
  525. }
  526. }
  527. class AssetStatusCacheMock : IAssetStatusCache
  528. {
  529. internal void SetStatus(string fullPath, AssetStatus status)
  530. {
  531. mData.Add(fullPath, status);
  532. }
  533. AssetStatus IAssetStatusCache.GetStatusForPath(string fullPath)
  534. {
  535. AssetStatus status = AssetStatus.None;
  536. mData.TryGetValue(fullPath, out status);
  537. return status;
  538. }
  539. AssetStatus IAssetStatusCache.GetStatusForGuid(string guid)
  540. {
  541. return AssetStatus.None;
  542. }
  543. LockStatusData IAssetStatusCache.GetLockStatusData(string guid)
  544. {
  545. return null;
  546. }
  547. LockStatusData IAssetStatusCache.GetLockStatusDataForPath(string path)
  548. {
  549. return null;
  550. }
  551. void IAssetStatusCache.Clear()
  552. {
  553. mData.Clear();
  554. }
  555. Dictionary<string, AssetStatus> mData =
  556. new Dictionary<string, AssetStatus>();
  557. }
  558. }
  559. }