PageRenderTime 732ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/MI.Modeller/MI.Modeller.Test.DataGenerators/B2MMLDataGenerator/OpMaterialSpecificationTypeDataGenerator.cs

https://bitbucket.org/lukesandells/modeller-test
C# | 256 lines | 202 code | 16 blank | 38 comment | 19 complexity | 2b4d28578b5e4f09d0371ca822c402b2 MD5 | raw file
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using MI.Modeller.Domain.Client;
  4. namespace MI.Modeller.Test.DataGenerators.B2MMLDataGenerator
  5. {
  6. /// <summary>
  7. /// Class OpMaterialSpecificationTypeDataGenerator.
  8. /// Generate data for testing
  9. /// Methods will yield the most comprehensive objects first, so all data populated and collections filled with multiple
  10. /// </summary>
  11. public static class OpMaterialSpecificationTypeDataGenerator
  12. {
  13. #region Members
  14. /// <summary>
  15. /// Generates the invalid op material specification types.
  16. /// </summary>
  17. /// <returns>System.Collections.Generic.IEnumerable&lt;OpMaterialSpecificationType&gt;.</returns>
  18. public static IEnumerable<OpMaterialSpecificationType> GenerateInvalidOpMaterialSpecificationTypes()
  19. {
  20. MaterialClassIDType[] materialClassId =
  21. {
  22. new MaterialClassIDType
  23. {
  24. Value = "EquipmentClassId"
  25. }
  26. };
  27. MaterialDefinitionIDType[] materialDefinitionId =
  28. {
  29. new MaterialDefinitionIDType
  30. {
  31. Value = "DefId"
  32. }
  33. };
  34. var materialSpecficationId = new IdentifierType
  35. {
  36. Value = "materialSpecificationId"
  37. };
  38. // null ref
  39. yield return default(OpMaterialSpecificationType);
  40. // Class and definition specificed
  41. yield return new OpMaterialSpecificationType
  42. {
  43. MaterialClassID = materialClassId,
  44. MaterialDefinitionID = materialDefinitionId,
  45. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  46. .First()
  47. };
  48. // invalid Quantitities
  49. foreach (var invalidOpMaterialSpecificationType in QuantityValueTypeDataGenerator
  50. .GenerateInvalidQuantityValueTypes()
  51. .Where(t => t != null)
  52. .Select(quantity => new OpMaterialSpecificationType
  53. {
  54. ID = materialSpecficationId,
  55. MaterialClassID = materialClassId,
  56. Quantity = new[]
  57. {
  58. quantity
  59. },
  60. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  61. .First()
  62. }))
  63. {
  64. yield return invalidOpMaterialSpecificationType;
  65. }
  66. // invalid hierarchy scopes
  67. foreach (var invalidOpMaterialSpecificationType in HierarchyScopeTypeDataGenerator
  68. .GenerateInvalidHierarchyScopeTypes()
  69. .Where(q => q != null)
  70. .Select(hierarchyScope => new OpMaterialSpecificationType
  71. {
  72. ID = materialSpecficationId,
  73. MaterialClassID = materialClassId,
  74. HierarchyScope = hierarchyScope
  75. }))
  76. {
  77. yield return invalidOpMaterialSpecificationType;
  78. }
  79. // invalid properties
  80. foreach (var invalidOpMaterialSpecificationType in OpMaterialSpecificationPropertyTypeDataGenerator
  81. .GenerateInvalidOpMaterialSpecificationPropertyTypes()
  82. .Where(q => q != null)
  83. .Select(property => new OpMaterialSpecificationType
  84. {
  85. ID = materialSpecficationId,
  86. MaterialClassID = materialClassId,
  87. MaterialSpecificationProperty = new[]
  88. {
  89. property
  90. },
  91. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  92. .First()
  93. }))
  94. {
  95. yield return invalidOpMaterialSpecificationType;
  96. }
  97. }
  98. /// <summary>
  99. /// Generates the valid op material specification type arrays.
  100. /// </summary>
  101. /// <returns>System.Collections.Generic.IEnumerable&lt;OpMaterialSpecificationType[]&gt;.</returns>
  102. public static IEnumerable<OpMaterialSpecificationType[]> GenerateValidOpMaterialSpecificationTypeArrays()
  103. {
  104. //empty, 1, and 2 records
  105. for (var i = 3 - 1; i >= 0; i--)
  106. {
  107. var vals = new OpMaterialSpecificationType[i];
  108. for (var j = 0; j < vals.Length; j++)
  109. {
  110. vals[j] = new OpMaterialSpecificationType
  111. {
  112. ID = new IdentifierType
  113. {
  114. Value = $"Specification.ID.{i}.{j}"
  115. },
  116. MaterialClassID = GenerateValidMaterialClassIdTypeArrays()
  117. .FirstOrDefault(p => p?.Length == 2),
  118. Description = DescriptionTypeDataGenerator.GenerateValidDescriptionTypeArrays()
  119. .FirstOrDefault(p => p?.Length == 2),
  120. MaterialUse = new MaterialUseType
  121. {
  122. Value = Domain.Client.MaterialUseType.Produced.ToString()
  123. },
  124. Quantity = QuantityValueTypeDataGenerator.GenerateValidQuantityValueTypeArrays()
  125. .FirstOrDefault(p => p?.Length == 2),
  126. SpatialLocation = GeoSpatialDesignationTypeDataGenerator
  127. .GenerateValidGeospatialDesignationTypes()
  128. .First(),
  129. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  130. .First(),
  131. MaterialSpecificationProperty = OpMaterialSpecificationPropertyTypeDataGenerator
  132. .GenerateValidOpMaterialSpecificationPropertyTypeArrays()
  133. .FirstOrDefault(p => p?.Length == 2)
  134. };
  135. }
  136. yield return vals;
  137. }
  138. }
  139. /// <summary>
  140. /// Generates the valid op material specification types.
  141. /// </summary>
  142. /// <returns>System.Collections.Generic.IEnumerable&lt;OpMaterialSpecificationType&gt;.</returns>
  143. public static IEnumerable<OpMaterialSpecificationType> GenerateValidOpMaterialSpecificationTypes()
  144. {
  145. // All fields populated and combinations of collections
  146. // empty
  147. // one
  148. // multiple
  149. for (var i = 3 - 1; i >= 0; i--)
  150. {
  151. yield return new OpMaterialSpecificationType
  152. {
  153. ID = new IdentifierType
  154. {
  155. Value = $"Specification.ID.{i}"
  156. },
  157. MaterialDefinitionID = GenerateValidMaterialDefinitionIdTypeArrays()
  158. .FirstOrDefault(p => p?.Length == 1),
  159. Description = DescriptionTypeDataGenerator.GenerateValidDescriptionTypeArrays()
  160. .FirstOrDefault(p => p?.Length == i),
  161. MaterialUse = new MaterialUseType
  162. {
  163. Value = Domain.Client.MaterialUseType.Produced.ToString()
  164. },
  165. Quantity = QuantityValueTypeDataGenerator.GenerateValidQuantityValueTypeArrays()
  166. .FirstOrDefault(p => p?.Length == i),
  167. SpatialLocation = GeoSpatialDesignationTypeDataGenerator.GenerateValidGeospatialDesignationTypes()
  168. .First(),
  169. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  170. .First(),
  171. MaterialSpecificationProperty = OpMaterialSpecificationPropertyTypeDataGenerator
  172. .GenerateValidOpMaterialSpecificationPropertyTypeArrays()
  173. .FirstOrDefault(p => p?.Length == i),
  174. AssemblyType = new AssemblyTypeType
  175. {
  176. Value = AssemblyType.Other.ToString()
  177. },
  178. AssemblyRelationship = new AssemblyRelationshipType
  179. {
  180. Value = Domain.Client.AssemblyRelationshipType.Permanent.ToString()
  181. },
  182. AssemblySpecification = GenerateValidOpMaterialSpecificationTypeArrays()
  183. .FirstOrDefault(c => c.Length == i)
  184. };
  185. }
  186. // basic with only mandatory fields
  187. yield return new OpMaterialSpecificationType
  188. {
  189. ID = new IdentifierType
  190. {
  191. Value = "Specification.ID"
  192. },
  193. HierarchyScope = HierarchyScopeTypeDataGenerator.GenerateValidHierarchyScopeTypes()
  194. .First()
  195. };
  196. }
  197. /// <summary>
  198. /// Generates the valid material class identifier type arrays.
  199. /// </summary>
  200. /// <returns>System.Collections.Generic.IEnumerable&lt;MaterialClassIDType[]&gt;.</returns>
  201. private static IEnumerable<MaterialClassIDType[]> GenerateValidMaterialClassIdTypeArrays()
  202. {
  203. // null, empty, 1, and 2 records
  204. yield return null;
  205. for (var i = 0; i < 3; i++)
  206. {
  207. var vals = new MaterialClassIDType[i];
  208. for (var j = 0; j < vals.Length; j++)
  209. {
  210. vals[j] = new MaterialClassIDType
  211. {
  212. Value = $"MaterialClassID.{j}"
  213. };
  214. }
  215. yield return vals;
  216. }
  217. }
  218. /// <summary>
  219. /// Generates the valid material definition identifier type arrays.
  220. /// </summary>
  221. /// <returns>System.Collections.Generic.IEnumerable&lt;MaterialDefinitionIDType[]&gt;.</returns>
  222. private static IEnumerable<MaterialDefinitionIDType[]> GenerateValidMaterialDefinitionIdTypeArrays()
  223. {
  224. // 1, and 2 records
  225. for (var i = 1; i < 3; i++)
  226. {
  227. var vals = new MaterialDefinitionIDType[i];
  228. for (var j = 0; j < vals.Length; j++)
  229. {
  230. vals[j] = new MaterialDefinitionIDType
  231. {
  232. Value = $"MaterialDefinitionID.{j}"
  233. };
  234. }
  235. yield return vals;
  236. }
  237. }
  238. #endregion
  239. }
  240. }