3 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 namespace Sage.
ES.S50.UnitTest
29 static partial class ExtensionesTest
31 #region Extensiones de entorno de test 34 private static bool _CargaEjecutada =
false;
40 public static void __Test_LoadRandomConfig(
this TestContext toContexto)
52 var claveDePruebaPresente = Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_ConfigUnitTestLoaded",
false));
53 if (claveDePruebaPresente)
59 __Test_LoadRandomConfigWithoutDictionary(toContexto);
63 LICENCIAS._ObtenerLicenciaActual();
64 if (!LICENCIAS._Validar_Licencia_Suscripcion())
65 Assert.Fail(
"Error al validar la licencia de suscripción.");
68 _CargaEjecutada =
true;
69 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_ConfigUnitTestLoaded",
true);
73 public static void __Test_LoadRandomConfigWithoutDictionary(
this TestContext toContexto)
75 string lcEmpresa =
System.Configuration.ConfigurationManager.AppSettings[
"_Empresa"].ToString();
76 string lcCaja =
System.Configuration.ConfigurationManager.AppSettings[
"_Caja"].ToString();
77 string lcXmlConfig =
System.Configuration.ConfigurationManager.AppSettings[
"_XmlConfig"].ToString();
80 __Test_SQLConnect(toContexto);
81 if (
string.IsNullOrWhiteSpace(lcEmpresa))
82 lcEmpresa = EmpresaAleatoria(toContexto);
83 if (
string.IsNullOrWhiteSpace(lcCaja))
84 lcCaja = CajaAleatoria(toContexto);
86 string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
87 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
88 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_usuario",
"SUPERVISOR");
89 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_pathinicio", dirName);
90 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_iniservidor", dirName);
91 EW_GLOBAL.ValorEnClave_VarGlob(
"wn_TipoProd", 2);
93 InitializeDependencyInjectionMock();
98 if (!
string.IsNullOrWhiteSpace(lcXmlConfig) && File.Exists(lcXmlConfig))
99 EW_GLOBAL._CargarVarExtra(lcXmlConfig);
103 EW_GLOBAL._Empresa =
new sage.
ew.
empresa.
Empresa(Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa")));
105 public static void __Test_SQLConnect(
this TestContext toContexto)
107 string lcServer =
System.Configuration.ConfigurationManager.AppSettings[
"_Server"].ToString();
108 string lcUser =
System.Configuration.ConfigurationManager.AppSettings[
"_User"].ToString();
109 string lcPass =
System.Configuration.ConfigurationManager.AppSettings[
"_Pass"].ToString();
110 string lcComunes =
System.Configuration.ConfigurationManager.AppSettings[
"_Comunes"].ToString();
112 if (DB.SQLChangeConnection(
"eurowin"))
116 DB.SQLConnect(lcServer, lcUser, lcPass, lcComunes, tcAliasConexion:
"eurowin");
119 public static void LoadAddons()
121 string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
122 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_pathinicio", dirName);
123 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_iniservidor", dirName);
127 GetSage50PathLibrerias = FUNCTIONS.GetSage50PathLibrerias,
128 CodigoLicencia = LICENCIAS._CodigoLicencia
150 public static string __FieldAleatorioNew(
this TestContext toContexto,
string tcDataBase,
string tcTable,
string tcField =
"CODIGO",
int tnLenCampoEntero = 9)
152 int lnLen = 0, lnMax = 0, lnCont = 0;
153 bool lltrobat =
false;
154 DataTable ldtTemp =
new DataTable();
155 string lcCodigo =
string.Empty;
156 string lcSql =
"SELECT a.*,b.name as tipo_campo " 157 +
" FROM " + DB.SQLDatabase(tcDataBase,
"columns",
true) +
" as a inner join " + DB.SQLDatabase(tcDataBase,
"types",
true) +
" as b on a.system_type_id=b.system_type_id " 158 +
" WHERE [object_id] = (select object_id from " + DB.SQLDatabase(tcDataBase,
"tables",
true) +
" as c where c.name=" + DB.SQLString(tcTable) +
") AND a.name=" + DB.SQLString(tcField) +
";";
159 DB.SQLExec(lcSql, ref ldtTemp);
161 if (ldtTemp != null && ldtTemp.Rows.Count > 0)
163 if (ldtTemp.Rows[0][
"tipo_campo"].ToString().Contains(
"char") || ldtTemp.Rows[0][
"tipo_campo"].ToString().Contains(
"text"))
166 System.Reflection.PropertyInfo loPropiedad = typeof(String).GetType().GetProperty(
"Chars");
167 if (ldtTemp.Rows[0][
"tipo_campo"].ToString().Contains(
"text"))
168 lnLen =
Int32.MaxValue;
170 lnLen = Convert.ToInt32(ldtTemp.Rows[0][
"max_length"].ToString());
172 lnMax = (lnLen ==
Int32.MaxValue) ? 1000 : (
int)Math.Pow(10, lnLen) - 1;
178 lcCodigo = Guid.NewGuid().ToString().ToUpper();
179 if (lcCodigo.Length > lnLen)
180 lcCodigo = lcCodigo.Substring(0, lnLen);
181 string loTemp = DB.SQLValor(tcTable, tcField, lcCodigo, tcField, tcDataBase).ToString();
182 if (!
string.IsNullOrWhiteSpace(loTemp))
188 lcCodigo =
string.Empty;
195 else if (ldtTemp.Rows[0][
"tipo_campo"].ToString().Contains(
"int"))
198 Random r =
new Random();
200 lnLen = tnLenCampoEntero > 0 ? tnLenCampoEntero : 9;
201 lnMax = (int)Math.Pow(10, lnLen) - 1;
205 lcCodigo = r.Next(0,
Int32.MaxValue).ToString();
206 if (lcCodigo.Length > lnLen)
207 lcCodigo = lcCodigo.Substring(0, lnLen);
208 string loTemp = DB.SQLValor(tcTable, tcField, lcCodigo, tcField, tcDataBase).ToString();
209 if (!
string.IsNullOrWhiteSpace(loTemp) && loTemp !=
"0")
215 lcCodigo =
string.Empty;
234 public static string __FieldAleatorio(
this TestContext toContexto,
string tcDataBase,
string tcTable,
string tcField =
"CODIGO")
236 string lcCodigoAleatoria =
string.Empty;
238 string lcSql =
string.Empty;
239 DataTable ldtResult =
new DataTable();
241 lcSql =
"SELECT " + tcField +
" FROM " + DB.SQLDatabase(tcDataBase, tcTable) +
" WHERE " + tcField +
" <> ''";
242 llOk = DB.SQLExec(lcSql, ref ldtResult);
243 if (llOk && ldtResult.Rows.Count > 0)
245 int lnMax = ldtResult.Rows.Count;
246 Random loRand =
new Random();
247 int lnRandomIndex = loRand.Next(0, lnMax);
249 lcCodigoAleatoria = ldtResult.Rows[lnRandomIndex][tcField].ToString();
253 return lcCodigoAleatoria;
265 public static object __FieldDatabase(
this TestContext toContexto,
string tcDataBase,
string tcTable,
string valueFiltro,
string tcFieldFiltro =
"CODIGO",
string tcFieldReturn =
"NOMBRE")
267 object oFieldValue =
new object();
269 string lcSql =
string.Empty;
270 DataTable ldtResult =
new DataTable();
272 lcSql =
"SELECT " + tcFieldReturn +
" FROM " + DB.SQLDatabase(tcDataBase, tcTable) +
" WHERE " + tcFieldFiltro +
" = '" + valueFiltro.Trim() +
"'";
273 llOk = DB.SQLExec(lcSql, ref ldtResult);
274 if (llOk && ldtResult.Rows.Count > 0)
276 oFieldValue = ldtResult.Rows[0][tcFieldReturn];
287 public static string __AnteriorEjercicio(
this TestContext toContexto)
289 return DB._AnteriorEjercicio();
296 public static string __SiguienteEjercicio(
this TestContext toContexto)
298 return DB._SiguienteEjercicio();
305 public static string __ActualEjercicio(
this TestContext toContexto)
307 return DB.Ejercicio_EW;
314 public static bool __EsPenultimoEjercicio(
this TestContext toContexto)
316 return DB._EsPenultimoEjercicio();
323 private static string EmpresaAleatoria(
this TestContext toContexto)
325 return toContexto.__FieldAleatorio(
"GESTION",
"EMPRESA",
"CODIGO");
332 private static string CajaAleatoria(
this TestContext toContexto)
334 return toContexto.__FieldAleatorio(
"TPV",
"CAJAS",
"CODIGO");
337 #endregion Extensiones de entorno de test 345 public static void __Test_MayorQueZero(
this Control toControl,
string tcNombrePropiedad)
348 System.Reflection.PropertyInfo loPropiedades = toControl.GetType().GetProperty(tcNombrePropiedad);
351 bool llTipoCorrecto =
false;
353 llTipoCorrecto = (loPropiedades.PropertyType.Name ==
"Decimal" || loPropiedades.PropertyType.Name ==
"Int32");
354 Assert.AreEqual<
bool>(llTipoCorrecto,
true,
"Tipo " + loPropiedades.PropertyType.Name +
" no contemplado para unit test genericas.");
356 dynamic lnDefault = (dynamic)loPropiedades.GetValue(toControl, null);
357 dynamic lnZero = 0, lnNegativo = 0, lnPositivo = 0;
360 switch (loPropiedades.PropertyType.Name)
379 loPropiedades.SetValue(toControl, lnZero, null);
380 lnActual = (dynamic)loPropiedades.GetValue(toControl, null);
381 Assert.AreNotEqual<dynamic>(lnActual, lnZero,
"Propiedad " + tcNombrePropiedad +
" admite un valor 0");
384 loPropiedades.SetValue(toControl, lnNegativo, null);
385 lnActual = (dynamic)loPropiedades.GetValue(toControl, null);
386 Assert.AreNotEqual<dynamic>(lnActual, lnNegativo,
"Propiedad " + tcNombrePropiedad +
" admite negativos");
389 loPropiedades.SetValue(toControl, lnPositivo, null);
390 lnActual = (dynamic)loPropiedades.GetValue(toControl, null);
391 Assert.AreEqual<dynamic>(lnActual, lnPositivo,
"Propiedad " + tcNombrePropiedad +
" no asigna correctamente el valor");
399 public static void __Test_SoloGET<T>(
this Control toControl,
string tcNombrePropiedad)
402 System.Reflection.PropertyInfo loPropiedades = toControl.GetType().GetProperty(tcNombrePropiedad);
405 dynamic loDefault = loPropiedades.GetValue(toControl, null);
407 dynamic loNuevo = loPropiedades.__Get_Random_Value();
410 while (Equals(loDefault, loNuevo))
412 loNuevo = loPropiedades.__Get_Random_Value();
418 loPropiedades.SetValue(toControl, loNuevo, null);
419 Assert.Fail(
"No se ha disparado excepción al hacer un SET => Existe dicho método para la propiedad");
421 catch (ArgumentException loException)
424 Assert.AreEqual(
"No se puede encontrar el método Set de la propiedad.", loException.Message);
426 catch (Exception loException)
428 Assert.Fail(
string.Format(
"Excepción inesperada del tipo {0} mensage: {1}", loException.GetType(), loException.Message));
443 public static void __Test_GetSetValue(
this Control toControl,
string tcNombrePropiedad,
object toTestValue = null)
446 System.Reflection.PropertyInfo loPropiedad = toControl.GetType().GetProperty(tcNombrePropiedad);
449 if (toTestValue == null)
452 object loDefault = loPropiedad.GetValue(toControl, null);
454 object loNuevo = loPropiedad.__Get_Random_Value();
457 while (Equals(loDefault, loNuevo))
459 loNuevo = loPropiedad.__Get_Random_Value();
463 loPropiedad.SetValue(toControl, loNuevo, null);
466 dynamic loActual = loPropiedad.GetValue(toControl, null);
467 Assert.IsFalse(Equals(loDefault, loActual),
"El valor actual es igual al inicial. Revisar que no haya restricciones al hacer un SET de la propiedad." + Environment.NewLine +
468 "De ser así utiliza el parámetro opcional para suministrar un valor que cumpla las restricciones.");
471 Assert.AreEqual<dynamic>(loActual, loNuevo,
"La propiedad " + tcNombrePropiedad +
" no realiza correctamente operaciones de GET y SET");
474 if (loPropiedad.PropertyType.FullName ==
"System.String")
475 Assert.AreEqual<
int>(((string)loActual).Length, ((string)loNuevo).Length,
"La longitud no concuerda.");
480 loPropiedad.SetValue(toControl, toTestValue, null);
482 dynamic loActual = loPropiedad.GetValue(toControl, null);
485 Assert.AreEqual<dynamic>(loActual, toTestValue,
"La propiedad " + tcNombrePropiedad +
" no realiza correctamente operaciones de GET y SET");
491 public static void __Test_NumericUpDownBasics(
this Control toControl)
495 Assert.AreEqual<
bool>(
true, llOk,
"La clase del objeto no es ewNumericUpDown.");
507 private static object __Get_Random_Value(
this System.Reflection.PropertyInfo toPropiedad)
511 switch (toPropiedad.PropertyType.FullName)
513 case "System.String":
515 return Guid.NewGuid().ToString();
517 loRandom =
new Random();
518 return loRandom.Next();
520 loRandom =
new Random();
521 int lnNum = loRandom.Next(0, 26);
522 return (
char)(
'a' + lnNum);
523 case "System.Boolean":
524 loRandom =
new Random();
525 return loRandom.Next(0, 2) == 0;
526 case "System.Decimal":
527 loRandom =
new Random();
528 int lnPrecision = loRandom.Next(1,28);
529 int lnEscala = loRandom.Next(0, lnPrecision);
530 decimal lnDecimal = 0M;
532 for (
int lnIndPres = 0; lnIndPres < lnPrecision; lnIndPres++)
534 int lnDigito = loRandom.Next(0, 10);
535 lnDecimal = lnDecimal * 10M + lnDigito;
537 for (
int lnIndEsc = 0; lnIndEsc < lnEscala; lnIndEsc++)
545 Type elementType = _GetType(toPropiedad.PropertyType.FullName);
546 if (elementType != null)
549 return Activator.CreateInstance(elementType);
562 private static Type _GetType(
string typeName,
bool tlBuscarControles =
false)
564 var type = Type.GetType(typeName);
565 if (type != null)
return type;
567 if (!tlBuscarControles)
569 foreach (var a
in AppDomain.CurrentDomain.GetAssemblies())
571 type = a.GetType(typeName);
578 foreach (var a
in AppDomain.CurrentDomain.GetAssemblies())
581 type = a.GetType(typeName);
582 if (type != null)
return type;
584 type = a.GetType(a.GetName().Name +
"." + typeName);
585 if (type != null)
return type;
587 type = a.GetType(a.GetName().Name +
".UserControls." + typeName);
588 if (type != null)
return type;
590 type = a.GetType(a.GetName().Name +
".Clases." + typeName);
591 if (type != null)
return type;
596 public static void InitializeDependencyInjectionMock()
601 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
608 #region Extensiones para tipo OBJECT 616 public static void __Test_GetSetValue(
this Object toObjeto,
string tcNombrePropiedad,
object toTestValue = null)
619 System.Reflection.PropertyInfo loPropiedad = toObjeto.GetType().GetProperty(tcNombrePropiedad);
622 if (toTestValue == null)
625 object loDefault = loPropiedad.GetValue(toObjeto, null);
627 object loNuevo = loPropiedad.__Get_Random_Value();
630 while (Equals(loDefault, loNuevo))
632 loNuevo = loPropiedad.__Get_Random_Value();
636 loPropiedad.SetValue(toObjeto, loNuevo, null);
639 dynamic loActual = loPropiedad.GetValue(toObjeto, null);
640 Assert.IsFalse(Equals(loDefault, loActual),
"El valor actual es igual al inicial. Revisar que no haya restricciones al hacer un SET de la propiedad." + Environment.NewLine +
641 "De ser así utiliza el parámetro opcional para suministrar un valor que cumpla las restricciones.");
644 if (loPropiedad.PropertyType.FullName ==
"System.Decimal")
647 int lnNumDecimales = BitConverter.GetBytes(decimal.GetBits((decimal)loActual)[3])[2];
648 Assert.AreEqual<dynamic>(loActual,
Decimal.Round((decimal)loNuevo, lnNumDecimales),
"La propiedad " + tcNombrePropiedad +
" no realiza correctamente operaciones de GET y SET");
651 Assert.AreEqual<dynamic>(loActual, loNuevo,
"La propiedad " + tcNombrePropiedad +
" no realiza correctamente operaciones de GET y SET");
655 if (loPropiedad.PropertyType.FullName ==
"System.String")
656 Assert.AreEqual<
int>(((string)loActual).Length, ((string)loNuevo).Length,
"La longitud no concuerda.");
661 loPropiedad.SetValue(toObjeto, toTestValue, null);
663 dynamic loActual = loPropiedad.GetValue(toObjeto, null);
666 Assert.AreEqual<dynamic>(loActual, toTestValue,
"La propiedad " + tcNombrePropiedad +
" no realiza correctamente operaciones de GET y SET");
670 #endregion Extensiones para tipo OBJECT static string GenerarChecksumOpciones(string tcOpcion, string tcSalt)
PE-102978: Generar una función hash segura a partir de una opción y un salt
Classe empresa basada en sage.ew.ewmante
static AddonsController Instance
Instancia al objeto singleton Addons
Argumentos para los eventos lanzados por el addons en caso de error
bool _CargarAddOns(FunctionsDependencies loFuntionsDependencies)
Carga addons
Clase Singleton para la carga de los diccionarios
Clase sage.ew.objetos.ewnumericupdown
PE-85105: Clase donde se implementaran aquellas funciones de encriptación y desencriptación utilizand...
Interfaz de registro de tipos
static bool CargarDiccionarios(string tcempresa, string tcCajaTpv)
A partir de un código de empresa y un código de caja nos carga las variables de empresa, mascaras, anchuras de campos standar y de TPV
static IDiccionarioGlobal GetDiccionarioGlobal()
obtiene una instancia a diccionario global
Factoria de diccionarios estáticos
void RegisterTypes()
Registra tipos
IAddonsManager AddonsManager
Gestor de Addons
Dependencias con functions
bool _CargarAddons_WaitAll()
Esperar a que se hayan cargado todos los addons