Skip to content

Commit

Permalink
Tests were corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-lipetsk committed Mar 7, 2024
1 parent ca8b9ec commit b500015
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 200 deletions.
12 changes: 6 additions & 6 deletions Tests/General/Source/CheckErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7846,7 +7846,7 @@ public static void CheckOleDbError__Firebird__IntegerDivideByZero
err.Source);

StringAssert.Contains
("Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero.",
("Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero.",
err.Message);

Assert.AreEqual
Expand All @@ -7866,7 +7866,7 @@ public static void CheckOleDbError__Firebird__FloatDivideByZero
err.Source);

StringAssert.Contains
("Floating-point divide by zero. The code attempted to divide a floating-point value by zero.",
("Floating-point divide by zero. The code attempted to divide a floating-point value by zero.",
err.Message);

Assert.AreEqual
Expand Down Expand Up @@ -8010,7 +8010,7 @@ public static void CheckOleDbError__Firebird__IntOpOverflow
err.Source);

StringAssert.Contains
("Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.",
("Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.",
err.Message);

Assert.AreEqual
Expand All @@ -8030,7 +8030,7 @@ public static void CheckOleDbError__Firebird__FloatOpOverflow
err.Source);

StringAssert.Contains
("Floating-point overflow. The exponent of a floating-point operation is greater than the magnitude allowed.",
("Floating-point overflow. The exponent of a floating-point operation is greater than the magnitude allowed.",
err.Message);

Assert.AreEqual
Expand Down Expand Up @@ -8097,13 +8097,13 @@ public static void CheckErrorRecord__IBP__FailedToBuildIbParamValue__CantConvert
var msg_ru
=string.Format
("Ошибка формирования ib-значения входящего параметра. Позиция {0}.\r\n"
+"Конвертирование из [{1}] в [{2}].",
+"Ошибка конвертирования типа данных [{1}] в [{2}].",
args);

var msg_en
=string.Format
("IB-native IN-parameter value create failed. Position {0}.\r\n"
+"Conversion from [{1}] to [{2}].",
+"Conversion from datatype [{1}] into datatype [{2}] failed.",
args);

CheckErrors.TestErrRecordSrcAndDescr2_RU_EN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,80 +70,56 @@ public static void Test_001()
T_DATA1 c_value1=new T_DATA1_U(12,14,34).Add(new System.TimeSpan(1000*1235)).Add(new System.TimeSpan(0));
T_DATA2 c_value2=new T_DATA2_U(12,14,34).Add(new System.TimeSpan(1000*1234)).Add(new System.TimeSpan(900));

System.Int64? testID=Helper__InsertRow(db,c_value1,c_value2);
try
{
var newRecord=new MyContext.TEST_RECORD();

var recs=db.testTable.Where(r => (r.COL_DATA1 /*OP{*/ > /*}OP*/ r.COL_DATA2) && r.TEST_ID==testID);
newRecord.COL_DATA1 =c_value1;
newRecord.COL_DATA2 =c_value2;

int nRecs=0;
db.testTable.Add(newRecord);

foreach(var r in recs)
{
Assert.AreEqual
(0,
nRecs);
db.SaveChanges(); //throw!

++nRecs;
TestServices.ThrowWeWaitError();
}
catch(DbUpdateException e)
{
CheckErrors.PrintException_OK(e);

Assert.IsTrue
(r.TEST_ID.HasValue);
Assert.NotNull
(e.InnerException);

Assert.AreEqual
(testID,
r.TEST_ID.Value);
Assert.IsInstanceOf
(typeof(xdb.OleDbException),
e.InnerException);

var e2=e.InnerException as xdb.OleDbException;

Assert.IsNull
(e2.InnerException);

Assert.AreEqual
(c_value1,
r.COL_DATA1);
(lcpi.lib.com.HResultCode.DB_E_UNSUPPORTEDCONVERSION,
e2.ErrorCode);

Assert.AreEqual
(c_value2,
r.COL_DATA2);
}//foreach r

db.CheckTextOfLastExecutedCommand
(new TestSqlTemplate()
.T("SELECT ").N("t","TEST_ID").T(", ").N("t",c_NameOf__COL_DATA1).T(", ").N("t",c_NameOf__COL_DATA2).EOL()
.T("FROM ").N(c_NameOf__TABLE).T(" AS ").N("t").EOL()
.T("WHERE (").N("t",c_NameOf__COL_DATA1).T(" > ").N("t",c_NameOf__COL_DATA2).T(") AND (").N("t","TEST_ID").T(" = ").P_ID("__testID_0").T(")"));

Assert.AreEqual
(1,
nRecs);
(3,
TestUtils.GetRecordCount(e2));

CheckErrors.CheckErrorRecord__IBP__FailedToBuildIbParamValue__CantConvert
(TestUtils.GetRecord(e2,0),
0,
"DBTYPE_DBTIME2",
"DBTYPE_DBTIMESTAMP",
lcpi.lib.com.HResultCode.DB_E_UNSUPPORTEDCONVERSION);
}//catch
}//using db

tr.Rollback();
}//using tr
}//using cn
}//Test_001

//Helper methods --------------------------------------------------------
private static System.Int64 Helper__InsertRow(MyContext db,
T_DATA1 valueForColData1,
T_DATA2 valueForColData2)
{
var newRecord=new MyContext.TEST_RECORD();

newRecord.COL_DATA1 =valueForColData1;
newRecord.COL_DATA2 =valueForColData2;

db.testTable.Add(newRecord);

db.SaveChanges();

db.CheckTextOfLastExecutedCommand
(new TestSqlTemplate()
.T("INSERT INTO ").N(c_NameOf__TABLE).T(" (").N(c_NameOf__COL_DATA1).T(", ").N(c_NameOf__COL_DATA2).T(")").EOL()
.T("VALUES (").P("p0").T(", ").P("p1").T(")").EOL()
.T("RETURNING ").N("TEST_ID").EOL()
.T("INTO ").P("p2").T(";"));

Assert.IsTrue
(newRecord.TEST_ID.HasValue);

Console.WriteLine("TEST_ID: {0}",newRecord.TEST_ID.Value);

return newRecord.TEST_ID.Value;
}//Helper__InsertRow
};//class TestSet_001__fields__01__VV

