|
From: <sv...@de...> - 2005-06-28 20:55:17
|
Author: pcamacho
Date: 2005-06-28 16:55:22 -0400 (Tue, 28 Jun 2005)
New Revision: 1432
Modified:
humano2/trunk/components/tests/Makefile
humano2/trunk/components/tests/viewTools.cs
humano2/trunk/components/viewTools/ViewTools.cs
Log:
ADD: first tests for viewtools.
Modified: humano2/trunk/components/tests/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/trunk/components/tests/Makefile 2005-06-28 16:37:26 UTC (rev =
1431)
+++ humano2/trunk/components/tests/Makefile 2005-06-28 20:55:22 UTC (rev =
1432)
@@ -24,6 +24,6 @@
all: $(dll)
=20
$(dll): *.cs
- $(csc) /out:$@ $(opts) /t:library /doc:$(docdir)/$(namespace).xml /r:Sy=
stem.Data,$(extdir)/nunit/nunit.framework $(dlllist) $^
+ $(csc) /out:$@ $(opts) /t:library /doc:$(docdir)/$(namespace).xml /r:Sy=
stem.Data,$(extdir)/nunit/nunit.framework $(dlllist) /r:$(bindir)/Humano2=
.Core.Db.dll /r:$(bindir)/Humano2.Core.dll $^
=20
-.PHONY: all
\ No newline at end of file
+.PHONY: all
Modified: humano2/trunk/components/tests/viewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/trunk/components/tests/viewTools.cs 2005-06-28 16:37:26 UTC (=
rev 1431)
+++ humano2/trunk/components/tests/viewTools.cs 2005-06-28 20:55:22 UTC (=
rev 1432)
@@ -12,6 +12,8 @@
=20
using System;
using System.Data;
+using Humano2.Core;
+using Humano2.Core.Db;
using Humano2.Components.ViewTools;
using NUnit.Framework;
=20
@@ -20,90 +22,145 @@
/// <summary>
/// Summary description for ViewTools.
/// </summary>
+ [TestFixture]
public class ViewTools
{
- [Test]
- [Ignore("Aun no definidos los parametros de entrada")]
- public string GenerarConsultaSimple()
- {
- DataTable tabla =3D new DataTable();
- DataColumn columna;
- string[] fila =3D {"26"};
- string respuesta;
- Humano2.Components.ViewTools.ViewTools vtInstancia;
- =09
- columna =3D new DataColumn("columna",typeof(string));
- tabla.Columns.Add(columna);
- columna =3D new DataColumn("filtros",typeof(string));
- tabla.Columns.Add(columna);
- tabla.Rows.Add(fila);
+ private absCrud crud =3D null;
+ private absComplex complex =3D null;
+ =20
+ private void init()
+ {
+ complex =3D Factory.Complex();
+ crud =3D complex.GetCore().Crud; =20
+ }
+ =20
+ [Test]
+ public void SQLSelect()
+ {
+ init(); =20
+ =20
+ Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
+ vt.Complex =3D complex;
+ vt.KeyFlag =3D 0;
+ =20
+ //Simple columns
+ string strSelect =3D vt.SQLSelect("10181");
+ Logger.Log("SQLSelect(\"10181\"): " + strSelect,LogLevel.Tra=
ce);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\"".Trim());
+ strSelect =3D vt.SQLSelect("0,10181");
+ Logger.Log("SQLSelect(\"0,10181\"): " + strSelect,LogLevel.T=
race);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".id_entity, \"d10160cTicket\".\"c10162Title\"".Trim());
+ =20
+ //Pertinence columns
+ strSelect =3D vt.SQLSelect("10231");
+ Logger.Log("SQLSelect(\"10231\"): " + strSelect,LogLevel.Tra=
ce);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Assigned to3\"".Trim());
+ =20
+ strSelect =3D vt.SQLSelect("10231^18");
+ Logger.Log("SQLSelect(\"10231^18\"): " + strSelect,LogLevel.=
Trace);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"user\".\"ema=
il\"".Trim());
+ =20
+ strSelect =3D vt.SQLSelect("10181,10231^18");
+ Logger.Log("SQLSelect(\"10181,10231^18\"): " + strSelect,Log=
Level.Trace);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\", \"user\".\"email\"".Trim());
+ =20
+ strSelect =3D vt.SQLSelect("10187^10179");
+ Logger.Log("SQLSelect(\"10187^10179\"): " + strSelect,LogLev=
el.Trace);
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t Status\".\"c10163Status Name\"".Trim());
+ }
+ =20
+ [Test]
+ public void SQLWhere()
+ {
+ init(); =20
+ =20
+ Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
+ vt.Complex =3D complex;
+ vt.KeyFlag =3D 0;
+ =20
+ //Simple conditions
+ string strWhere =3D vt.SQLWhere("10187^10179|7|'closed'|0|0"=
);
+ Logger.Log("SQLWhere(\"10187^10179|7|'closed'|0|0\"):" + str=
Where, LogLevel.Trace);
+ Assert.IsTrue(strWhere.Trim() =3D=3D "WHERE \"d10160cTicket =
Status\".\"c10163Status Name\" ILIKE '%closed%'".Trim());
+ =20
+ =20
+ //Double conditions
+ strWhere =3D vt.SQLWhere("10187^10179|7|'closed'|1|0;10181|4=
|'Joli ticket'|0|0");
+ Logger.Log("SQLWhere(\"10187^10179|7|'closed'|1|0;10181|4|'J=
oli ticket'|0|0\"):" + strWhere, LogLevel.Trace);
+ Assert.IsTrue(strWhere.Trim() =3D=3D "WHERE \"d10160cTicket =
Status\".\"c10163Status Name\" ILIKE '%closed%' AND \"d10160cTicket\".\"c=
10162Title\" =3D 'Joli ticket'".Trim()); =20
+ }
+ =20
+ [Test]
+ public void SQLOrderBy()
+ {
+ init(); =20
+ Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
+ vt.Complex =3D complex;
+ vt.KeyFlag =3D 0;
+ =20
+ string strOrder =3D vt.SQLOrderBy(" 10181|0,10208|1");
+ Logger.Log("SQLWhere(\"10181|0,10208|1\"):" + strOrder, LogL=
evel.Trace);
+ Assert.IsTrue(strOrder.Trim() =3D=3D "ORDER BY upper(\"d1016=
0cTicket\".\"c10162Title\") asc , upper(\"d10160cTicket\".\"c10162Date\")=
desc".Trim());
+ }
+ =20
+ [Test]
+ public void SQLFrom()
+ {
+ init(); =20
+ Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
+ vt.Complex =3D complex;
+ vt.KeyFlag =3D 0; =20
+ string strFrom =3D vt.SQLFrom("0,10181,10208,10231^18,10209"=
,"10187^10179|7|'closed'|0|0");
+ Logger.Log("SQLFrom(\"0,10181,10208,10231^18,10209\",\"10187=
^10179|7|'closed'|0|0\");" + strFrom, LogLevel.Trace);
+ =20
+ Assert.IsTrue(strFrom.Trim() =3D=3D "FROM \"d10160cTicket\" =
inner join \"entity\" on \"d10160cTicket\".id_entity =3D \"entity\".id_en=
tity and entity.\"delDate\" is null LEFT JOIN \"user\" ON \"d10160cTick=
et\".\"c10162Assigned to3\" =3D \"user\".id_entity LEFT JOIN entity e1 ON=
\"user\".id_entity =3D e1.id_entity LEFT JOIN \"d10160cTicket Status\" =
ON \"d10160cTicket\".\"c10162Status\" =3D \"d10160cTicket Status\".id_ent=
ity LEFT JOIN entity e2 ON \"d10160cTicket Status\".id_entity =3D e2.id_e=
ntity".Trim());
+ }
+ =20
+ [Test]
+ public void ParseQuery()
+ {
+ init(); =20
+ Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
+ vt.Complex =3D complex;
+ vt.KeyFlag =3D 0; =20
+ DataTable dtParam =3D this.makeDataTableInViewTools();
+ DataRow dr =3D dtParam.NewRow();
+ =20
+ dr["columna"] =3D "0,10181,10208,10231^18,10209";
+ dr["filtros"] =3D "10187^10179|7|'closed'|0|0";
+ //dr["group"] =3D "";
+ //dr["having"] =3D "";
+ dr["order"] =3D "10231^18|0";
=20
- vtInstancia =3D new Humano2.Components.ViewTools.ViewTools(1);
- respuesta =3D vtInstancia.GetSQLString(tabla).ToUpper();
- return respuesta;
- }
-
- [Test]
- [Ignore("Aun no definidos los parametros de entrada")]
- public string GenerarConsultaConFiltro()
- {
- DataTable tabla =3D new DataTable();
- DataColumn columna;
- string[] fila =3D {"21","20|5|'1'"};
- string respuesta;
- Humano2.Components.ViewTools.ViewTools vtInstancia;
- =09
- columna =3D new DataColumn("columna",typeof(string));
- tabla.Columns.Add(columna);
- columna =3D new DataColumn("filtros",typeof(string));
- tabla.Columns.Add(columna);
- tabla.Rows.Add(fila);
-
- vtInstancia =3D new Humano2.Components.ViewTools.ViewTools(1);
- respuesta =3D vtInstancia.GetSQLString(tabla).ToUpper();
- return respuesta;
- }
-
- [Test]
- [Ignore("Aun no definidos los parametros de entrada")]
- public string GenerarConsultaConRelacion()
- {
- DataTable tabla =3D new DataTable();
- DataColumn columna;
- string[] fila =3D {"28^26,28","28^26^20|5|'29'"};
- string respuesta;
- Humano2.Components.ViewTools.ViewTools vtInstancia;
- =09
- columna =3D new DataColumn("columna",typeof(string));
- tabla.Columns.Add(columna);
- columna =3D new DataColumn("filtros",typeof(string));
- tabla.Columns.Add(columna);
- tabla.Rows.Add(fila);
-
- vtInstancia =3D new Humano2.Components.ViewTools.ViewTools(1);
- respuesta =3D vtInstancia.GetSQLString(tabla).ToUpper();
- return respuesta;
- }
-
- [Test]
- [Ignore("Aun no definidos los parametros de entrada")]
- public string GenerarConsultaConAgrupacion()
- {
- DataTable tabla =3D new DataTable();
- DataColumn columna;
- string[] fila =3D {"28^26,28,28^26|1","28^26^20|5|'29'"};
- string respuesta;
- Humano2.Components.ViewTools.ViewTools vtInstancia;
- =09
- columna =3D new DataColumn("columna",typeof(string));
- tabla.Columns.Add(columna);
- columna =3D new DataColumn("filtros",typeof(string));
- tabla.Columns.Add(columna);
- tabla.Rows.Add(fila);
-
- vtInstancia =3D new Humano2.Components.ViewTools.ViewTools(1);
- respuesta =3D vtInstancia.GetSQLString(tabla).ToUpper();
- return respuesta;
- }
- }
+ dtParam.Rows.Add(dr);
+ vt.GetSQLDataTable(dtParam); //Don't get result, only to hav=
e the query
+ string strQuery =3D vt.GetLastExecutedQuery();
+ Logger.Log("strQuery=3D " + strQuery,LogLevel.Trace);
+ Assert.IsTrue(strQuery.Trim() =3D=3D "SELECT \"d10160cTicket=
\".id_entity, \"d10160cTicket\".\"c10162Title\", \"d10160cTicket\".\"c101=
62Date\", \"user\".\"email\", \"d10160cTicket\".\"c10162Resolution Date\"=
FROM \"d10160cTicket\" inner join \"entity\" on \"d10160cTicket\".id_ent=
ity =3D \"entity\".id_entity and entity.\"delDate\" is null LEFT JOIN \=
"user\" ON \"d10160cTicket\".\"c10162Assigned to3\" =3D \"user\".id_entit=
y LEFT JOIN entity e1 ON \"user\".id_entity =3D e1.id_entity LEFT JOIN \=
"d10160cTicket Status\" ON \"d10160cTicket\".\"c10162Status\" =3D \"d1016=
0cTicket Status\".id_entity LEFT JOIN entity e2 ON \"d10160cTicket Status=
\".id_entity =3D e2.id_entity WHERE e1.\"delDate\" IS NULL AND e2.\"delD=
ate\" IS NULL and \"d10160cTicket Status\".\"c10163Status Name\" ILIKE '=
%closed%' ORDER BY upper(\"user\".\"email\") asc".Trim());
+ }
+ =20
+ =20
+ /// <summary>
+ /// Funcion que genera un datatable con la forma en que ViewTool=
s lo recibe...
+ /// </summary>
+ /// <returns></returns>
+ private DataTable makeDataTableInViewTools()
+ {
+ DataTable dt1 =3D new DataTable();
+ DataColumn dc1;
+ dc1 =3D new DataColumn("columna",typeof(string));
+ dt1.Columns.Add(dc1);
+ dc1 =3D new DataColumn("filtros",typeof(string));
+ dt1.Columns.Add(dc1);
+ dc1 =3D new DataColumn("group",typeof(string));
+ dt1.Columns.Add(dc1);
+ dc1 =3D new DataColumn("having",typeof(string));
+ dt1.Columns.Add(dc1);
+ dc1 =3D new DataColumn("order",typeof(string));
+ dt1.Columns.Add(dc1);
+ dc1 =3D new DataColumn("keys",typeof(string));
+ dt1.Columns.Add(dc1);
+ return dt1;
+ }
+ }
}
Modified: humano2/trunk/components/viewTools/ViewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/trunk/components/viewTools/ViewTools.cs 2005-06-28 16:37:26 U=
TC (rev 1431)
+++ humano2/trunk/components/viewTools/ViewTools.cs 2005-06-28 20:55:22 U=
TC (rev 1432)
@@ -35,6 +35,7 @@
private string _tempTable;
private string _whereInit =3D "";
private bool _caseSensitive; //To allow doing insensitive case s=
earch
+ private string query; //To get the query from outside
#endregion
=20
#region "CONSTRUCTORES"
@@ -53,6 +54,7 @@
public ViewTools(int IdClass)
{
this._idclass =3D IdClass;
+ this.query =3D "";
}
=20
/// <summary>
@@ -410,7 +412,8 @@
ViewTable[] affectedTables;
StringBuilder Query =3D new StringBuilder();
ViewColumns[] affectedColumns;
- affectedTables =3D GetTableList(param.Split(",".ToCharArray()));
+ Logger.Log("SQLSelect: " + param,LogLevel.Trace);
+ affectedTables =3D GetTableList(param.Split(",".ToCharArray(=
)));
int i =3D 1;
ArrayList values =3D new ArrayList();
DisplayOrder[] disp;
@@ -664,7 +667,7 @@
return Query.ToString();
}
=20
- private string ParseQuery(DataTable Params)
+ public string ParseQuery(DataTable Params)
{
DataRow objRow;
object[] objArray;
@@ -746,10 +749,18 @@
=20
res =3D Query.ToString();
//Logger.Log("Query=3D" + res,LogLevel.Trace);
- ViewCache.Instance().AddStatement(objRow, res, PageView);
+ =09
+ this.query =3D res; //Update query
+ =20
+ ViewCache.Instance().AddStatement(objRow, res, PageView);
=20
return res;
}
+ =20
+ public string GetLastExecutedQuery()
+ {
+ return this.query; =20
+ }
=09
private string GetGroupingFilters(string[] strParams)
{
@@ -1232,10 +1243,12 @@
string tableName;
int columnIndex, tablePosition;
int i =3D 1;
- =09
+ Logger.Log("GetTableList. Step 1",LogLevel.Trace);
foreach(string Indice in strParams)
{
- string valor =3D Indice.Split("|".ToCharArray()).GetValue(0).ToStrin=
g();
+ Logger.Log("GetTableList. Loop",LogLevel.Trace);
+ Logger.Log("GetTableList. param=3D " + Indice,LogLevel.T=
race);
+ string valor =3D Indice.Split("|".ToCharArray()).GetValu=
e(0).ToString();
if(IsNumeric(valor))
{
columnIndex =3D Convert.ToInt32(valor);
|