FunctionsUnitTest.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Diagnostics;
6 using System.IO;
7 using System.Linq;
8 using System.Text;
9 using System.Text.RegularExpressions;
10 using System.Web.Script.Serialization;
11 
12 namespace Sage.ES.S50.UnitTest.Tools
13 {
17  public static partial class FunctionsUnitTest
18  {
19  private static string _cPantalla = string.Empty;
20 
27  public static void _ImportXMLToDataTable(string tcXmlFile, ref DataTable tdtDataTable, out string tcErrorMessage)
28  {
29  tcErrorMessage = "";
30 
31  if (!File.Exists(tcXmlFile))
32  {
33  tcErrorMessage = "El fichero '" + tcXmlFile + "' no existe.";
34  return;
35  }
36 
37  try
38  {
39  using (DataSet ds = new DataSet())
40  {
41  ds.ReadXml(tcXmlFile);
42 
43  if (ds != null && ds.Tables.Count > 0)
44  tdtDataTable = ds.Tables[0].Copy();
45  }
46  }
47  catch (Exception loEx)
48  {
49  tcErrorMessage = loEx.Message;
50  }
51  }
52 
58  public static string _GetXmlFolderMockTest(List<string> tlsMetodosExcluidos)
59  {
60  string lcFolder = "";
61 
62  if (tlsMetodosExcluidos == null)
63  tlsMetodosExcluidos = new List<string>();
64 
65  // A partir de la pila de llamadas, obtenemos el método del test unitario que originó la consulta desde dónde llegamos
66  // El nombre del método debe coincidir con la carpeta donde tendremos los ficheros XML.
67  StackTrace stackTrace = new StackTrace();
68  StackFrame[] loSt = stackTrace.GetFrames();
69  IEnumerable<StackFrame> loStUnitTest = loSt.AsEnumerable().Where(l => l.GetMethod().Module.Name == "Sage.ES.S50.UnitTest.dll" && !tlsMetodosExcluidos.Contains(l.GetMethod().Name));
70  lcFolder = loStUnitTest.FirstOrDefault().GetMethod().Name;
71 
72  return lcFolder;
73  }
74 
78  public static string _GetXmlFolderMockTest()
79  {
80  return _GetXmlFolderMockTest(null);
81  }
82 
86  public static string _Pantalla
87  {
88  get => _cPantalla;
89  set => _cPantalla = value;
90  }
91 
97  public static string PathXML()
98  {
99  return PathXML(_Pantalla);
100  }
101 
108  public static string PathXML(string tcPantalla)
109  {
110  string lcPathMockXml = "XML"; // SII
111 
112  switch (tcPantalla)
113  {
114  case "MODEL140":
115  lcPathMockXml = @"Mock\addons\factucert\140\XML";
116  break;
117 
118  case "MODEL240":
119  lcPathMockXml = @"Mock\addons\factucert\240\XML";
120  break;
121  }
122 
123  return Path.Combine(Directory.GetCurrentDirectory(), lcPathMockXml);
124  }
125  }
126 }