2 using System.Collections.Generic;
7 using Microsoft.VisualStudio.TestTools.UnitTesting;
10 namespace Sage.
ES.S50.UnitTest
12 static partial class ExtensionesTest
14 #region PE-93059 : Extensiones para tipo ewMante 20 public static void __Test_Constructores(
this ewMante toObjeto)
23 ConstructorInfo[] p = toObjeto.GetType().GetConstructors();
25 Assert.Inconclusive(
"El mantenimiento debe tener como mínimo dos constructores (con y sin código)");
37 public static void __Test_EwMante_New(
this IMante toObjeto,
string tcCodigo,
bool tlDeleteOnFinish =
true, RequiredValues toRequiredValues = null)
39 Type loType = toObjeto.GetType();
40 IMante target = (
IMante)Activator.CreateInstance(loType);
41 IMante loadedTarget = (
IMante)Activator.CreateInstance(loType);
45 bool llResult =
false;
46 string newNombre =
"Registro para " + tcCodigo;
50 Assert.AreEqual<
bool>(
false, target.
_Existe_Registro(),
"No se ha puede hacer el test _New puesto que el código " + tcCodigo +
" ya existe en la base de datos");
53 llResult = target.
_Save();
54 Assert.AreEqual<
bool>(
false, llResult,
"Se ha guardado el registro con código " + tcCodigo +
" sin definir su nombre");
59 toRequiredValues?.FillRequiredValues(target);
60 llResult = target.
_Save();
61 Assert.AreEqual<
bool>(
true, llResult,
"No se ha guardado el nuevo registro con código " + tcCodigo +
". _Error_Message:" + target.
_Error_Message);
63 loadedTarget.
_Codigo = tcCodigo;
66 Assert.AreEqual<
bool>(
true, loadedTarget.
_Existe_Registro(),
"No se ha encontrado el nuevo registro '" + loadedTarget.
_Codigo +
"' en la base de datos");
67 Assert.AreEqual<
string>(tcCodigo, loadedTarget.
_Codigo,
"El campo _Codigo no coincide (" + loadedTarget.
_Codigo +
" - " + tcCodigo +
").");
68 Assert.AreEqual<
string>(newNombre, loadedTarget.
_Nombre,
"El campo _Nombre no coincide (" + loadedTarget.
_Nombre +
" - " + newNombre +
").");
74 Assert.AreEqual<
bool>(
false, loadedTarget.
_Existe_Registro(),
"No se ha borrado el registro '" + loadedTarget.
_Codigo +
"' de la base de datos. _Error_Message:" + target.
_Error_Message);
85 public static void __Test_EwMante_Load(
this IMante toObjeto,
string tcCodigo,
string tcCodigoNew =
"", RequiredValues toRequiredValues = null)
87 Type loType = toObjeto.GetType();
88 IMante target = (
IMante)Activator.CreateInstance(loType);
90 bool llDelete =
false;
91 if (
string.IsNullOrWhiteSpace(tcCodigo))
93 Assert.AreNotEqual<
string>(
String.Empty, tcCodigoNew,
"Load generando registro: No se ha pasado el código para generar un nuevo registro");
95 Assert.AreEqual<
bool>(
false, target.
_Existe_Registro(),
"Load generando registro: Se ha encontrado el registro '" + tcCodigo +
"' en la base de datos");
96 toObjeto.__Test_EwMante_New(tcCodigoNew, tlDeleteOnFinish:
false, toRequiredValues: toRequiredValues);
97 tcCodigo = tcCodigoNew;
103 Assert.AreEqual<
bool>(
true, target.
_Existe_Registro(),
"No se ha encontrado el registro '" + tcCodigo +
"' en la base de datos");
108 Assert.AreEqual<
string>(tcCodigo, target.
_Codigo,
"El campo _Codigo no coincide (" + tcCodigo +
").");
109 Assert.AreNotEqual<
string>(
String.Empty, target.
_Nombre,
"El campo _Nombre esta vacío (" + tcCodigo +
")");
113 IMante loadedTarget = (
IMante)Activator.CreateInstance(loType);
115 loadedTarget.
_Codigo = tcCodigo;
116 loadedTarget.
_Load();
119 Assert.AreEqual<
bool>(
false, loadedTarget.
_Existe_Registro(),
"Load generando registro: No se ha borrado el registro '" + loadedTarget.
_Codigo +
"' de la base de datos. _Error_Message:" + loadedTarget.
_Error_Message);
130 public static void __Test_EwMante_Save(
this IMante toObjeto,
string tcCodigo,
string tcCodigoNew =
"", RequiredValues toRequiredValues = null)
132 Type loType = toObjeto.GetType();
133 IMante target = (
IMante)Activator.CreateInstance(loType);
134 IMante loadedTarget = (
IMante)Activator.CreateInstance(loType);
136 bool llDelete =
false;
137 if (
string.IsNullOrWhiteSpace(tcCodigo))
139 Assert.AreNotEqual<
string>(
String.Empty, tcCodigoNew,
"Save generando registro: No se ha pasado el código para generar un nuevo registro");
141 Assert.AreEqual<
bool>(
false, target.
_Existe_Registro(),
"Save generando registro: Se ha encontrado el registro '" + tcCodigo +
"' en la base de datos");
142 toObjeto.__Test_EwMante_New(tcCodigoNew, tlDeleteOnFinish:
false, toRequiredValues: toRequiredValues);
143 tcCodigo = tcCodigoNew;
147 string lcNombreOriginal =
string.Empty;
148 string lcNombreModificado =
string.Empty;
153 Assert.AreEqual<
bool>(
true, target.
_Existe_Registro(),
"No se ha encontrado el registro '" + tcCodigo +
"' en la base de datos");
156 Assert.AreNotEqual<
string>(
String.Empty, target.
_Nombre,
"El campo _Nombre del registro esta vacío (" + tcCodigo +
")");
158 lcNombreOriginal = target.
_Nombre;
160 if (lcNombreOriginal.StartsWith(
"(TEST)"))
161 lcNombreModificado = lcNombreOriginal.Substring(6);
163 lcNombreModificado =
"(TEST)" + lcNombreOriginal;
164 target.
_Nombre = lcNombreModificado;
168 loadedTarget.
_Codigo = tcCodigo;
169 loadedTarget.
_Load();
172 if (loadedTarget.
_Nombre.Length < lcNombreModificado.Length)
173 lcNombreModificado = loadedTarget.
_Nombre;
175 Assert.AreNotEqual<
string>(
String.Empty, loadedTarget.
_Nombre,
"El campo _Nombre del registro modificado esta vacío (" + tcCodigo +
")");
177 Assert.AreEqual<
string>((lcNombreModificado.Length > loadedTarget.
_Nombre.Length) ?
178 lcNombreModificado.Substring(6, loadedTarget.
_Nombre.Length) :
179 lcNombreModificado, loadedTarget.
_Nombre,
"El campo _Nombre del registro modificado no coincide (" + tcCodigo +
").");
184 target.
_Nombre = lcNombreOriginal;
190 loadedTarget = (
IMante)Activator.CreateInstance(loType);
191 loadedTarget.
_Codigo = tcCodigo;
192 loadedTarget.
_Load();
193 Assert.AreNotEqual<
string>(
String.Empty, loadedTarget.
_Nombre,
"El campo _Nombre del registro modificado esta vacío (" + tcCodigo +
")");
194 Assert.AreEqual<
string>((lcNombreOriginal.Length > loadedTarget.
_Nombre.Length) ?
195 lcNombreOriginal.Substring(0, loadedTarget.
_Nombre.Length) :
196 lcNombreOriginal, loadedTarget.
_Nombre,
"El campo _Nombre del registro modificado no coincide (" + tcCodigo +
").");
200 IMante loadedTarget2 = (
IMante)Activator.CreateInstance(loType);
202 loadedTarget2.
_Codigo = tcCodigo;
203 loadedTarget2.
_Load();
206 Assert.AreEqual<
bool>(
false, loadedTarget2.
_Existe_Registro(),
"Load generando registro: No se ha borrado el registro '" + loadedTarget2.
_Codigo +
"' de la base de datos. _Error_Message:" + loadedTarget2.
_Error_Message);
218 public static void __Test_EwMante_Delete(
this IMante toObjeto,
string tcCodigo,
string tcCodigoNew =
"", RequiredValues toRequiredValues = null)
220 Type loType = toObjeto.GetType();
221 IMante target = (
IMante)Activator.CreateInstance(loType);
222 IMante loadedTarget = (
IMante)Activator.CreateInstance(loType);
224 bool llDelete =
false;
225 if (
string.IsNullOrWhiteSpace(tcCodigo))
227 Assert.AreNotEqual<
string>(
String.Empty, tcCodigoNew,
"Delete generando registro: No se ha pasado el código para generar un nuevo registro");
229 Assert.AreEqual<
bool>(
false, target.
_Existe_Registro(),
"Delete generando registro: Se ha encontrado el registro '" + tcCodigo +
"' en la base de datos");
230 toObjeto.__Test_EwMante_New(tcCodigoNew, tlDeleteOnFinish:
false, toRequiredValues: toRequiredValues);
231 tcCodigo = tcCodigoNew;
241 target.
_Nombre =
"Registro temporal";
242 toRequiredValues?.FillRequiredValues(target);
245 Assert.AreEqual<
bool>(
true, target.
_Existe_Registro(),
"No se ha puede hacer el test _Delete puesto que no se ha podido crear el registro con código " + tcCodigo);
251 loadedTarget.
_Load();
257 Assert.AreEqual<
bool>(
false, target.
_Existe_Registro(),
"No se ha borrado el registro con código " + tcCodigo +
". _Error_Message:" + target.
_Error_Message);
259 if (!
string.IsNullOrWhiteSpace(loadedTarget.
_Codigo))
261 loadedTarget.
_Save();
262 Assert.AreEqual<
bool>(
true, loadedTarget.
_Existe_Registro(),
"No se ha podido regenerar el registro con código " + tcCodigo +
". _Error_Message:" + target.
_Error_Message);
268 Assert.AreNotEqual<
string>(
String.Empty, target.
_Error_Message,
"No se ha borrado el registro con código " + tcCodigo +
" ni se ha informado el porque en _Error_Message");
273 IMante loadedTarget2 = (
IMante)Activator.CreateInstance(loType);
275 loadedTarget2.
_Codigo = tcCodigo;
276 loadedTarget2.
_Load();
279 Assert.AreEqual<
bool>(
false, loadedTarget2.
_Existe_Registro(),
"Load generando registro: No se ha borrado el registro '" + loadedTarget2.
_Codigo +
"' de la base de datos. _Error_Message:" + loadedTarget2.
_Error_Message);
289 public static void __Test_EwMante_New_Load_Save_Delete(
this IMante toObjeto,
string tcNewCodigo,
string tcRandomCodigo, RequiredValues toRequiredValues = null)
292 toObjeto.__Test_EwMante_New(tcNewCodigo,
true,toRequiredValues);
294 toObjeto.__Test_EwMante_Load(tcRandomCodigo, tcNewCodigo, toRequiredValues);
296 toObjeto.__Test_EwMante_Save(tcRandomCodigo, tcNewCodigo, toRequiredValues);
298 toObjeto.__Test_EwMante_Delete(tcNewCodigo,
"", toRequiredValues);
299 toObjeto.__Test_EwMante_Delete(tcRandomCodigo, tcNewCodigo, toRequiredValues);
302 #endregion PE-93059 : Extensiones para tipo ewMante string _Nombre
Campo de la tabla que representa el "Nombre" del mantenimiento. Por defecto siempre es NOMBRE ...
bool _Existe_Registro()
Nos indica si existe el registro en la Base de Datos
Clase de negocio base para mantenimientos
Nueva interficie madre de IMantes y de la que colgara ewMante. Propiedades: _Codigo, _Nombre, _Error_Message. Metodos: _New, Save, _Delete, _Load, _Existe_Registro, _Clonar
string _Codigo
Campo de la tabla que representa el "Código" del mantenimiento. Por defecto siempre es CODIGO ...
bool _Delete()
Elimina el registro actual
string _Error_Message
Campo donde se informará de los errores en mantenimientos.
bool _Save()
Guarda el registro actual en la tabla asociada
void _Load()
Carga el registro actual de la tabla asociada