Skip to content

Commit a927c74

Browse files
Fix a broken case and add it to unit tests.
1 parent 66de4c6 commit a927c74

File tree

7 files changed

+1801
-22
lines changed

7 files changed

+1801
-22
lines changed

dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ private static void RestProcess(GXBaseObject worker, Dictionary<string, object>
875875

876876
protected static object MakeRestType( object collectionValue, bool isApiObject)
877877
{
878+
System.Diagnostics.Debugger.Launch();
878879
Type vType = collectionValue.GetType();
879880
Type itemType;
880881
if (vType.IsConstructedGenericType && typeof(IGxCollection).IsAssignableFrom(vType))
@@ -898,31 +899,27 @@ protected static object MakeRestType( object collectionValue, bool isApiObject)
898899
{
899900
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTLInterface", null);
900901
}
901-
else
902+
else if (typeof(IGxGenericCollectionItem).IsAssignableFrom(vType))//Collection<SDTType> convert to GxGenericCollection<SDTType_RESTInterface>
902903
{
903-
904-
if (typeof(IGxJSONSerializable).IsAssignableFrom(itemType))
905-
{
906-
if (restItemType == null)//Collection<SDTType> convert to GxGenericCollection<SDTType_RESTInterface>
907-
{
908-
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTInterface", null);
909-
}
910-
object[] attributes = restItemType.GetCustomAttributes(typeof(GxJsonSerialization), false);
911-
IEnumerable<object> serializationAttributes = attributes.Where(a => a.GetType() == typeof(GxJsonSerialization));
912-
if (serializationAttributes != null && serializationAttributes.Any<object>())
913-
{
914-
GxJsonSerialization attFmt = (GxJsonSerialization)serializationAttributes.FirstOrDefault();
915-
wrappedStatus = attFmt.JsonUnwrapped;
916-
isWrapped = (isApiObject) ? ((wrappedStatus == "wrapped") ? true : false) : ((wrappedStatus == "unwrapped") ? false : true);
917-
}
918-
isEmpty = !restItemType.IsDefined(typeof(GxOmitEmptyCollection), false);
919-
Type genericListItemType = typeof(GxGenericCollection<>).MakeGenericType(restItemType);
920-
collectionObject = Activator.CreateInstance(genericListItemType, new object[] { collectionValue, isWrapped, wrappedStatus });
921-
}
922-
else
904+
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTInterface", null);
905+
}
906+
else if (typeof(IGxJSONSerializable).IsAssignableFrom(vType))
907+
{
908+
collectionObject = collectionValue;
909+
}
910+
if (restItemType != null)
911+
{
912+
object[] attributes = restItemType.GetCustomAttributes(typeof(GxJsonSerialization), false);
913+
IEnumerable<object> serializationAttributes = attributes.Where(a => a.GetType() == typeof(GxJsonSerialization));
914+
if (serializationAttributes != null && serializationAttributes.Any<object>())
923915
{
924-
collectionObject = collectionValue;
916+
GxJsonSerialization attFmt = (GxJsonSerialization)serializationAttributes.FirstOrDefault();
917+
wrappedStatus = attFmt.JsonUnwrapped;
918+
isWrapped = (isApiObject) ? ((wrappedStatus == "wrapped") ? true : false) : ((wrappedStatus == "unwrapped") ? false : true);
925919
}
920+
isEmpty = !restItemType.IsDefined(typeof(GxOmitEmptyCollection), false);
921+
Type genericListItemType = typeof(GxGenericCollection<>).MakeGenericType(restItemType);
922+
collectionObject = Activator.CreateInstance(genericListItemType, new object[] { collectionValue, isWrapped, wrappedStatus });
926923
}
927924
}
928925
// Empty collection serialized w/ noproperty

dotnet/test/DotNetCoreWebUnitTest/DotNetCoreWebUnitTest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<None Update="apps\getcollection.svc">
6161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6262
</None>
63+
<None Update="apps\getsdtcollection.svc">
64+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
65+
</None>
6366
<None Update="apps\httpcors.svc">
6467
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6568
</None>

dotnet/test/DotNetCoreWebUnitTest/Middleware/RestServiceTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public RestServiceTest() : base()
2424
ClassLoader.FindType("apps.append", "GeneXus.Programs.apps", "append", Assembly.GetExecutingAssembly(), true);//Force loading assembly for append procedure
2525
ClassLoader.FindType("apps.saveimage", "GeneXus.Programs.apps", "saveimage", Assembly.GetExecutingAssembly(), true);//Force loading assembly for saveimage procedure
2626
ClassLoader.FindType("apps.getcollection", "GeneXus.Programs.apps", "getcollection", Assembly.GetExecutingAssembly(), true);
27+
ClassLoader.FindType("apps.getsdtcollection", "GeneXus.Programs.apps", "getsdtcollection", Assembly.GetExecutingAssembly(), true);
2728
server.AllowSynchronousIO = true;
2829
}
2930
const string serviceBodyResponse = "OK";
@@ -153,6 +154,19 @@ public async Task TestRestServiceWithSimpleCollectionOutput()
153154
string responseBody = await response.Content.ReadAsStringAsync();
154155
Assert.Equal("{\"CliType\":1,\"CliCode\":[1,2]}", responseBody);
155156
}
157+
[Fact]
158+
public async Task TestRestServiceWithSdtCollectionOutput()
159+
{
160+
server.AllowSynchronousIO = true;
161+
HttpClient client = server.CreateClient();
162+
HttpResponseMessage response = await client.PostAsync("rest/apps/getsdtcollection", null);
163+
response.EnsureSuccessStatusCode();
164+
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
165+
string responseBody = await response.Content.ReadAsStringAsync();
166+
167+
string expected = "{\"InvoiceDate\":\"2024-02-02\",\"uri\":\"\"}";
168+
Assert.Contains(expected, responseBody, StringComparison.OrdinalIgnoreCase);
169+
}
156170

