Skip to main content
Answer

Getting extension in unit test returns null

  • December 16, 2022
  • 5 replies
  • 202 views

Forum|alt.badge.img

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.Caches[typeof(CashAccount)].Insert(
new CashAccount
{
CashAccountCD = "Test"
}
);

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

 

Best answer by naufal58

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.

5 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 16, 2022

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


    AppDomain.CurrentDomain.Load("YourDll");

 

Does it help?


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • December 16, 2022

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.Caches[typeof(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.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • December 19, 2022

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


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • Answer
  • January 9, 2023

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.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 9, 2023

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