Skip to content

Commit 7641b1b

Browse files
committed
EDU-9495: Committed the project needed for completing the activities related to the Unit Test Framework for the AI-Assisted Diagnostics and Testing for Acumatica Customizations workshop/help guide
1 parent 862e582 commit 7641b1b

35 files changed

Lines changed: 3337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Xunit;
2+
using PX.Data;
3+
using PX.Tests.Unit;
4+
using PX.Objects.IN;
5+
using Autofac;
6+
using PX.Objects.CM.Extensions;
7+
using PhoneRepairShop;
8+
9+
namespace PhoneRepairShop_Code.Tests
10+
{
11+
public class InventoryItemMaintTests : TestBase
12+
{
13+
[Theory]
14+
[InlineData(true)]
15+
[InlineData(false)]
16+
public void RepairItemTypeEnabled_WhenRepairItemSelected
17+
(bool enabled)
18+
{
19+
var graph = PXGraph.CreateInstance<InventoryItemMaint>();
20+
21+
InventoryItem item =
22+
(InventoryItem)graph.Caches[typeof(InventoryItem)].Insert(
23+
new InventoryItem
24+
{
25+
InventoryCD = "Item1",
26+
Descr = "Item 1"
27+
});
28+
29+
InventoryItemExt itemExt = item.GetExtension<InventoryItemExt>();
30+
31+
itemExt.UsrRepairItem = enabled;
32+
graph.Caches[typeof(InventoryItem)].Update(item);
33+
PXFieldState fieldState =
34+
((PXFieldState)graph.Caches[typeof(InventoryItem)].GetStateExt<
35+
InventoryItemExt.usrRepairItemType>(item));
36+
Assert.True(enabled == fieldState.Enabled);
37+
}
38+
39+
protected override void RegisterServices(ContainerBuilder builder)
40+
{
41+
base.RegisterServices(builder);
42+
builder.RegisterType<PX.Objects.Unit.CurrencyServiceMock>().
43+
As<IPXCurrencyService>();
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<TargetFramework>net48</TargetFramework>
6+
<RootNamespace>PhoneRepairShop_Code.Tests</RootNamespace>
7+
<AssemblyName>PhoneRepairShop_Code.Tests</AssemblyName>
8+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
9+
<OutputPath>bin\$(Configuration)</OutputPath>
10+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
11+
<FileVersion>26.100.0217</FileVersion>
12+
<InformationalVersion>26.100.0217</InformationalVersion>
13+
<LangVersion>9.0</LangVersion>
14+
<Nullable>enable</Nullable>
15+
<Copyright>Copyright © 2005-2026 Acumatica, Inc. All rights reserved.</Copyright>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.7" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.7" />
20+
<PackageReference Include="Moq" Version="4.20.72" />
21+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
22+
<PackageReference Include="xunit" Version="2.4.2" />
23+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
24+
<PrivateAssets>all</PrivateAssets>
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
</PackageReference>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ProjectReference Include="..\PhoneRepairShop_Code\PhoneRepairShop_Code.csproj" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<Reference Include="Autofac">
34+
<HintPath>..\..\..\..\Bin\Autofac.dll</HintPath>
35+
</Reference>
36+
<Reference Include="PX.Common">
37+
<HintPath>..\..\..\..\Bin\PX.Common.dll</HintPath>
38+
</Reference>
39+
<Reference Include="PX.Common.Std">
40+
<HintPath>..\..\..\..\Bin\PX.Common.Std.dll</HintPath>
41+
</Reference>
42+
<Reference Include="PX.CS.Contracts">
43+
<HintPath>..\..\..\..\Bin\PX.CS.Contracts.dll</HintPath>
44+
</Reference>
45+
<Reference Include="PX.Data">
46+
<HintPath>..\..\..\..\Bin\PX.Data.dll</HintPath>
47+
</Reference>
48+
<Reference Include="PX.Data.BQL.Fluent">
49+
<HintPath>..\..\..\..\Bin\PX.Data.BQL.Fluent.dll</HintPath>
50+
</Reference>
51+
<Reference Include="PX.Objects">
52+
<HintPath>..\..\..\..\Bin\PX.Objects.dll</HintPath>
53+
</Reference>
54+
<Reference Include="PX.Web.Customization">
55+
<HintPath>..\..\..\..\Bin\PX.Web.Customization.dll</HintPath>
56+
</Reference>
57+
<Reference Include="PX.Tests.Unit">
58+
<HintPath>..\..\..\..\Bin\PX.Tests.Unit.dll</HintPath>
59+
</Reference>
60+
</ItemGroup>
61+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("PhoneRepairShop_Code.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Acumatica")]
12+
[assembly: AssemblyProduct("PhoneRepairShop_Code.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © Acumatica 2026")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c92d9eb5-4240-42c1-a525-1aa990672947")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using Xunit;
2+
using PX.Data;
3+
using PX.Objects.IN;
4+
using PX.Tests.Unit;
5+
using PhoneRepairShop;
6+
7+
namespace PhoneRepairShop_Code.Tests
8+
{
9+
public class RSSVRepairPriceMaintTests : TestBase
10+
{
11+
[Fact]
12+
public void TestServicesAndPricesForm()
13+
{
14+
var graph = PXGraph.CreateInstance<RSSVRepairPriceMaint>();
15+
16+
graph.Caches[typeof(RSSVDevice)].Insert(new RSSVDevice
17+
{
18+
DeviceCD = "Device1"
19+
});
20+
graph.Caches[typeof(RSSVRepairService)].Insert(new
21+
RSSVRepairService
22+
{
23+
ServiceCD = "Service1"
24+
});
25+
26+
RSSVRepairPrice repairPrice =
27+
(RSSVRepairPrice)graph.Caches[typeof(RSSVRepairPrice)].
28+
Insert(new RSSVRepairPrice());
29+
30+
InventoryItem battery1 = (InventoryItem)graph.
31+
Caches[typeof(InventoryItem)].Insert(new
32+
InventoryItem
33+
{
34+
InventoryCD = "Battery1"
35+
});
36+
graph.Caches[typeof(InventoryItemCurySettings)].Insert(new
37+
InventoryItemCurySettings
38+
{
39+
InventoryID = battery1.InventoryID,
40+
CuryID = "USD"
41+
});
42+
InventoryItemExt batteryExt1 =
43+
battery1.GetExtension<InventoryItemExt>();
44+
batteryExt1.UsrRepairItem = true;
45+
batteryExt1.UsrRepairItemType = RepairItemTypeConstants.Battery;
46+
graph.Caches[typeof(InventoryItem)].Update(battery1);
47+
48+
InventoryItem battery2 =
49+
(InventoryItem)graph.Caches[typeof(InventoryItem)].Insert(new
50+
InventoryItem
51+
{
52+
InventoryCD = "Battery2"
53+
});
54+
graph.Caches[typeof(InventoryItemCurySettings)].Insert(new
55+
InventoryItemCurySettings
56+
{
57+
InventoryID = battery2.InventoryID,
58+
CuryID = "USD"
59+
});
60+
InventoryItemExt batteryExt2 =
61+
battery2.GetExtension<InventoryItemExt>();
62+
batteryExt2.UsrRepairItem = true;
63+
batteryExt2.UsrRepairItemType = RepairItemTypeConstants.Battery;
64+
graph.Caches[typeof(InventoryItem)].Update(battery2);
65+
66+
InventoryItem backCover1 =
67+
(InventoryItem)graph.Caches[typeof(InventoryItem)].Insert(new
68+
InventoryItem
69+
{
70+
InventoryCD = "BackCover1"
71+
});
72+
graph.Caches[typeof(InventoryItemCurySettings)].Insert(new
73+
InventoryItemCurySettings
74+
{
75+
InventoryID = backCover1.InventoryID,
76+
CuryID = "USD"
77+
});
78+
InventoryItemExt backCoverExt1 =
79+
backCover1.GetExtension<InventoryItemExt>();
80+
backCoverExt1.UsrRepairItem = true;
81+
backCoverExt1.UsrRepairItemType = RepairItemTypeConstants.BackCover;
82+
graph.Caches[typeof(InventoryItem)].Update(backCover1);
83+
84+
InventoryItem work1 = (InventoryItem)graph.
85+
Caches[typeof(InventoryItem)].Insert(new InventoryItem
86+
{
87+
InventoryCD = "Work1",
88+
StkItem = false
89+
});
90+
91+
// Configure the back cover repair item
92+
RSSVRepairItem repairItemBackCover1 =
93+
(RSSVRepairItem)graph.Caches[typeof(RSSVRepairItem)].Insert(
94+
new RSSVRepairItem
95+
{
96+
InventoryID = backCover1.InventoryID,
97+
Required = true,
98+
BasePrice = 10,
99+
IsDefault = true
100+
});
101+
102+
// Configure the first battery repair item
103+
RSSVRepairItem repairItemBattery1 =
104+
(RSSVRepairItem)graph.Caches[typeof(RSSVRepairItem)].Insert(
105+
new RSSVRepairItem
106+
{
107+
InventoryID = battery1.InventoryID
108+
});
109+
repairItemBattery1.Required = true;
110+
repairItemBattery1.BasePrice = 20;
111+
repairItemBattery1.IsDefault = true;
112+
graph.Caches[typeof(RSSVRepairItem)].Update(repairItemBattery1);
113+
114+
// Configure the second battery repair item
115+
RSSVRepairItem repairItemBattery2 =
116+
(RSSVRepairItem)graph.Caches[typeof(RSSVRepairItem)].Insert(
117+
new RSSVRepairItem
118+
{ InventoryID = battery2.InventoryID });
119+
repairItemBattery2.Required = false;
120+
repairItemBattery2.BasePrice = 30;
121+
repairItemBattery2.IsDefault = true;
122+
graph.Caches[typeof(RSSVRepairItem)].Update(repairItemBattery2);
123+
124+
// 2nd battery is not required -> 1st battery is also not required
125+
Assert.False(repairItemBattery1.Required);
126+
// 2nd battery is used by default -> 1st battery is not used by default
127+
Assert.False(repairItemBattery1.IsDefault);
128+
// The back cover's Required and Default fields are not affected
129+
Assert.True(repairItemBackCover1.Required);
130+
Assert.True(repairItemBackCover1.IsDefault);
131+
132+
RSSVLabor labor = (RSSVLabor)graph.Caches[typeof(RSSVLabor)].
133+
Insert(new RSSVLabor
134+
{
135+
InventoryID = work1.InventoryID,
136+
DefaultPrice = 2,
137+
Quantity = 3
138+
});
139+
Assert.Equal(6, labor.ExtPrice);
140+
Assert.Equal(66, repairPrice.Price);
141+
}
142+
}
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Xunit;
2+
using PX.Data;
3+
using PX.Tests.Unit;
4+
using PhoneRepairShop;
5+
6+
namespace PhoneRepairShop_Code.Tests
7+
{
8+
public class RSSVRepairServiceMaintTests : TestBase
9+
{
10+
[Fact]
11+
public void PreliminaryCheckAndWalkInServiceFlags_AreOpposite()
12+
{
13+
var graph = PXGraph.CreateInstance<RSSVRepairServiceMaint>();
14+
15+
var repairService =
16+
graph.Caches[typeof(RSSVRepairService)].
17+
Insert(new RSSVRepairService
18+
{
19+
ServiceCD = "Service1",
20+
Description = "Service 1",
21+
WalkInService = true,
22+
PreliminaryCheck = false
23+
}) as RSSVRepairService;
24+
25+
if (repairService != null)
26+
{
27+
repairService.WalkInService = false;
28+
graph.Caches[typeof(RSSVRepairService)].Update(repairService);
29+
Assert.True(repairService.PreliminaryCheck);
30+
31+
repairService.WalkInService = true;
32+
graph.Caches[typeof(RSSVRepairService)].Update(repairService);
33+
Assert.False(repairService.PreliminaryCheck);
34+
35+
repairService.PreliminaryCheck = false;
36+
graph.Caches[typeof(RSSVRepairService)].Update(repairService);
37+
Assert.True(repairService.WalkInService);
38+
39+
repairService.PreliminaryCheck = true;
40+
graph.Caches[typeof(RSSVRepairService)].Update(repairService);
41+
Assert.False(repairService.WalkInService);
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)