Walaa wrote:
This works if the entity already exists in the database. So no problem there. But what I really wanted to test is if the method got called without having to really delete something from the database.
So when exactly do you want it to be audited?
At which event?
Ok... this works for me when testing to make sure a field change gets audited.
[Test]
public void TestFieldSetAuditOfEntity()
{
// Intercept calls to the RAMAuditor object
Mock entityListMock = MockManager.Mock(typeof(RAMAuditor), Constructor.NotMocked);
// This auditor will now be mocked
RAMAuditor ramAuditor = new RAMAuditor();
RIAEntity entityToTest = new RIAEntity();
entityToTest.AuditorToUse = ramAuditor;
// When we rename the entity the method AddAuditEntryToList should be called
entityListMock.ExpectCall("AddAuditEntryToList").Args(entityToTest, RAMAuditor.AuditType.EntityFieldSet, Check.IsAny());
entityToTest.Name = "*" + entityToTest.Name;
MockManager.Verify();
}
Now when I try to do the same for deleting an entity with this
[Test]
public void TestDeletionAuditOfEntity()
{
// Intercept calls to the RAMAuditor object
Mock entityListMock = MockManager.Mock(typeof(RAMAuditor),Constructor.NotMocked);
// This auditor will now be mocked
RAMAuditor ramAuditor = new RAMAuditor();
RIAEntity entityToTest = new RIAEntity();
entityToTest.AuditorToUse = ramAuditor;
// When we delete an entity the method AddAuditEntryToList with "DeleteOfEntity" should be called.
entityListMock.ExpectCall("AddAuditEntryToList").Args(entityToTest, RAMAuditor.AuditType.DeleteOfEntity, Check.IsAny());
_adapter.DeleteEntity(entityToTest);
MockManager.Verify();
}
It won't trigger the DeleteOfEntity method UNLESS I replace
RIAEntity entityToTest = new RIAEntity();
with this
RIAEntity entityToTest = new RIAEntity(xx);
Where xx represents a real record inside the database.
Basically I want to know is if the AuditDeleteOfEntity gets called IF the entity is NEW and un-saved.
Thanks,
-Luke