Actions - Galad/tranquire GitHub Wiki
You can find more details on actions here:
Implementing actions
CompositeAction
ActionBuilder
If
extension method
The If
extension method allows to execute the given action only if the predicate passed in argument is true.
var action = Click.On(button).If(() => true);
var action = Click.On(button).If((WebBrowser webBrowser) => webBrowser.Url().Contains(something));
SelectMany
extension method
The SelectMany
extension method allows to create an action or a question that depends on the result of another action.
// CreateItem is an action that creates an item with a server generated name
var action = CreateItem().SelectMany(itemName => SelectItem(itemName));
var question = CreateItem().SelectMany(itemName => IsItemSelected(itemName));
Actions.Empty
action
Actions.Empty
represents an action that has no effect.
Actions.FromResult
Actions.FromResult
can create an action that has not effect, and returns always the same result.
var action = Action.FromResult("test");
Actions.Create
Actions.Create
can be used to create an action without having to implement an IAction
interface.
var action = Actions.Create("Add an item", actor =>
{
actor.Execute(Click.On(ItemTextArea));
actor.Execute(Enter.TheValue(this.item.Name));
actor.Execute(Click.On(AddButton));
});
Actions.CreateDispatched
Actions.CreateDispatched
can be used to create an action that execute different actions according to the context.
You need to provide 2 actions to the method, one for the Given context and the other one for the When context.
You can use this type of action to execute an action that have the same result but by a different mean. Typically, in the Given phase of the test, how the action is executed is not relevant, what counts is the end result. So you can provide a faster way to obtain the same result, for instance by using an API, or even directly inserting records in the database.
var givenAction = Add.ItemByApi("buy some milk");
var whenAction = Add.Item("buy some milk");
var action = Actions.CreateDispatched("Add the item 'buy some milk'", givenAction, whenAction);
Actor.Given(action); // uses givenAction
Actor.When(action); // uses whenAction