You're right. I change a few things around and was able to both configure Dependency Injection via App.config and call it from MBUnit. However...
I use TypeMock to test the calls to various methods. For example take the following.
[Test]
public void TestAuditDirectDeleteOfEntities()
{
// Intercept calls to the RAMAuditor object
Mock ramAuditorMock = MockManager.Mock(typeof(RAMAuditor), Constructor.NotMocked);
// This auditor will now be mocked
RAMAuditor ramAuditor = new RAMAuditor();
// Set up the predicate filter
IRelationPredicateBucket filter = new RelationPredicateBucket((CustodianFields.Name == "Test"));
// When we directly delete the entities then AddAuditEntryToList should be called with these parameters
ramAuditorMock.ExpectCall("AddAuditEntryToList").Args("CustodianEntity", RAMAuditor.AuditType.DirectDeleteOfEntities, Check.IsAny());
_adapter.DeleteEntitiesDirectly(typeof(CustodianEntity), filter);
MockManager.Verify();
}
This had worked perfectly with single entity calls. But now if I use dependency injection I cannot mock the auditor class since the auditor now gets set in the constructor of the entity. Is there no way to set the auditor in code that would be used for multi-entity calls like DeleteEntitiesDirectly?
Thanks,
-Luke
daelmo wrote:
Ok Luke,
As far as I know there're only two overloads for DeleteEntitiesDirectly:
A._DeleteEntitiesDirectly(Type typeOfEntity, IRelationPredicateBucket filterBucket)_
B._DeleteEntitiesDirectly(string entityName, IRelationPredicateBucket filterBucket)
_
However **B **doesn't support Authorization or Auditing, so you have to use A if you want Auditing. Now, to set the Auditor I see to options for you:
I. Setting the auditor when the Entity class is initiated (see above posts).
II. Using Dependency Injection. (see docs).
Hope helpful