today I want to show to unit test, and I mean really unit test SOOrderEntry graph extnesion in Acumatica with XUnit.
In order to achieve it, you'll need following steps:
- Create .Net Class library
- Reference xUnit
- Create public class that inherits from TestBase class
- Add override ResisterServices
- Create something like PrepareGraph with usage of TestBase.Setup class
- Write your mehtods.
I will not describe how steps 1 - 4 may look, as it is pretty obvious, but step 5 and 6 at C# level may look like this:
public class SOOrderEntrySDExtTests : TestBase
protected IPXCurrencyService CurrencyService;
protected IFinPeriodRepository FinPeriodService;
FinPeriodService = new PX.Objects.Unit.FinPeriodServiceMock();
CurrencyService = new PX.Objects.Unit.CurrencyServiceMock();
protected override void RegisterServices(ContainerBuilder builder)
private SOOrderEntry PrepareGraph()
DefaultOrderType = "SC",
TransferOrderType = "TR",
ShipmentNumberingID = "SOSHIPMENT",
ProrateDiscounts = true,
FreeItemShipping = "S",
FreightAllocation = "A",
CreditCheckError = false,
MinGrossProfitValidation = "W"
var graph = PXGraph.CreateInstance<SOOrderEntry>();
OrderType = "SC",
OrderDesc = "some test desc"
var graphExtension = graph.GetExtension<SOOrderEntryExt>();
public void CheckInsertion()
var graph = PrepareGraph();
graph.CurrentDocument.Current.Approved = true;
Few more comments regarding code.
- As of now, in order to give to SOOrderEntry setup classes, you'll need to go from one exception message to another. Not very convenient, but the only available way
- RegisterServices was copy/pasted from Github post of Dmitriy Naumov
- You may need to take a look on graphExtnesion
- Regarding extension fields I suggest to set up them in the cache
Acumatica team put big amount of efforts in order to add stability to their products. Also they put a lot of efforts for giving line for adding stability to Acumatica by other ISV. It will be a crime not to benefit from it. Crime against customers!