Virtual data and attached handlers
You can use XData as database mock engine. XData has feature to replace database interactions with attached handlers call. Virtual objects is attached to repository using Attach method of IRepository<T> interface. To detach virtual objects used Detach method. Multiple virtual entities can be attached to repository as new objects using AttachNewObjects method.
Tip
This method (AttachNewObjects) can be used to add multiple detached objects to real repository.
Every virtual entity can override handlers attached to repository with their own realization using parameters of AttachNewObjects method or SetAttachedHandlers method call. To set repository level handlers use special overload of SetAttachedHandlers. To clear attached objects You can use ClearAttachedObjects method. To help wrap handlers to abstract AttachedHandler<T> class and unwrap it back to specialized handlers XData has a wrapper class RepositoryAttachedHandler.
Attached handlers can have followed types (see AttachedHandlerType):
- OnClear - (ClearAttachedHandler) handler called instead of Clear
- OnExecute - (ExecuteAttachedHandler<T>) handler called instead of Execute
- OnGetLob - (GetLobAttachedHandler) handler called instead of requesting LOB data
- OnGetLobSize - (GetLobSizeAttachedHandler) handler called instead of requesting LOB size
- OnGetXml - (GetXmlAttachedHandler) handler called instead of requesting XML data
- OnLock - (LockAttachedHandler<T>) handler called instead of Lock
- OnRefresh - (RefreshAttachedHandler<T>) handler called instead of refreshing data
- OnSetLob - (SetLobAttachedHandler) handler called instead of saving LOB data
- OnSetXml - (SetXmlAttachedHandler) handler called instead of saving XML data
- OnSubmit - (SubmitAttachedHandler<T>) handler called instead of Submit multiple objects
- OnSubmitObject - (SubmitObjectAttachedHandler<T>) handler called instead of submitting single object
- OnSubmitQuery - (SubmitQueryAttachedHandler<T>) handler called instead of submitting query generation