BusinessProcessSavingRow Event
Namespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public event SavingRowEventHandler SavingRow
Public Event SavingRow As SavingRowEventHandler
member SavingRow : IEvent<SavingRowEventHandler,
EventArgs>
Value
SavingRowEventHandler
When running business process the SavingRow event will occur after the
LeaveRow event under the following circumstances:
The different subtleties of
SavingRow event
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 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 BusinessProcessSavingRow
{
[Test]
public void HappensForChangedRows()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var bp = new BusinessProcess { From = jobs };
var changedRows = "";
bp.SavingRow += args => changedRows += jobs.Id.ToString().Trim() + ",";
bp.ForEachRow(() =>
{
bp.RowChanged.ShouldBe(false);
if (jobs.Id == 5 || jobs.Id == 7)
{
jobs.Description.Value += "change";
bp.RowChanged.ShouldBe(true);
}
});
changedRows.ShouldBe("5,7,");
}
[Test]
public void HappensForChangedRows1()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var bp = new BusinessProcess { From = jobs };
bp.Where.Add(jobs.Id.IsEqualTo(3));
bool savingRowHappaned = false;
bp.SavingRow += args => savingRowHappaned = true;
bp.ForFirstRow(() => { });
savingRowHappaned.ShouldBe(false);
bp.ForFirstRow(() => jobs.Description.Value += "change");
savingRowHappaned.ShouldBe(true);
}
[Test]
public void HappensForNewRows()
{
var jobs = new Pubs.Jobs();
jobs.Truncate();
var bp = new BusinessProcess
{
From = jobs,
Activity = Activities.Insert
};
bool savingRowHappaned = false;
bp.SavingRow += args => savingRowHappaned = true;
savingRowHappaned.ShouldBe(false);
bp.ForFirstRow(() => jobs.Id.Value = 5);
savingRowHappaned.ShouldBe(true);
}
[Test]
public void HappensForDeletedRows()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var bp = new BusinessProcess
{
From = jobs,
Activity = Activities.Delete
};
bool savingRowHappaned = false;
bp.SavingRow += args => savingRowHappaned = true;
bp.ForFirstRow(() => { });
savingRowHappaned.ShouldBe(true);
}
[Test]
public void DeleteRowAfterLeavingItIfMethod()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
int counter = 0;
var bp = new BusinessProcess
{
From = jobs
};
bp.DeleteRowAfterLeavingItIf(() => true);
bp.Where.Add(jobs.Id.IsEqualTo(1));
bp.SavingRow += args => counter++;
bp.ForFirstRow(() =>
{
if (counter == 0)
bp.Activity.ShouldBe(Activities.Update);
else if (counter == 1)
bp.Activity.ShouldBe(Activities.Delete);
jobs.Description.Value = "";
});
counter.ShouldBe(2);
}
[Test]
public void DeleteRowAfterLeavingItIfMethod1()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
string savingRowsOrder = "";
var bp = new BusinessProcess
{
From = jobs
};
bp.Where.Add(jobs.Id.IsLessOrEqualTo(5));
bp.DeleteRowAfterLeavingItIf(() => jobs.Id == 3);
bp.SavingRow += args => { savingRowsOrder += jobs.Id.ToString().Trim() + ","; };
bp.ForEachRow(() =>
{
jobs.Description.Value += "";
});
savingRowsOrder.ShouldBe("1,2,3,3,4,5,"); //Notice: The "3" id is shown twice
}
[Test]
public void CancelEvent()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var bp = new BusinessProcess
{
From = jobs
};
bp.SavingRow += args =>
{
args.Cancel = jobs.Id == 3;
};
bp.ForEachRow(() =>
{
jobs.Description.Value = "";
});
var checkBP = new BusinessProcess { From = jobs };
checkBP.ForEachRow(() =>
{
if (jobs.Id != 3)
jobs.Description.ShouldBe("");
else
jobs.Description.ShouldBe("Business Operations Manager");
});
}
}
}