public void TestNullValueForDecimal() { ObjectMap om = ObjectFactory.GetMap(null, typeof(PropertyHolder)); FieldMap fm = om.GetFieldMap("TDecimal"); decimal dec = (decimal)fm.NullValue; Assert.AreEqual(Decimal.MinValue, dec, "Invalid NullValue for test case."); // test NULL handling for decimals a = new PropertyHolder(0, "MyPH", 2, 3, Decimal.MinValue, 5.0, true, DateTime.Now, DateTime.Now, "char", "nchar", "varchar", "nvarchar", "text", "ntext"); a.Persist(); // verify that NULL is inserted when using NullValue SqlResult sr = Broker.Execute("select TDecimal from PropertyHolder where ph_Id = " + a.Id); Assert.IsNull(sr[0, "TDecimal"], "Default NullValue was not converted to NULL on insert."); // verify that object creation uses correct NullValue b = PropertyHolder.Retrieve(a.Id); Assert.AreEqual(a.TDecimal, b.TDecimal); Assert.AreEqual(Decimal.MinValue, b.TDecimal); // verify that translation is disabled for ordinary values b.TDecimal = 4; b.Persist(); a = PropertyHolder.Retrieve(b.Id); Assert.AreEqual(4, a.TDecimal); // verify that translation is disabled for MaxValue // diabled: SQL Server 2005 only works with 2^38-1 (whereas MaxValue is 2^96-1).. //a.TDecimal = Decimal.MaxValue; //a.Persist(); //sr = Broker.Execute( "select TDecimal from PropertyHolder where ph_Id = "+a.Id ); //Assert.IsNotNull( sr[ 0, "TDecimal" ], "Erronous NullValue conversion for MaxValue." ); // cleanup a.Remove(); }
public void TestIdFieldNotSame() { // avoid using DateTime.Now when comparing objects/DTs (because of common db rounding mismatches) a = new PropertyHolder(0, "MyPH", 2, 3, 4, 5.0, true, new DateTime(2000, 1, 20), new DateTime(2000, 1, 30), "char", "nchar", "varchar", "nvarchar", "text", "ntext"); // insert a.Persist(); Assert.AreEqual(a.Name, "MyPH"); Assert.AreEqual(a.TDecimal, 4, "TDecimal not updated."); // select b = PropertyHolder.Retrieve(a.Id); Assert.AreEqual(a, b, "Refresh did not properly retrieve all fields."); a = (PropertyHolder)Broker.RetrieveInstance(a.GetType(), new Key(typeof(PropertyHolder), true, "Id", a.Id)); Assert.AreEqual(a, b, "Refresh and retrieve did not yield identical objects."); // cleanup a.Remove(); }
public void TestNullValueForDecimal() { ObjectMap om = ObjectFactory.GetMap( null, typeof(PropertyHolder) ); FieldMap fm = om.GetFieldMap( "TDecimal" ); decimal dec = (decimal) fm.NullValue; Assert.AreEqual( Decimal.MinValue, dec, "Invalid NullValue for test case." ); // test NULL handling for decimals a = new PropertyHolder( 0, "MyPH", 2, 3, Decimal.MinValue, 5.0, true, DateTime.Now, DateTime.Now, "char", "nchar", "varchar", "nvarchar", "text", "ntext" ); a.Persist(); // verify that NULL is inserted when using NullValue SqlResult sr = Broker.Execute( "select TDecimal from PropertyHolder where ph_Id = " + a.Id ); Assert.IsNull( sr[ 0, "TDecimal" ], "Default NullValue was not converted to NULL on insert." ); // verify that object creation uses correct NullValue b = PropertyHolder.Retrieve( a.Id ); Assert.AreEqual( a.TDecimal, b.TDecimal ); Assert.AreEqual( Decimal.MinValue, b.TDecimal ); // verify that translation is disabled for ordinary values b.TDecimal = 4; b.Persist(); a = PropertyHolder.Retrieve( b.Id ); Assert.AreEqual( 4, a.TDecimal ); // verify that translation is disabled for MaxValue // diabled: SQL Server 2005 only works with 2^38-1 (whereas MaxValue is 2^96-1).. //a.TDecimal = Decimal.MaxValue; //a.Persist(); //sr = Broker.Execute( "select TDecimal from PropertyHolder where ph_Id = "+a.Id ); //Assert.IsNotNull( sr[ 0, "TDecimal" ], "Erronous NullValue conversion for MaxValue." ); // cleanup a.Remove(); }
public void TestIdFieldNotSame() { // avoid using DateTime.Now when comparing objects/DTs (because of common db rounding mismatches) a = new PropertyHolder( 0, "MyPH", 2, 3, 4, 5.0, true, new DateTime( 2000, 1, 20 ), new DateTime( 2000, 1, 30 ), "char", "nchar", "varchar", "nvarchar", "text", "ntext" ); // insert a.Persist(); Assert.AreEqual( a.Name, "MyPH" ); Assert.AreEqual( a.TDecimal, 4, "TDecimal not updated." ); // select b = PropertyHolder.Retrieve( a.Id ); Assert.AreEqual( a, b, "Refresh did not properly retrieve all fields." ); a = (PropertyHolder) Broker.RetrieveInstance( a.GetType(), new Key( typeof(PropertyHolder), true, "Id", a.Id ) ); Assert.AreEqual( a, b, "Refresh and retrieve did not yield identical objects." ); // cleanup a.Remove(); }