PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/EDXLSharp-AWS/EDXLSharp_Lib/NIMCADTest/ResourceDetailTests/ResourceStatus/ResourceStatusGenerator.cs

#
C# | 236 lines | 170 code | 30 blank | 36 comment | 5 complexity | 0c85e84a50faf0c160c30abd74f8b970 MD5 | raw file
Possible License(s): Apache-2.0
  1. // ———————————————————————–
  2. // <copyright file="ResourceStatusGenerator.cs" company="The MITRE Corporation">
  3. // Copyright (c) 2014 The MITRE Corporation. All rights reserved.
  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. // </copyright>
  14. // ———————————————————————–
  15. /////////////////////////////////////////////////////////////////////////////////////////////////
  16. // ResourceStatusGenerator.cs:
  17. //
  18. // A generator for good and bad examples of ResourceStatus.
  19. //
  20. // Project: NIEMCADTest
  21. // Author: Lizzie DeYoung - MITRE
  22. /////////////////////////////////////////////////////////////////////////////////////////////////
  23. // Copyright (c) 2014 The MITRE Corporation. All rights reserved.
  24. //
  25. // NOTICE
  26. // This software was produced for the U. S. Government
  27. // under Contract No. FA8721-09-C-0001, and is
  28. // subject to the Rights in Noncommercial Computer Software
  29. // and Noncommercial Computer Software Documentation Clause
  30. // (DFARS) 252.227-7014 (JUN 1995)
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Linq;
  34. using System.Text;
  35. using System.Threading.Tasks;
  36. using System.Xml;
  37. using EDXLSharp.NIEMCADLib;
  38. using EDXLSharp.NIEMMilOpsLib;
  39. using EDXLSharp;
  40. using Microsoft.VisualStudio.TestTools.UnitTesting;
  41. using System.Diagnostics;
  42. namespace NIEMCADTest.ResourceDetailTests
  43. {
  44. class ResourceStatusGenerator : Generator
  45. {
  46. public const string PRIMARY_STATUS = "primaryStatus";
  47. public const string SECONDARY_STATUS = "secondaryStatus";
  48. public const string SECONDARY_STATUS_TYPE = "secondaryStatusType";
  49. public const string RESOURCE_UCAD_STATUS = "ResourceUCADStatus";
  50. public const string RESOURCE_EIDD_STATUS = "ResourceEIDDStatus";
  51. public const string RESOURCE_SECONDARY_STATUS = "ResourceSecondaryStatusText";
  52. //TODO: LDY modify these to use $namespace$ $name$ and $prefix$
  53. //TODO: TEST modify all references to these xml strings with GetXml from superclass.
  54. public const string RESOURCE_STATUS_EMPTY = @"
  55. <cad:ResourceStatus xmlns:cad='http://mitre.org/emevent/0.8/cad2cad/'>
  56. </cad:ResourceStatus>";
  57. public const string RESOURCE_STATUS_PRIMARY_ONLY = @"
  58. <cad:ResourceStatus xmlns:cad='http://mitre.org/emevent/0.8/cad2cad/'>
  59. <cad:ResourcePrimaryStatus>$code</cad:ResourcePrimaryStatus>
  60. </cad:ResourceStatus>";
  61. public const string RESOURCE_STATUS_SECONDARY_ONLY = @"
  62. <cad:ResourceStatus xmlns:cad='http://mitre.org/emevent/0.8/cad2cad/'>
  63. <cad:$elementname>$code</cad:$elementname>
  64. </cad:ResourceStatus>";
  65. public const string RESOURCE_STATUS = @"
  66. <cad:ResourceStatus xmlns:cad='http://mitre.org/emevent/0.8/cad2cad/'>
  67. <cad:ResourcePrimaryStatus>$primarycode</cad:ResourcePrimaryStatus>
  68. <cad:$elementname>$secondarycode</cad:$elementname>
  69. </cad:ResourceStatus>";
  70. public static string[] SECONDARY_RESOURCE_TYPES =
  71. new string[3] { RESOURCE_UCAD_STATUS, RESOURCE_EIDD_STATUS, RESOURCE_SECONDARY_STATUS };
  72. public ResourceStatusGenerator()
  73. {
  74. elementName = "ResourceStatus";
  75. elementNamespace = "http://mitre.org/emevent/0.8/cad2cad/";
  76. elementPrefix = "cad";
  77. }
  78. public List<TestObject> BAD_ResourceStatusEmpty()
  79. {
  80. string xml = RESOURCE_STATUS_EMPTY;
  81. TestObject testObject = GetTestObject(xml, null, null, null);
  82. List<TestObject> list = new List<TestObject>();
  83. list.Add(testObject);
  84. return list;
  85. }
  86. public List<TestObject> BAD_ResourceNoPrimaryStatus()
  87. {
  88. List<TestObject> list = new List<TestObject>();
  89. TestObject testObject;
  90. foreach (string secondaryResourceType in SECONDARY_RESOURCE_TYPES)
  91. {
  92. string baseXml = RESOURCE_STATUS_SECONDARY_ONLY.Replace("$elementname", secondaryResourceType);
  93. string xml, text;
  94. switch (secondaryResourceType)
  95. {
  96. case RESOURCE_UCAD_STATUS:
  97. foreach (ResourceUCADStatusCode code in Enum.GetValues(typeof(ResourceUCADStatusCode)))
  98. {
  99. text = code.GetText();
  100. xml = baseXml.Replace("$code", text);
  101. testObject = GetTestObject(xml, null, secondaryResourceType, text);
  102. list.Add(testObject);
  103. }
  104. break;
  105. case RESOURCE_EIDD_STATUS:
  106. foreach (ResourceEIDDStatusCode code in Enum.GetValues(typeof(ResourceEIDDStatusCode)))
  107. {
  108. text = code.GetText();
  109. xml = baseXml.Replace("$code", text);
  110. testObject = GetTestObject(xml, null, secondaryResourceType, text);
  111. list.Add(testObject);
  112. }
  113. break;
  114. case RESOURCE_SECONDARY_STATUS:
  115. text = "this is a status";
  116. xml = baseXml.Replace("$code", text);
  117. testObject = GetTestObject(xml, null, secondaryResourceType, text);
  118. list.Add(testObject);
  119. break;
  120. default:
  121. throw new Exception("something bad happened");
  122. }
  123. }
  124. return list;
  125. }
  126. public List<TestObject> GOOD_ResourceOnlyPrimaryStatus()
  127. {
  128. List<TestObject> list = new List<TestObject>();
  129. TestObject testObject;
  130. foreach (ResourcePrimaryStatusCode code in Enum.GetValues(typeof(ResourcePrimaryStatusCode)))
  131. {
  132. string text = code.GetText();
  133. string xml = RESOURCE_STATUS_PRIMARY_ONLY.Replace("$code", text);
  134. testObject = GetTestObject(xml, text, null, null);
  135. list.Add(testObject);
  136. }
  137. return list;
  138. }
  139. public List<TestObject> GOOD_ResourcePrimaryAndSecondaryStatus()
  140. {
  141. List<TestObject> list = new List<TestObject>();
  142. TestObject testObject;
  143. foreach (ResourcePrimaryStatusCode primaryCode in Enum.GetValues(typeof(ResourcePrimaryStatusCode)))
  144. {
  145. string primaryCodeText = primaryCode.GetText();
  146. string primaryStatusXml = RESOURCE_STATUS.Replace("$primarycode", primaryCodeText);
  147. foreach (string secondaryResourceType in SECONDARY_RESOURCE_TYPES)
  148. {
  149. string secondaryStatusXml = primaryStatusXml.Replace("$elementname", secondaryResourceType);
  150. string xml, secondaryCodetext;
  151. switch (secondaryResourceType)
  152. {
  153. case RESOURCE_UCAD_STATUS:
  154. foreach (ResourceUCADStatusCode secondaryCode in Enum.GetValues(typeof(ResourceUCADStatusCode)))
  155. {
  156. secondaryCodetext = secondaryCode.GetText();
  157. xml = secondaryStatusXml.Replace("$secondarycode", secondaryCodetext);
  158. testObject = GetTestObject(xml, primaryCodeText, secondaryResourceType, secondaryCodetext);
  159. list.Add(testObject);
  160. }
  161. break;
  162. case RESOURCE_EIDD_STATUS:
  163. foreach (ResourceEIDDStatusCode secondaryCode in Enum.GetValues(typeof(ResourceEIDDStatusCode)))
  164. {
  165. secondaryCodetext = secondaryCode.GetText();
  166. xml = secondaryStatusXml.Replace("$secondarycode", secondaryCodetext);
  167. testObject = GetTestObject(xml, primaryCodeText, secondaryResourceType, secondaryCodetext);
  168. list.Add(testObject);
  169. }
  170. break;
  171. case RESOURCE_SECONDARY_STATUS:
  172. secondaryCodetext = "this is a status";
  173. xml = secondaryStatusXml.Replace("$secondarycode", secondaryCodetext);
  174. testObject = GetTestObject(xml, primaryCodeText, secondaryResourceType, secondaryCodetext);
  175. list.Add(testObject);
  176. break;
  177. default:
  178. throw new Exception("something went wrong with the test...");
  179. }
  180. }
  181. }
  182. return list;
  183. }
  184. //TODO: LDY implement this once the resource secondary status turns into a list
  185. /*
  186. public static List<XmlNode> GOOD_ResourcePrimaryAndMultipleSecondaryStatus() { throw new NotImplementedException(); }
  187. */
  188. private TestObject GetTestObject(string xml, string primaryStatus, string secondaryStatusType, string secondaryStatus)
  189. {
  190. TestObject testObject = this.GetTestObject(xml);
  191. if (!string.IsNullOrWhiteSpace(primaryStatus))
  192. {
  193. testObject.TestParameters.Add(PRIMARY_STATUS, primaryStatus);
  194. }
  195. if (!string.IsNullOrWhiteSpace(secondaryStatusType))
  196. {
  197. testObject.TestParameters.Add(SECONDARY_STATUS_TYPE, secondaryStatusType);
  198. }
  199. if (!string.IsNullOrWhiteSpace(secondaryStatus))
  200. {
  201. testObject.TestParameters.Add(SECONDARY_STATUS, secondaryStatus);
  202. }
  203. return testObject;
  204. }
  205. }
  206. }