コード例 #1
0
ファイル: ODBLoadTest.cs プロジェクト: olexta/Toolkit
		public void AddTransLoadTest()
		{
			PersistentTransaction trans = new PersistentTransaction();
			for ( int i = 0; i < 20; i++ ) {
				TestObject t_obj = new TestObject();
				t_obj.Name = m_obj_name + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
				t_obj._int = 111;
				t_obj._stream = new PersistentStream( @"c:\ntldr" );
				trans.Add( t_obj, PersistentTransaction.ACTION.Save );
			}
			trans.Process();
		}
コード例 #2
0
ファイル: ODBTest.cs プロジェクト: olexta/Toolkit
	public void SaveRetriveSearchTransTest()
	{
		PersistentTransaction trans;
		RetrieveCriteria ret_crit;

		// common variables
		TestObject obj;
		int _id_expected;
		string _name_expected;
		DateTime _stamp_expected;

		string _string_expected;
		int? _int_expected;
		bool? _boolean_expected;
		double? _double_expected;
		DateTime? _datetime_expected;


		obj = new TestObject();
		_name_expected = obj.Name = m_obj_name + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
		_int_expected = obj._int = 1234567890;
		_boolean_expected = obj._bool = true;
		_string_expected = obj._string = 
			@"Test строка (ї,ё) 1@№" + DateTime.Now.ToString();
		obj._datetime = DateTime.Now;
		_double_expected = obj._double = (double) 1 / 33;
		
		obj.Save();
		_id_expected = obj.ID;
		_stamp_expected = obj.Stamp;
		_datetime_expected = obj._datetime;

	    #region check props after save
	    Assert.AreEqual( _name_expected, obj.Name );
	    Assert.AreEqual( _int_expected, obj._int );
	    Assert.AreEqual( _boolean_expected, obj._bool );
	    Assert.AreEqual( _string_expected, obj._string );
	    Assert.IsTrue( DateTime.Equals(_datetime_expected, obj._datetime ));
	    Assert.IsTrue( DateTime.Equals( _stamp_expected, obj.Stamp ) );
	    Assert.AreEqual( _double_expected, obj._double );
	    #endregion

		// check property update in transaction
		_name_expected = obj.Name = m_obj_name + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
		_int_expected = obj._int = int.MaxValue;
		_boolean_expected = obj._bool = !obj._bool;
		_string_expected = obj._string = obj.Name;
		_datetime_expected = obj._datetime = DateTime.Now;
		_double_expected = obj._double = (double) 2 / 33;
		
		trans = new PersistentTransaction(obj, PersistentTransaction.ACTION.Save );
		trans.Process();

		_stamp_expected = obj.Stamp;
		_datetime_expected = obj._datetime;
		
		ret_crit = new RetrieveCriteria( obj.Type, "(ID = " + obj.ID );
		ret_crit.Perform();
		
		if( ret_crit.Count != 1 ) {
			Assert.Fail( "Update object in transaction failed!" );
		} else {
			#region check props
			Assert.AreEqual( _name_expected, ((TestObject)ret_crit[0]).Name );
			Assert.AreEqual( _int_expected, ((TestObject) ret_crit[0])._int );
			Assert.AreEqual( _boolean_expected, ((TestObject) ret_crit[0])._bool );
			Assert.AreEqual( _string_expected, ((TestObject) ret_crit[0])._string );
			Assert.IsTrue( DateTime.Equals( _datetime_expected, 
								((TestObject) ret_crit[0])._datetime ) );
			Assert.IsTrue( DateTime.Equals( _stamp_expected, 
								((TestObject) ret_crit[0]).Stamp ) );
			Assert.AreEqual( _double_expected, 
							((TestObject) ret_crit[0])._double );
			#endregion
		}
		
		// check property update in failed transaction
		_name_expected= obj.Name = m_obj_name + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
		_int_expected = obj._int = int.MaxValue;
		_boolean_expected = obj._bool = !obj._bool;
		_string_expected = obj._string = obj.Name;
		_datetime_expected = obj._datetime = DateTime.Now;
		_double_expected = obj._double = (double) 3 / 33;

		trans = new PersistentTransaction( obj, PersistentTransaction.ACTION.Save );
		TestObject fObj = new TestObject();
		fObj.FailOn = TestObject.FAIL.Save;
		trans.Add( fObj, PersistentTransaction.ACTION.Save );
		// run transaction
		try {
			trans.Process();
			Assert.Fail( "Exception wasn't raised" );
		} catch {/*catch exception that will be*/}
		// retrive object to check that nothing was changed
		ret_crit = new RetrieveCriteria( obj.Type, "(ID = " + obj.ID + ")" );
		ret_crit.Perform();

		if( ret_crit.Count != 1 ) {
			Assert.Fail( "Update object in transaction failed!" );
		} else {
			#region check props
			Assert.IsTrue( DateTime.Equals( _stamp_expected, 
							((TestObject) ret_crit[0]).Stamp ) );
			Assert.AreEqual( _name_expected, ((TestObject) ret_crit[0]).Name );
			Assert.AreEqual( _int_expected, ((TestObject) ret_crit[0])._int );
			Assert.AreEqual( _boolean_expected, ((TestObject) ret_crit[0])._bool );
			Assert.AreEqual( _string_expected, ((TestObject) ret_crit[0])._string );
			Assert.IsTrue( DateTime.Equals( _datetime_expected, 
							((TestObject) ret_crit[0])._datetime ) );
			Assert.AreEqual( _double_expected, ((TestObject) ret_crit[0])._double );
			#endregion
		}

		#region delete + failed
		trans = new PersistentTransaction();
		trans.Add( ret_crit[0], PersistentTransaction.ACTION.Delete );
		fObj = new TestObject();
		fObj.FailOn = TestObject.FAIL.Save;
		trans.Add( fObj, PersistentTransaction.ACTION.Save );
		try {
			trans.Process();
			Assert.Fail( "Exception wasn't raised" );
		} catch {/*catch exception that will be*/}
		ret_crit.Perform();
		// object must exist
		Assert.IsTrue( (ret_crit.CountFound == 1), 
						"rollbacked transaction didn't recover deleted object" );
		#endregion

		#region delete
		trans = new PersistentTransaction();
		trans.Add( ret_crit[0], PersistentTransaction.ACTION.Delete );
		trans.Process();
		ret_crit.Perform();
		// object must not exist
		Assert.IsTrue( (ret_crit.CountFound == 0),
						"transaction didn't delete object" );
		#endregion
	}