PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/OrcasEngine/UnitTests/Compatibility/Import_Tests.cs

https://gitlab.com/Banul/la-project1
C# | 329 lines | 261 code | 18 blank | 50 comment | 0 complexity | 3f9e09344378aa460940994aa6e429a2 MD5 | raw file
  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. //-----------------------------------------------------------------------
  4. // <copyright file="Import_Tests.cs" company="Microsoft">
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // </copyright>
  7. // <summary>Baseline Regression Tests for v9 OM Public Interface Compatibility: Import Class</summary>
  8. //-----------------------------------------------------------------------
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. using System.IO;
  13. using NUnit.Framework;
  14. using Microsoft.Build;
  15. using Microsoft.Build.BuildEngine;
  16. using Microsoft.Build.Framework;
  17. using Microsoft.Build.UnitTests;
  18. namespace Microsoft.Build.UnitTests.OM.OrcasCompatibility
  19. {
  20. /// <summary>
  21. /// Fixture Class for the v9 OM Public Interface Compatibility Tests. Import Class.
  22. /// Also see Toolset tests in the Project test class.
  23. /// </summary>
  24. [TestFixture]
  25. public sealed class Import_Tests
  26. {
  27. /// <summary>
  28. /// Condition Test, Simple Condition, assert only accessible after evaluation.
  29. /// </summary>
  30. [Test]
  31. public void ConditionGet_Simple()
  32. {
  33. string importPath = String.Empty;
  34. try
  35. {
  36. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  37. Project p = new Project();
  38. p.AddNewImport(importPath, "true");
  39. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  40. Assertion.AssertNull("true", import);
  41. object o = p.EvaluatedProperties;
  42. import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  43. Assertion.AssertEquals("true", import.Condition);
  44. }
  45. finally
  46. {
  47. CompatibilityTestHelpers.RemoveFile(importPath);
  48. }
  49. }
  50. /// <summary>
  51. /// Condition Test, Null condition.
  52. /// </summary>
  53. [Test]
  54. public void ConditionGet_Null()
  55. {
  56. string importPath = string.Empty;
  57. try
  58. {
  59. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  60. Project p = new Project();
  61. p.AddNewImport(importPath, null);
  62. object o = p.EvaluatedProperties;
  63. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  64. Assertion.AssertNull(import.Condition);
  65. }
  66. finally
  67. {
  68. CompatibilityTestHelpers.RemoveFile(importPath);
  69. }
  70. }
  71. /// <summary>
  72. /// Condition Test, Set Null condition, assert empty string back.
  73. /// </summary>
  74. [Test]
  75. public void ConditionSet_Null()
  76. {
  77. string importPath = String.Empty;
  78. try
  79. {
  80. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  81. Project p = new Project();
  82. p.AddNewImport(importPath, "true");
  83. object o = p.EvaluatedProperties;
  84. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  85. import.Condition = null;
  86. Assertion.AssertEquals(String.Empty, import.Condition);
  87. }
  88. finally
  89. {
  90. CompatibilityTestHelpers.RemoveFile(importPath);
  91. }
  92. }
  93. /// <summary>
  94. /// Condition Test, dirty wet set.
  95. /// </summary>
  96. [Test]
  97. public void ConditionSet_DirtyWhenSet()
  98. {
  99. string projectPath = String.Empty;
  100. string importPath = String.Empty;
  101. try
  102. {
  103. projectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("project.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  104. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  105. Project p = new Project();
  106. p.AddNewImport(importPath, "true");
  107. object o = p.EvaluatedProperties;
  108. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  109. p.Save(projectPath);
  110. Assertion.AssertEquals(false, p.IsDirty);
  111. import.Condition = "condition";
  112. Assertion.AssertEquals(true, p.IsDirty);
  113. }
  114. finally
  115. {
  116. CompatibilityTestHelpers.RemoveFile(importPath);
  117. CompatibilityTestHelpers.RemoveFile(projectPath);
  118. }
  119. }
  120. /// <summary>
  121. /// ProjectPath Test, get when set in the constructor.
  122. /// </summary>
  123. [Test]
  124. public void ProjectPathGetWhenSetInCtor()
  125. {
  126. string importPath = String.Empty;
  127. try
  128. {
  129. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  130. Project p = new Project();
  131. p.AddNewImport(importPath, "true");
  132. object o = p.EvaluatedProperties;
  133. // The verbosity of this assertion is to abstract the internal implentation of FindFirstMatchingImportByPath.
  134. Assertion.AssertEquals(importPath, CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath).ProjectPath);
  135. }
  136. finally
  137. {
  138. CompatibilityTestHelpers.RemoveFile(importPath);
  139. }
  140. }
  141. /// <summary>
  142. /// ProjectPath Test, get when set in ctor
  143. /// </summary>
  144. [Test]
  145. public void EvaluatedProjectPathGetWhenSetInCtor()
  146. {
  147. string importPath = "importA.proj";
  148. string fullImportPath = ObjectModelHelpers.CreateFileInTempProjectDirectory(importPath, TestData.Content3SimpleTargetsDefaultSpecified);
  149. string projectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("project.proj", TestData.ContentImportA);
  150. try
  151. {
  152. Project p = new Project();
  153. p.Load(projectPath);
  154. // The verbosity of this assertion is to abstract the internal implentation of FindFirstMatchingImportByPath.
  155. Assertion.AssertEquals(fullImportPath, CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath).EvaluatedProjectPath);
  156. }
  157. finally
  158. {
  159. CompatibilityTestHelpers.RemoveFile(projectPath);
  160. CompatibilityTestHelpers.RemoveFile(fullImportPath);
  161. }
  162. }
  163. /// <summary>
  164. /// ProjectPath Test, get when set in loaded xml.
  165. /// </summary>
  166. [Test]
  167. public void ProjectPathGetWhenSetInXML()
  168. {
  169. string projectPath = String.Empty;
  170. string importPath = String.Empty;
  171. string fullImportPath = String.Empty;
  172. try
  173. {
  174. projectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("project.proj", TestData.ContentImportA);
  175. importPath = "importA.proj"; // as specified in xml
  176. fullImportPath = ObjectModelHelpers.CreateFileInTempProjectDirectory(importPath, TestData.ContentA);
  177. Project p = new Project();
  178. p.Load(projectPath);
  179. Assertion.AssertEquals(importPath, CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath).ProjectPath);
  180. }
  181. finally
  182. {
  183. CompatibilityTestHelpers.RemoveFile(projectPath);
  184. CompatibilityTestHelpers.RemoveFile(fullImportPath);
  185. }
  186. }
  187. /// <summary>
  188. /// ProjectPath Test, set overriding ctor value.
  189. /// </summary>
  190. [Test]
  191. public void ProjectPathSet()
  192. {
  193. string importPath = String.Empty;
  194. try
  195. {
  196. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  197. Project p = new Project();
  198. p.AddNewImport(importPath, "true");
  199. object o = p.EvaluatedProperties;
  200. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  201. import.ProjectPath = @"c:\anotherPath";
  202. Assertion.AssertEquals(@"c:\anotherPath", import.ProjectPath);
  203. }
  204. finally
  205. {
  206. CompatibilityTestHelpers.RemoveFile(importPath);
  207. }
  208. }
  209. /// <summary>
  210. /// ProjectPath Test, set overriding ctor value.
  211. /// </summary>
  212. [Test]
  213. public void ProjectPathSet_Escaped()
  214. {
  215. string importPath = String.Empty;
  216. try
  217. {
  218. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  219. Project p = new Project();
  220. p.AddNewImport(importPath, "true");
  221. object o = p.EvaluatedProperties;
  222. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  223. import.ProjectPath = @"%25%2a%3f%40%24%28%29%3b\";
  224. Assertion.AssertEquals(@"%25%2a%3f%40%24%28%29%3b\", import.ProjectPath);
  225. }
  226. finally
  227. {
  228. CompatibilityTestHelpers.RemoveFile(importPath);
  229. }
  230. }
  231. /// <summary>
  232. /// IsImported Test, false when project is an import
  233. /// </summary>
  234. [Test]
  235. public void IsImported_ProjectImport()
  236. {
  237. string importPath = String.Empty;
  238. try
  239. {
  240. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  241. Project p = new Project();
  242. p.AddNewImport(importPath, "true");
  243. object o = p.EvaluatedProperties;
  244. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  245. Assertion.AssertEquals(false, import.IsImported);
  246. }
  247. finally
  248. {
  249. CompatibilityTestHelpers.RemoveFile(importPath);
  250. }
  251. }
  252. /// <summary>
  253. /// IsImported Test, true when import is via an imported project.
  254. /// </summary>
  255. [Test]
  256. public void IsImported_ProjectImportImport()
  257. {
  258. string project1 = String.Empty;
  259. string importPathA = String.Empty;
  260. string importPathB = String.Empty;
  261. string importPathBFull = String.Empty;
  262. try
  263. {
  264. project1 = ObjectModelHelpers.CreateFileInTempProjectDirectory("project.proj", TestData.ContentImportA);
  265. importPathA = ObjectModelHelpers.CreateFileInTempProjectDirectory("importA.proj", TestData.ContentImportB);
  266. importPathB = "importB.proj"; // as specified in TestData.ContentImportB xml
  267. importPathBFull = ObjectModelHelpers.CreateFileInTempProjectDirectory(importPathB, TestData.ContentA);
  268. Project p = new Project();
  269. p.Load(project1);
  270. object o = p.EvaluatedProperties;
  271. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPathB);
  272. Assertion.AssertEquals(true, import.IsImported);
  273. }
  274. finally
  275. {
  276. CompatibilityTestHelpers.RemoveFile(project1);
  277. CompatibilityTestHelpers.RemoveFile(importPathA);
  278. CompatibilityTestHelpers.RemoveFile(importPathBFull);
  279. }
  280. }
  281. /// <summary>
  282. /// ProjectPath Test, does not evaluate scalars
  283. /// </summary>
  284. [Test]
  285. public void ProjectPathSet_ScalarValue()
  286. {
  287. string importPath = String.Empty;
  288. string importPath2 = String.Empty;
  289. try
  290. {
  291. importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  292. importPath2 = ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.proj", TestData.Content3SimpleTargetsDefaultSpecified);
  293. Project p = new Project();
  294. p.AddNewImport(importPath, "true");
  295. p.SetProperty("path", importPath2);
  296. object o = p.EvaluatedProperties;
  297. BuildProperty path = CompatibilityTestHelpers.FindBuildProperty(p, "path");
  298. Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
  299. import.ProjectPath = "$(path)";
  300. Assertion.AssertEquals("$(path)", import.ProjectPath);
  301. o = p.EvaluatedProperties;
  302. Assertion.AssertEquals(false, object.Equals(importPath2, import.EvaluatedProjectPath)); // V9 OM does not evaluate imports
  303. }
  304. finally
  305. {
  306. CompatibilityTestHelpers.RemoveFile(importPath);
  307. CompatibilityTestHelpers.RemoveFile(importPath2);
  308. }
  309. }
  310. }
  311. }