public void TestConcurrencyControlError() { try { // object uniqing defeats this test GentleSettings.CacheObjects = false; Check.LogError(LogCategories.General, "The following error message has been provoked as part of a test case:"); if (GentleSettings.ConcurrencyControl) { m1 = MemberCC.Retrieve(1); m2 = MemberCC.Retrieve(1); long version = m1.DatabaseVersion; m1.Persist(); // ok m2.Persist(); // fails as it is the same record as m1 } else { // fake expected result Check.Fail(Error.UnexpectedRowCount, 0, 0); } } catch (GentleException ge) { if (ge.Error == Error.UnexpectedRowCount) { throw new GentleException(Error.Unspecified, "TEST"); } else { throw; } } }
public void TestConcurrencyControlValue() { if (GentleSettings.ConcurrencyControl) { m1 = MemberCC.Retrieve(1); long version = m1.DatabaseVersion; m1.Persist(); Assert.AreEqual(version + 1, m1.DatabaseVersion, "Object version was not updated."); m2 = MemberCC.Retrieve(1); Assert.AreEqual(m1.DatabaseVersion, m2.DatabaseVersion, "Database version was not updated."); } }
public void TestCRUD() { GentleSettings.CacheObjects = false; if( GentleSettings.ConcurrencyControl ) { m1 = new MemberCC( list.Id, "John Doe", "*****@*****.**" ); // insert m1.Persist(); Assert.AreEqual( m1.Name, "John Doe", "The object was not properly inserted!" ); Assert.AreEqual( m1.Address, "*****@*****.**", "The object was not properly inserted!" ); // select m2 = MemberCC.Retrieve( m1.Id ); // verify select/insert Assert.IsTrue( m2.Id != 0, "The object could not be retrieved from the database!" ); Assert.IsTrue( m2.Id > 4, "Existing id was reused!" ); Assert.AreEqual( m1.Id, m2.Id, "The object could not be retrieved from the database!" ); Assert.AreEqual( "John Doe", m2.Name, "The object was not properly retrieved on construction!" ); Assert.AreEqual( "*****@*****.**", m2.Address, "The object was not properly retrieved on construction!" ); Assert.AreEqual( m1.DatabaseVersion, m2.DatabaseVersion, "Database revision not retrieved!" ); // update m2.Name = "Jane Doe"; m2.Address = "*****@*****.**"; m2.Persist(); Assert.AreEqual( m1.DatabaseVersion + 1, m2.DatabaseVersion, "Database revision not incremented!" ); // verify update m1 = MemberCC.Retrieve( m2.Id ); Assert.AreEqual( m2.Name, m1.Name, "Name not updated!" ); Assert.AreEqual( m2.Address, m1.Address, "SenderAddress not updated!" ); Assert.AreEqual( m1.DatabaseVersion, m2.DatabaseVersion, "Database revision not retrieved!" ); // delete m2.Remove(); // verify delete by counting the number of rows SqlBuilder sb = new SqlBuilder( StatementType.Count, typeof(MemberCC) ); sb.AddConstraint( Operator.Equals, "Id", m1.Id ); SqlResult sr = Broker.Execute( sb.GetStatement( true ) ); Assert.AreEqual( 0, sr.Count, "Object not removed" ); } }
public void TestCRUD() { GentleSettings.CacheObjects = false; if (GentleSettings.ConcurrencyControl) { m1 = new MemberCC(list.Id, "John Doe", "*****@*****.**"); // insert m1.Persist(); Assert.AreEqual(m1.Name, "John Doe", "The object was not properly inserted!"); Assert.AreEqual(m1.Address, "*****@*****.**", "The object was not properly inserted!"); // select m2 = MemberCC.Retrieve(m1.Id); // verify select/insert Assert.IsTrue(m2.Id != 0, "The object could not be retrieved from the database!"); Assert.IsTrue(m2.Id > 4, "Existing id was reused!"); Assert.AreEqual(m1.Id, m2.Id, "The object could not be retrieved from the database!"); Assert.AreEqual("John Doe", m2.Name, "The object was not properly retrieved on construction!"); Assert.AreEqual("*****@*****.**", m2.Address, "The object was not properly retrieved on construction!"); Assert.AreEqual(m1.DatabaseVersion, m2.DatabaseVersion, "Database revision not retrieved!"); // update m2.Name = "Jane Doe"; m2.Address = "*****@*****.**"; m2.Persist(); Assert.AreEqual(m1.DatabaseVersion + 1, m2.DatabaseVersion, "Database revision not incremented!"); // verify update m1 = MemberCC.Retrieve(m2.Id); Assert.AreEqual(m2.Name, m1.Name, "Name not updated!"); Assert.AreEqual(m2.Address, m1.Address, "SenderAddress not updated!"); Assert.AreEqual(m1.DatabaseVersion, m2.DatabaseVersion, "Database revision not retrieved!"); // delete m2.Remove(); // verify delete by counting the number of rows SqlBuilder sb = new SqlBuilder(StatementType.Count, typeof(MemberCC)); sb.AddConstraint(Operator.Equals, "Id", m1.Id); SqlResult sr = Broker.Execute(sb.GetStatement(true)); Assert.AreEqual(0, sr.Count, "Object not removed"); } }
public void TestConcurrencyControlError() { try { // object uniqing defeats this test GentleSettings.CacheObjects = false; Check.LogError( LogCategories.General, "The following error message has been provoked as part of a test case:" ); if( GentleSettings.ConcurrencyControl ) { m1 = MemberCC.Retrieve( 1 ); m2 = MemberCC.Retrieve( 1 ); long version = m1.DatabaseVersion; m1.Persist(); // ok m2.Persist(); // fails as it is the same record as m1 } else { // fake expected result Check.Fail( Error.UnexpectedRowCount, 0, 0 ); } } catch( GentleException ge ) { if( ge.Error == Error.UnexpectedRowCount ) { throw new GentleException( Error.Unspecified, "TEST" ); } else { throw; } } }
public void TestConcurrencyControlValue() { if( GentleSettings.ConcurrencyControl ) { m1 = MemberCC.Retrieve( 1 ); long version = m1.DatabaseVersion; m1.Persist(); Assert.AreEqual( version + 1, m1.DatabaseVersion, "Object version was not updated." ); m2 = MemberCC.Retrieve( 1 ); Assert.AreEqual( m1.DatabaseVersion, m2.DatabaseVersion, "Database version was not updated." ); } }