I want to exactly what Omar is trying to do, but I can't get the code right, apparently. Here is my overloaded adapter code:
public class NCSDataAccessAdapter : DataAccessAdapter
{
string _userName;
public NCSDataAccessAdapter():base()
{
}
/// <summary>
/// A constructor to set the username value to be persisted as current_user
/// </summary>
/// <param name="userName">The user name value to mimic current_user</param>
public NCSDataAccessAdapter(string userName):base()
{
_userName = userName;
}
/// <summary>
/// A constructor to set the username value and to set the connection string
/// </summary>
/// <param name="connectionString">The connection string to pass to the overloaded class</param>
/// <param name="userName">The username to persist as current_user</param>
public NCSDataAccessAdapter(string connectionString, string userName):base(connectionString)
{
_userName = userName;
}
/// <summary>
/// Overloaded Method that will first set the userName value mimicing current_user
/// </summary>
/// <param name="entityToSave">The entity to be saved</param>
/// <param name="isInsert">If true then this entity is in the insertqueue, otherwise updatequeue</param>
public override void OnBeforeEntitySave(IEntity2 entityToSave, bool isInsert)
{
for (int i = entityToSave.Fields.Count-1; i >= 0; i--)
{
EntityField2 ef = entityToSave.Fields[i] as EntityField2;
if (ef.Name.ToLower() == "update_date")
{
ef.CurrentValue = this._userName;
break;
}
}
}
}
...and here is my test method (TestDriven.Net)
public void NCSDataAccessAdapterConstructTest()
{
NCSDataAccessAdapter da = new NCSDataAccessAdapter("testUser");
string returnedUser;
try
{
da.StartTransaction(IsolationLevel.ReadCommitted,"userTest");
HlpUserEntity hu = new HlpUserEntity(4);
da.FetchEntity(hu);
hu.City="Changed";
da.SaveEntity(hu,true);
da.Commit();
returnedUser = hu.UpdateUser;
}
catch
{
da.Rollback();
throw;
}
finally
{
da.Dispose();
}
Assert.AreEqual(returnedUser,"testUser");
}
but my Assert always comes back false. I put a breakpoint in my overloaded OnBeforeEntitySave method in the code above and it never gets there. What am I missing?
I can't even tell if my code inside of the overloaded OnBeforeEntitySave method is going to work because I can't seem to even get there.
P.S. I have removed the trigger on the back end.