157171
}
158172

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using GeneXus.Application;
3+
using GeneXus.Data.NTier;
4+
using GeneXus.Procedure;
5+
using GeneXus.Utils;
6+
namespace GeneXus.Programs.apps
7+
{
8+
public class getsdtcollection : GXProcedure
9+
{
10+
public getsdtcollection()
11+
{
12+
context = new GxContext();
13+
DataStoreUtil.LoadDataStores(context);
14+
IsMain = true;
15+
context.SetDefaultTheme("GeneXusXEv2", false);
16+
}
17+
18+
public getsdtcollection(IGxContext context)
19+
{
20+
this.context = context;
21+
IsMain = false;
22+
}
23+
24+
public void execute(DateTime aP0_invoicedate,
25+
short aP1_CustomerId,
26+
string aP2_Customername,
27+
out GXBCCollection<SdtInvoice> aP3_Gxm2rootcol)
28+
{
29+
this.AV6invoicedate = aP0_invoicedate;
30+
this.AV5CustomerId = aP1_CustomerId;
31+
this.AV7Customername = aP2_Customername;
32+
this.Gxm2rootcol = new GXBCCollection<SdtInvoice>(context, "Invoice", "TestRestProcs");
33+
initialize();
34+
ExecuteImpl();
35+
aP3_Gxm2rootcol = this.Gxm2rootcol;
36+
}
37+
38+
public GXBCCollection<SdtInvoice> executeUdp(DateTime aP0_invoicedate,
39+
short aP1_CustomerId,
40+
string aP2_Customername)
41+
{
42+
execute(aP0_invoicedate, aP1_CustomerId, aP2_Customername, out aP3_Gxm2rootcol);
43+
return Gxm2rootcol;
44+
}
45+
46+
public void executeSubmit(DateTime aP0_invoicedate,
47+
short aP1_CustomerId,
48+
string aP2_Customername,
49+
out GXBCCollection<SdtInvoice> aP3_Gxm2rootcol)
50+
{
51+
this.AV6invoicedate = aP0_invoicedate;
52+
this.AV5CustomerId = aP1_CustomerId;
53+
this.AV7Customername = aP2_Customername;
54+
this.Gxm2rootcol = new GXBCCollection<SdtInvoice>(context, "Invoice", "TestRestProcs");
55+
SubmitImpl();
56+
aP3_Gxm2rootcol = this.Gxm2rootcol;
57+
}
58+
59+
protected override void ExecutePrivate()
60+
{
61+
/* GeneXus formulas */
62+
/* Output device settings */
63+
Gxm1invoice = new SdtInvoice(context);
64+
Gxm2rootcol.Add(Gxm1invoice, 0);
65+
Gxm1invoice.gxTpr_Invoiceid = 1;
66+
Gxm1invoice.gxTpr_Invoicedate = context.localUtil.YMDToD(2024, 1, 1);
67+
Gxm1invoice.gxTpr_Customerid = 1;
68+
Gxm3invoice_level = new SdtInvoice_Level(context);
69+
Gxm1invoice.gxTpr_Level.Add(Gxm3invoice_level, 0);
70+
Gxm3invoice_level.gxTpr_Invoicelevelid = 1;
71+
Gxm3invoice_level.gxTpr_Productid = 1;
72+
Gxm3invoice_level.gxTpr_Invoicelevelqty = 10;
73+
74+
75+
Gxm1invoice = new SdtInvoice(context);
76+
Gxm2rootcol.Add(Gxm1invoice, 0);
77+
Gxm1invoice.gxTpr_Invoiceid = 2;
78+
Gxm1invoice.gxTpr_Invoicedate = context.localUtil.YMDToD(2024, 2, 2);
79+
Gxm1invoice.gxTpr_Customerid = 2;
80+
Gxm3invoice_level = new SdtInvoice_Level(context);
81+
Gxm1invoice.gxTpr_Level.Add(Gxm3invoice_level, 0);
82+
Gxm3invoice_level.gxTpr_Invoicelevelid = 2;
83+
Gxm3invoice_level.gxTpr_Productid = 2;
84+
Gxm3invoice_level.gxTpr_Invoicelevelqty = 20;
85+
cleanup();
86+
}
87+
88+
public override void cleanup()
89+
{
90+
CloseCursors();
91+
if (IsMain)
92+
{
93+
context.CloseConnections();
94+
}
95+
ExitApp();
96+
}
97+
98+
public override void initialize()
99+
{
100+
Gxm1invoice = new SdtInvoice(context);
101+
Gxm3invoice_level = new SdtInvoice_Level(context);
102+
/* GeneXus formulas. */
103+
}
104+
105+
private short AV5CustomerId;
106+
private string AV7Customername;
107+
private DateTime AV6invoicedate;
108+
private GXBCCollection<SdtInvoice> Gxm2rootcol;
109+
private SdtInvoice Gxm1invoice;
110+
private SdtInvoice_Level Gxm3invoice_level;
111+
private GXBCCollection<SdtInvoice> aP3_Gxm2rootcol;
112+
}
113+
114+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%@ServiceHost Service= "GeneXus.Programs.apps.getsdtcollection,getsdtcollection" %>

0 commit comments

Comments
 (0)