Skip to main content

Hi, I’m trying to create a unit test for my Extension Library, but retrieving a DAC Extension always returns null for some reason. I followed all the steps in T280 course but I still can’t get the DAC Extension. I am currently trying to create unit tests for version 22R1. Here is the code snippet:

 

using Xunit;
using PX.Data;
using PX.Tests.Unit;
using PX.Objects.CA;
using Custom.DAC;
using PX.Objects.GL;

namespace Customization.Tests
{
public class CashAccountMaintExtTest : TestBase
{
Fact]
public void TestingCashAccountExtension()
{
Setup<CashAccountMaint>(new GLSetup());
Setup<CashAccountMaint>(new CASetup());
var graph = PXGraph.CreateInstance<CashAccountMaint>();

CashAccount cashAccount = (CashAccount) graph.Cachesatypeof(CashAccount)].Insert(
new CashAccount
{
CashAccountCD = "Test"
}
);

//This always returns null
var cashAccountExt = cashAccount.GetExtension<CustomCashAccountExt>();
}
}
}

 

Is your extension in a separate dll? You can try something like that in the test constructor:


    AppDomain.CurrentDomain.Load("YourDll");

 

Does it help?


Hi Dmitrii thanks for the reply, I tried the solution. So, for reference here’s the change:
 

public class CashAccountMaintExtTest : TestBase
{
public CashAccountMaintExtTest()
{
AppDomain.CurrentDomain.Load("Customization");
}

Fact]
public void AccountTypeAndDefaultReferenceType()
{

Setup<CashAccountMaint>(new GLSetup());
Setup<CashAccountMaint>(new CASetup());
var graph = PXGraph.CreateInstance<CashAccountMaint>();

CashAccount cashAccount = (CashAccount) graph.Cacheshtypeof(CashAccount)].Insert(
new CashAccount
{
CashAccountCD = "Test"
}
);

var cashAccountExt = cashAccount.GetExtension<CustomCashAccountExt>();

Assert.NotNull(cashAccountExt);
}
}

The reference to the project is called “Customization” and the test project already references it in the same solution. However the test still returns a fail.


Could you share the entire project for me to try on my side?


I’ve finally found the reason for the error. I’ve been referencing the extension library project this whole time. When I switched to referencing the .dll file of the extension library from the bin folder of the instance the GetExtension<> method now returns the extension.


Thank you for sharing your solution with the community @naufal58 !


Reply