PageRenderTime 64ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/Collaboris.Saf.Tests/Tests/ActionDefinition/ActionDefinitionCacheTests.cs

#
C# | 207 lines | 131 code | 44 blank | 32 comment | 15 complexity | 20c76d2b9bfed5dc35a2256ec336b60d MD5 | raw file
  1. namespace Collaboris.Saf.Tests.Tests.ActionDefinition
  2. {
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Diagnostics;
  6. using System.Xml;
  7. using Definitions;
  8. using Microsoft.VisualStudio.TestTools.UnitTesting;
  9. using SharePoint.Wss.Attributes;
  10. using Utilities;
  11. /// <summary>
  12. /// Summary description for MSBuildTests
  13. /// </summary>
  14. [TestClass]
  15. public class ActionDefinitionCacheTests
  16. {
  17. /// <summary>
  18. /// Runs Before all tests.
  19. /// </summary>
  20. /// <param name="testContext">The test context.</param>
  21. [ClassInitialize]
  22. public static void BeforeAllTests(TestContext testContext)
  23. {
  24. }
  25. /// <summary>
  26. /// Uses the Execute SQL Test to ensure we have full utilised cache
  27. /// and that we can retrieve definition from collaboris.Saf.
  28. /// </summary>
  29. [TestMethod]
  30. public void Test_For_Known_Class_In_Clb_Saf()
  31. {
  32. string fourPart =
  33. "Collaboris.Saf.Actions.SQL.ExecuteSQL,Collaboris.Saf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  34. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  35. CollaborisClassAttribute attribute = ActionReflector.GetClassAttribute(fourPart);
  36. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  37. Assert.IsTrue(definition.ReleaseStatus == attribute.ReleaseStatus);
  38. Assert.IsTrue(definition.Title == attribute.Title);
  39. Assert.IsTrue(definition.Summary == attribute.Summary);
  40. Assert.IsTrue(definition.ContactAuthorEmail == attribute.ContactAuthorEmail);
  41. }
  42. /// <summary>
  43. /// Uses the Execute SQL Test to ensure we have full utilised cache
  44. /// and that we can retrieve definition from collaboris.Saf.Actions.MOSS
  45. /// </summary>
  46. [TestMethod]
  47. public void Test_For_Known_Class_In_Clb_Saf_MOSS()
  48. {
  49. string fourPart =
  50. "Collaboris.Saf.Actions.Moss.Publishing.PublishPage,Collaboris.Saf.Actions.Moss, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  51. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  52. CollaborisClassAttribute attribute = ActionReflector.GetClassAttribute(fourPart);
  53. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  54. Assert.IsTrue(definition.ReleaseStatus == attribute.ReleaseStatus);
  55. Assert.IsTrue(definition.Title == attribute.Title);
  56. Assert.IsTrue(definition.Summary == attribute.Summary);
  57. Assert.IsTrue(definition.ContactAuthorEmail == attribute.ContactAuthorEmail);
  58. }
  59. /// <summary>
  60. /// Uses the Execute SQL Test to ensure we have full utilised cache
  61. /// and that we can retrieve definition from collaboris.Saf.Actions.WSS
  62. /// </summary>
  63. [TestMethod]
  64. public void Test_For_Known_Class_In_Clb_Saf_WSS()
  65. {
  66. string fourPart = "Collaboris.Saf.Actions.Wss.Web.CreateWeb,Collaboris.Saf.Actions.Wss, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  67. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  68. CollaborisClassAttribute attribute = ActionReflector.GetClassAttribute(fourPart);
  69. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  70. Assert.IsTrue(definition.ReleaseStatus == attribute.ReleaseStatus);
  71. Assert.IsTrue(definition.Title == attribute.Title);
  72. Assert.IsTrue(definition.Summary == attribute.Summary);
  73. Assert.IsTrue(definition.ContactAuthorEmail == attribute.ContactAuthorEmail);
  74. }
  75. /// <summary>
  76. /// Tests to see that the Action Properties get set ok - corresponding to
  77. /// Saf Attribute set on the entity
  78. /// </summary>
  79. [TestMethod]
  80. public void Test_Action_Properties_Definitions_Resolve()
  81. {
  82. string fourPart =
  83. "Collaboris.Saf.Actions.Wss.Web.CreateWeb,Collaboris.Saf.Actions.Wss, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  84. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  85. string genericTypeName = ActionReflector.GetSoleEntityType(fourPart).FullName;
  86. CollaborisPropertyAttribute attribute = ActionReflector.GetSafPropertyAttribute(fourPart, "EntityList");
  87. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  88. Assert.IsTrue(definition.Properties["EntityList"].Title == attribute.Title);
  89. Assert.IsTrue(definition.Properties["EntityList"].Summary== attribute.Summary);
  90. Assert.IsTrue(definition.Properties["EntityList"].ReadMore == attribute.ReadMore);
  91. // Test the short cuts
  92. //Assert.IsTrue(definition.EntityDefinition.Title == attribute.Title);
  93. //Assert.IsTrue(definition.EntityDefinition.Summary == attribute.Summary);
  94. }
  95. /// <summary>
  96. /// Creates an object definition
  97. /// </summary>
  98. [TestMethod]
  99. public void Test_That_Spring_Returns_Correct_Xml_For_Action()
  100. {
  101. string fourPart =
  102. "Collaboris.Saf.Actions.Wss.Wrappers.StsAdmin, Collaboris.Saf.Actions.Wss, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  103. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  104. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  105. // or used like this ....
  106. // SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions.Find(typeof(Collaboris.Saf.Actions.Templating.NVelocity));
  107. // returns the class definition represented as Spring.
  108. string springXml = "<Root>" + definition.ToSpring() + "</Root>";
  109. XmlDocument xmlDocument = new XmlDocument();
  110. xmlDocument.LoadXml(springXml);
  111. }
  112. [TestMethod]
  113. public void Test_That_Aliasing_works_on_a_tricky_Generic_Action()
  114. {
  115. string fourPart =
  116. "Collaboris.Saf.Actions.Powershell.ExecutePowershell, Collaboris.Saf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  117. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  118. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  119. string alias = definition.Alias;
  120. SafPropertyDefinitionCollection allProperties = definition.Properties;
  121. SafPropertyDefinition entityProperty = allProperties["EntityList"];
  122. Assert.IsTrue(entityProperty.ClassDefinition.IsGeneric);
  123. Assert.IsTrue(entityProperty.ClassDefinition.Alias == "Entity.PowershellScriptInfo");
  124. }
  125. [TestMethod]
  126. public void Test_that_Complex_Property_But_Not_Saf_Class_Works()
  127. {
  128. string fourPart =
  129. "Collaboris.Saf.Actions.Powershell.ExecutePowershell, Collaboris.Saf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=182db3eac6a9e195";
  130. string knownClassToTestFor = ActionReflector.Convert4PartTypeNameToKey(fourPart);
  131. SafClassDefinition definition = SafDefinitionCache.SafClassDefinitions[knownClassToTestFor];
  132. SafPropertyDefinition propDefinition =
  133. definition.Properties["EntityList"].ClassDefinition.Properties["DoScript"].ClassDefinition.Properties["Commands"];
  134. SafClassDefinition powershellDefinition =
  135. definition.Properties["EntityList"].ClassDefinition.Properties["DoScript"].ClassDefinition;
  136. definition.AssignParent(null);
  137. string stsXml = definition.ToStsAdm(true);
  138. string msBuildXml = definition.ToMSBuild(true, false);
  139. string springXml = definition.ToSpring(false, false);
  140. string macroXml = definition.ToSpring(true, false);
  141. }
  142. [TestMethod]
  143. public void Test_That_The_Namespaces_Come_Back_And_That_we_Have_A_Few_Known_Ones()
  144. {
  145. ReadOnlyCollection<string> namespaces = SafDefinitionCache.SafFilteredNamespaces;
  146. foreach (string s in namespaces)
  147. {
  148. Debug.Write(s);
  149. }
  150. Assert.IsTrue(namespaces.Contains("Collaboris.Saf.Actions.SQL"));
  151. }
  152. [TestMethod]
  153. public void Test_That_We_Can_Get_Namespace_By_Assembly_Name()
  154. {
  155. ReadOnlyCollection<string> namespaces = SafDefinitionCache.GetFilteredNamespacesByAssembly("Collaboris.Saf");
  156. foreach (string s in namespaces)
  157. {
  158. Debug.Write(s);
  159. }
  160. Assert.IsTrue(namespaces.Contains("Collaboris.Saf.Actions.SQL"));
  161. }
  162. }
  163. }