/// <summary> /// Add behavior that will be run against every object returned by the fixture. /// </summary> /// <param name="behavior"></param> public void Add(Func <DataRequest, object, object> behavior) { var when = new WhenFilter <object>(); _behaviors.Add((r, o) => { if (((IBehaviorFilter <object>)when).PassesFilter(r, o)) { return(behavior(r, o)); } return(o); }); }
/// <summary> /// Add behavior for specific type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="behavior"></param> public WhenFilter <T> Add <T>(Action <T> behavior) { var whenFilter = new WhenFilter <T>(); Func <DataRequest, object, object> objectFunc = (r, o) => { if (o is T && ((IBehaviorFilter <T>)whenFilter).PassesFilter(r, (T)o)) { behavior((T)o); } return(o); }; _behaviors.Add(objectFunc); return(whenFilter); }