You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a scenario where I wanted to run a set of actions over a collection, even in the event that one of more fails. The main one is running unit tests, but there are other scenarios like handling many files with a common action, that I've found it handy.
For my code it's replaced anywhere I would use a foreach at the top of my Does() statement, hence calling the extension method DoesForEach().
publicstaticCakeTaskBuilder<ActionTask>DoesForEach<T>(thisCakeTaskBuilder<ActionTask>builder,IEnumerable<T>items,Action<T>action){return DoesForEach(builder,()=> items,(i,c)=> action(i));}publicstaticCakeTaskBuilder<ActionTask>DoesForEach<T>(thisCakeTaskBuilder<ActionTask>builder,IEnumerable<T>items,Action<T,ICakeContext>action){return DoesForEach(builder,()=> items, action);}publicstaticCakeTaskBuilder<ActionTask>DoesForEach<T>(thisCakeTaskBuilder<ActionTask>builder,Func<IEnumerable<T>>items,Action<T>action){return DoesForEach(builder, items,(i,c)=> action(i));}publicstaticCakeTaskBuilder<ActionTask>DoesForEach<T>(thisCakeTaskBuilder<ActionTask>builder,Func<IEnumerable<T>>items,Action<T,ICakeContext>action){
builder.Does(c =>{varexceptions=newList<Exception>();foreach(var item in items()){try{ action(item, c);}catch(Exceptione){ exceptions.Add(e);}}if(exceptions.Any())thrownew AggregateException("Task failed with following exceptions", exceptions);});returnbuilder;}
The text was updated successfully, but these errors were encountered:
I ran into a scenario where I wanted to run a set of actions over a collection, even in the event that one of more fails. The main one is running unit tests, but there are other scenarios like handling many files with a common action, that I've found it handy.
For my code it's replaced anywhere I would use a
foreach
at the top of myDoes()
statement, hence calling the extension methodDoesForEach()
.The text was updated successfully, but these errors were encountered: