Solved

Getting extension in unit test returns null

  • 16 December 2022
  • 5 replies
  • 128 views

Userlevel 2
Badge

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>();
}
}
}

 

icon

Best answer by naufal58 9 January 2023, 13:19

View original

5 replies

Userlevel 7
Badge +5

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


    AppDomain.CurrentDomain.Load("YourDll");

 

Does it help?

Userlevel 2
Badge

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.

Userlevel 7
Badge +5

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

Userlevel 2
Badge

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.

Userlevel 7
Badge

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

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved