BusinessProcessHandlers Property
Namespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public HandlerCollection Handlers { get; }
Public ReadOnly Property Handlers As HandlerCollection
Get
member Handlers : HandlerCollection with get
Property Value
HandlerCollection usage of handlers
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from
www.NUnit.org. For more information about unit testing visit:
www.NUnit.org.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;
namespace TestFirefly.Box.Documentation
{
[TestFixture]
public class TaskInvoke
{
[Test]
public void UsageOfCustomCommand()
{
var bp = new BusinessProcess();
var command = new CustomCommand();
bool happened = false;
bp.Handlers.Add(command).Invokes += e => happened = true;
bp.ForFirstRow(() =>
{
happened.ShouldBe(false);
bp.Invoke(command);
happened.ShouldBe(true);
});
}
[Test]
public void UsageOfCustomCommandAndIdleTiming()
{
var bp = new BusinessProcess();
var command = new CustomCommand();
bool happened = false;
bp.Handlers.Add(command).Invokes += e => happened = true;
bp.ForFirstRow(() =>
{
happened.ShouldBe(false);
bp.Raise(command);
happened.ShouldBe(false);//The handler doesn't happen immediately,
//but will be handled the next time the application is idle,
//usually in the next active UIController
});
}
[Test]
public void InvokingACustomCommandByKey()
{
var bp = new BusinessProcess();
var command = new CustomCommand() {Name = "command name", Key = "Key", AllowInvokeByKey = CustomCommandAllowInvokeByKey.Always };
bool happened = false;
bp.Handlers.Add(command).Invokes += e => happened = true;
bp.ForFirstRow(() =>
{
happened.ShouldBe(false);
bp.Invoke("Key");
happened.ShouldBe(true);
});
}
[Test]
public void AnInvokedCommandBublesBetweenDeferentTasks()
{
var bp = new BusinessProcess();
var command = new CustomCommand();
bool happened = false;
bp.Handlers.Add(command).Invokes += e => happened = true;
bp.ForFirstRow(() =>
{
var childBp = new BusinessProcess();
childBp.ForFirstRow(() =>
{
childBp.Invoke(command);
happened.ShouldBe(true);
});
});
}
}
}