-
Notifications
You must be signed in to change notification settings - Fork 68
ExecutionResult
ExecutionResult is an actor within the peasy framework that serves as the result of command execution. When a service command is executed via Command.ExecuteAsync
, initialization logic, validation and business rule validations, and command logic (data proxy invocations, workflow logic, etc.) are subjected to the command execution pipeline.
Upon completion of command execution, an instance of ExecutionResult is returned, which contains a success status, an errors list, and object state (optionally). Based on the successful validation of rules, the success status of execution result will be true
, potentially containing object state from the result of the command operation. When the validation of rules fail, the success status of execution result will be false
, and the errors list will be populated.
Below are a couple of test code samples that show how an ExecutionResult can be consumed:
An example of a command that has been configured with a rule that succeeds during validation.
var executionResult = await createCustomerCommand.ExecuteAsync();
executionResult.Success.ShouldBeTrue();
executionResult.Errors.ShouldBeNull();
executionResult.Value.ShouldBeEquivalentTo(new Customer { ID = 1, FirstName = "Foo", LastName = "Bar"});
An example of a command that has been configured with a rule that fails during validation.
var executionResult = await createCustomerCommand.ExecuteAsync();
executionResult.Success.ShouldBeFalse();
executionResult.Errors.Count().ShouldBe(1);
executionResult.Errors.First().ErrorMessage.ShouldBe("Last name is required");
executionResult.Value.ShouldBeNull();