/// <summary> /// Called before deleting an enumeration of entities. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state.</param> /// <returns> /// True to cancel the delete operation; false otherwise. /// </returns> public bool OnBeforeDelete(IEnumerable <IEntity> entities, IDictionary <string, object> state) { foreach (var userAccount in entities.Select(entity => entity.As <UserAccount>()).Where(userAccount => userAccount != null)) { // Gather user account details required OnAfterDelete _auditLogEventTarget.GatherAuditLogEntityDetailsForDelete(userAccount, state); } return(false); }
public void TestOnDeleteUserAccount() { bool success = true; string userName = "******" + Guid.NewGuid(); var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict); mockAuditLog.Setup(al => al.OnDeleteUserAccount(success, userName)); var eventTarget = new AuditLogUserAccountEventTarget(mockAuditLog.Object); var user = new UserAccount { Name = userName }; IDictionary <string, object> state = new Dictionary <string, object>(); eventTarget.GatherAuditLogEntityDetailsForDelete(user, state); eventTarget.WriteDeleteAuditLogEntries(success, user.Id, state); mockAuditLog.VerifyAll(); }