BusinessProcessForEachRow(Action) Method
Performs the specified action on each row that matches the
Where property filter.
Namespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public long ForEachRow(
Action action
)
Public Function ForEachRow (
action As Action
) As Long
member ForEachRow :
action : Action -> int64
- action Action
- The Action to be performed for each row
Int64
Created for ease of use scenarios.
Most simple business operations needs to perform an action for each row that matches the filter.
Behaves the same way as registering that action to the
LeaveRow event, and invoking the
Run method.
This example demonstrates both ForEachRow and ForFirstRow
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.
This example is based on test data. The code for the entities included in this test data can be found in the documentation of
Entityusing NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;
namespace TestFirefly.Box.Documentation
{
[TestFixture]
public class ForEachRow
{
[Test]
public void SumOfMinLevel()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
int totalMinLevel = 0;
var bp = new BusinessProcess
{
From = jobs
};
bp.ForEachRow(() => totalMinLevel += jobs.MinLevel);
totalMinLevel.ShouldBe(1370);
}
[Test]
public void ForEachRowDemo()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
string jobTitles = "";
var bp = new BusinessProcess
{
From = jobs,
};
bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
bp.ForEachRow(() =>
{
if (jobTitles.Length > 0)
jobTitles += ", ";
jobTitles += jobs.Description.Value.TrimEnd();
});
jobTitles.ShouldBe(
"New Hire - Job not specified, Chief Executive Officer, Business Operations Manager"
);
}
[Test]
public void AchievingTheBehaviourOfForEachRowWithLeaveRow()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
string jobTitles = "";
var bp = new BusinessProcess
{
From = jobs,
};
bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
bp.LeaveRow += () =>
{
if (jobTitles.Length > 0)
jobTitles += ", ";
jobTitles += jobs.Description.Value.TrimEnd();
};
bp.Run();
jobTitles.ShouldBe(
"New Hire - Job not specified, Chief Executive Officer, Business Operations Manager"
);
}
[Test]
public void ForFirstRowDemo()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
string jobTitles = "";
var bp = new BusinessProcess
{
From = jobs,
};
bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
bp.ForFirstRow(() =>
{
if (jobTitles.Length > 0)
jobTitles+=", ";
jobTitles+=jobs.Description.Value.TrimEnd();
});
jobTitles.ShouldBe("New Hire - Job not specified");
}
[Test]
public void AchievingTheBehaviourOfForFirstRowWithLeaveRowEvent()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
string jobTitles = "";
var bp = new BusinessProcess
{
From = jobs,
};
bp.Where.Add(jobs.Id.IsLessOrEqualTo(3));
bp.LeaveRow += () =>
{
if (jobTitles.Length > 0)
jobTitles+=", ";
jobTitles+=jobs.Description.Value.TrimEnd();
};
bp.Exit(ExitTiming.AfterRow);
bp.Run();
jobTitles.ShouldBe("New Hire - Job not specified");
}
}
}