////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,91 +69,56 @@ public static void Test_001()
{
T_DATA1 c_value1=new T_DATA1_U(12,14,34).Add(new System.TimeSpan(1000*1234)).Add(new System.TimeSpan(100));

System.Int64? testID=Helper__InsertRow(db,c_value1,null);

var recs=db.testTable.Where(r => (r.COL_DATA1 /*OP{*/ > /*}OP*/ r.COL_DATA2) && r.TEST_ID==testID);

foreach(var r in recs)
try
{
TestServices.ThrowSelectedRow();
}//foreach r

db.CheckTextOfLastExecutedCommand
(new TestSqlTemplate()
.T("SELECT ").N("t","TEST_ID").T(", ").N("t",c_NameOf__COL_DATA1).T(", ").N("t",c_NameOf__COL_DATA2).EOL()
.T("FROM ").N(c_NameOf__TABLE).T(" AS ").N("t").EOL()
.T("WHERE (").N("t",c_NameOf__COL_DATA1).T(" > ").N("t",c_NameOf__COL_DATA2).T(") AND (").N("t","TEST_ID").T(" = ").P_ID("__testID_0").T(")"));
}//using db
var newRecord=new MyContext.TEST_RECORD();

tr.Rollback();
}//using tr
}//using cn
}//Test_001
newRecord.COL_DATA1 =c_value1;
newRecord.COL_DATA2 =null;

//-----------------------------------------------------------------------
[Test]
public static void Test_002()
{
using(var cn=LocalCnHelper.CreateCn())
{
cn.Open();
db.testTable.Add(newRecord);

using(var tr=cn.BeginTransaction())
{
//insert new record in external transaction
using(var db=new MyContext(tr))
{
T_DATA1 c_value1=new T_DATA1_U(12,14,34).Add(new System.TimeSpan(1000*1234)).Add(new System.TimeSpan(100));

System.Int64? testID=Helper__InsertRow(db,c_value1,null);

var recs=db.testTable.Where(r => !(r.COL_DATA1 /*OP{*/ > /*}OP*/ r.COL_DATA2) && r.TEST_ID==testID);
db.SaveChanges(); //throw!

foreach(var r in recs)
{
TestServices.ThrowSelectedRow();
}//foreach r

db.CheckTextOfLastExecutedCommand
(new TestSqlTemplate()
.T("SELECT ").N("t","TEST_ID").T(", ").N("t",c_NameOf__COL_DATA1).T(", ").N("t",c_NameOf__COL_DATA2).EOL()
.T("FROM ").N(c_NameOf__TABLE).T(" AS ").N("t").EOL()
.T("WHERE NOT (").N("t",c_NameOf__COL_DATA1).T(" > ").N("t",c_NameOf__COL_DATA2).T(") AND (").N("t","TEST_ID").T(" = ").P_ID("__testID_0").T(")"));
}//using db

tr.Rollback();
}//using tr
}//using cn
}//Test_002
TestServices.ThrowWeWaitError();
}
catch(DbUpdateException e)
{
CheckErrors.PrintException_OK(e);

//Helper methods --------------------------------------------------------
private static System.Int64 Helper__InsertRow(MyContext db,
T_DATA1 valueForColData1,
T_DATA2 valueForColData2)
{
var newRecord=new MyContext.TEST_RECORD();
Assert.NotNull
(e.InnerException);

newRecord.COL_DATA1 =valueForColData1;
newRecord.COL_DATA2 =valueForColData2;
Assert.IsInstanceOf
(typeof(xdb.OleDbException),
e.InnerException);

db.testTable.Add(newRecord);
var e2=e.InnerException as xdb.OleDbException;

db.SaveChanges();
Assert.IsNull
(e2.InnerException);

db.CheckTextOfLastExecutedCommand
(new TestSqlTemplate()
.T("INSERT INTO ").N(c_NameOf__TABLE).T(" (").N(c_NameOf__COL_DATA1).T(", ").N(c_NameOf__COL_DATA2).T(")").EOL()
.T("VALUES (").P("p0").T(", ").P("p1").T(")").EOL()
.T("RETURNING ").N("TEST_ID").EOL()
.T("INTO ").P("p2").T(";"));
Assert.AreEqual
(lcpi.lib.com.HResultCode.DB_E_UNSUPPORTEDCONVERSION,
e2.ErrorCode);

Assert.IsTrue
(newRecord.TEST_ID.HasValue);
Assert.AreEqual
(3,
TestUtils.GetRecordCount(e2));

Console.WriteLine("TEST_ID: {0}",newRecord.TEST_ID.Value);
CheckErrors.CheckErrorRecord__IBP__FailedToBuildIbParamValue__CantConvert
(TestUtils.GetRecord(e2,0),
0,
"DBTYPE_DBTIME2",
"DBTYPE_DBTIMESTAMP",
lcpi.lib.com.HResultCode.DB_E_UNSUPPORTEDCONVERSION);
}//catch
}//using db

return newRecord.TEST_ID.Value;
}//Helper__InsertRow
tr.Rollback();
}//using tr
}//using cn
}//Test_001
};//class TestSet_001__fields__02__VN

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit b500015

Please sign in to comment.