/src/AddIns/Misc/PackageManagement/Test/Src/PackageFilesTests.cs

https://github.com/ajadex/SharpDevelop · C# · 163 lines · 108 code · 38 blank · 17 comment · 0 complexity · 08c5b6a54d5c36bde7284cfd8a4adef1 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Collections.Generic;
  20. using ICSharpCode.PackageManagement;
  21. using ICSharpCode.PackageManagement.Design;
  22. using NuGet;
  23. using NUnit.Framework;
  24. namespace PackageManagement.Tests
  25. {
  26. [TestFixture]
  27. public class PackageFilesTests
  28. {
  29. PackageFiles packageFiles;
  30. void CreatePackageFiles(FakePackage package)
  31. {
  32. packageFiles = new PackageFiles(package);
  33. }
  34. void CreatePackageFilesWithOneFile(string fileName)
  35. {
  36. var package = new FakePackage();
  37. package.AddFile(fileName);
  38. CreatePackageFiles(package);
  39. }
  40. void CreatePackageFilesWithTwoFiles(string fileName1, string fileName2)
  41. {
  42. var package = new FakePackage();
  43. package.AddFile(fileName1);
  44. package.AddFile(fileName2);
  45. CreatePackageFiles(package);
  46. }
  47. [Test]
  48. public void HasAnyPackageScripts_HasOnePowerShellInitScript_ReturnsTrue()
  49. {
  50. CreatePackageFilesWithOneFile(@"tools\init.ps1");
  51. bool hasScripts = packageFiles.HasAnyPackageScripts();
  52. Assert.IsTrue(hasScripts);
  53. }
  54. [Test]
  55. public void HasAnyPackageScripts_HasOneCSharpFile_ReturnsFalse()
  56. {
  57. CreatePackageFilesWithOneFile(@"src\test.cs");
  58. bool hasScripts = packageFiles.HasAnyPackageScripts();
  59. Assert.IsFalse(hasScripts);
  60. }
  61. [Test]
  62. public void HasAnyPackageScripts_HasOnePowerShellInitScriptWithDifferentParentFolder_ReturnsTrue()
  63. {
  64. CreatePackageFilesWithOneFile(@"parentfolder\init.ps1");
  65. bool hasScripts = packageFiles.HasAnyPackageScripts();
  66. Assert.IsTrue(hasScripts);
  67. }
  68. [Test]
  69. public void HasAnyPackageScripts_HasOnePowerShellInitScriptInUpperCase_ReturnsTrue()
  70. {
  71. CreatePackageFilesWithOneFile(@"tools\INIT.PS1");
  72. bool hasScripts = packageFiles.HasAnyPackageScripts();
  73. Assert.IsTrue(hasScripts);
  74. }
  75. [Test]
  76. public void HasAnyPackageScripts_HasOnePowerShellInstallScript_ReturnsTrue()
  77. {
  78. CreatePackageFilesWithOneFile(@"tools\install.ps1");
  79. bool hasScripts = packageFiles.HasAnyPackageScripts();
  80. Assert.IsTrue(hasScripts);
  81. }
  82. [Test]
  83. public void HasAnyPackageScripts_HasOnePowerShellInstallScriptInUpperCase_ReturnsTrue()
  84. {
  85. CreatePackageFilesWithOneFile(@"tools\INSTALL.PS1");
  86. bool hasScripts = packageFiles.HasAnyPackageScripts();
  87. Assert.IsTrue(hasScripts);
  88. }
  89. [Test]
  90. public void HasAnyPackageScripts_HasOnePowerShellUninstallScript_ReturnsTrue()
  91. {
  92. CreatePackageFilesWithOneFile(@"tools\uninstall.ps1");
  93. bool hasScripts = packageFiles.HasAnyPackageScripts();
  94. Assert.IsTrue(hasScripts);
  95. }
  96. [Test]
  97. public void HasAnyPackageScripts_HasOnePowerShellUninstallScriptInUpperCase_ReturnsTrue()
  98. {
  99. CreatePackageFilesWithOneFile(@"tools\UNINSTALL.PS1");
  100. bool hasScripts = packageFiles.HasAnyPackageScripts();
  101. Assert.IsTrue(hasScripts);
  102. }
  103. [Test]
  104. public void HasAnyPackageScripts_SecondFileIsPowerShellInitScript_ReturnsTrue()
  105. {
  106. CreatePackageFilesWithTwoFiles(@"src\test.cs", @"tools\init.ps1");
  107. bool hasScripts = packageFiles.HasAnyPackageScripts();
  108. Assert.IsTrue(hasScripts);
  109. }
  110. [Test]
  111. public void HasUninstallPackageScript_HasOnePowerShellUninstallScript_ReturnsTrue()
  112. {
  113. CreatePackageFilesWithOneFile(@"tools\uninstall.ps1");
  114. bool hasScript = packageFiles.HasUninstallPackageScript();
  115. Assert.IsTrue(hasScript);
  116. }
  117. [Test]
  118. public void HasUninstallPackageScript_HasOneCSharpFile_ReturnsFalse()
  119. {
  120. CreatePackageFilesWithOneFile(@"tools\test.cs");
  121. bool hasScript = packageFiles.HasUninstallPackageScript();
  122. Assert.IsFalse(hasScript);
  123. }
  124. }
  125. }