Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,21 +898,30 @@ protected static object MakeRestType( object collectionValue, bool isApiObject)
{
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTLInterface", null);
}
if (restItemType == null)//Collection<SDTType> convert to GxGenericCollection<SDTType_RESTInterface>
else //Collection<SDTType> convert to GxGenericCollection<SDTType_RESTInterface>
{
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTInterface", null);
if (typeof(GxUserType).IsAssignableFrom(itemType)){
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTInterface", null);
}
else
{
collectionObject = collectionValue;
}
}
object[] attributes = restItemType.GetCustomAttributes(typeof(GxJsonSerialization), false);
IEnumerable<object> serializationAttributes = attributes.Where(a => a.GetType() == typeof(GxJsonSerialization));
if (serializationAttributes != null && serializationAttributes.Any<object>())
if (restItemType != null)
{
GxJsonSerialization attFmt = (GxJsonSerialization)serializationAttributes.FirstOrDefault();
wrappedStatus = attFmt.JsonUnwrapped;
isWrapped = (isApiObject)? ((wrappedStatus == "wrapped")? true: false): ((wrappedStatus == "unwrapped") ? false : true);
object[] attributes = restItemType.GetCustomAttributes(typeof(GxJsonSerialization), false);
IEnumerable<object> serializationAttributes = attributes.Where(a => a.GetType() == typeof(GxJsonSerialization));
if (serializationAttributes != null && serializationAttributes.Any<object>())
{
GxJsonSerialization attFmt = (GxJsonSerialization)serializationAttributes.FirstOrDefault();
wrappedStatus = attFmt.JsonUnwrapped;
isWrapped = (isApiObject) ? ((wrappedStatus == "wrapped") ? true : false) : ((wrappedStatus == "unwrapped") ? false : true);
}
isEmpty = !restItemType.IsDefined(typeof(GxOmitEmptyCollection), false);
Type genericListItemType = typeof(GxGenericCollection<>).MakeGenericType(restItemType);
collectionObject = Activator.CreateInstance(genericListItemType, new object[] { collectionValue, isWrapped, wrappedStatus });
}
isEmpty = !restItemType.IsDefined(typeof(GxOmitEmptyCollection), false);
Type genericListItemType = typeof(GxGenericCollection<>).MakeGenericType(restItemType);
collectionObject = Activator.CreateInstance(genericListItemType, new object[] { collectionValue, isWrapped , wrappedStatus});
}
// Empty collection serialized w/ noproperty
if (collectionObject is IList restList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
<None Update="apps\createsession.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apps\getcollection.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apps\getsdtcollection.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apps\getbccollection.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apps\httpcors.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
42 changes: 42 additions & 0 deletions dotnet/test/DotNetCoreWebUnitTest/Middleware/RestServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public RestServiceTest() : base()
{
ClassLoader.FindType("apps.append", "GeneXus.Programs.apps", "append", Assembly.GetExecutingAssembly(), true);//Force loading assembly for append procedure
ClassLoader.FindType("apps.saveimage", "GeneXus.Programs.apps", "saveimage", Assembly.GetExecutingAssembly(), true);//Force loading assembly for saveimage procedure
ClassLoader.FindType("apps.getcollection", "GeneXus.Programs.apps", "getcollection", Assembly.GetExecutingAssembly(), true);
ClassLoader.FindType("apps.getsdtcollection", "GeneXus.Programs.apps", "getsdtcollection", Assembly.GetExecutingAssembly(), true);
ClassLoader.FindType("apps.getbccollection", "GeneXus.Programs.apps", "getbccollection", Assembly.GetExecutingAssembly(), true);
server.AllowSynchronousIO = true;
}
const string serviceBodyResponse = "OK";
Expand Down Expand Up @@ -129,6 +132,7 @@ private async Task<HttpResponseMessage> RunController(HttpClient client)
return response;
}
string ACCESS_CONTROL_MAX_AGE_HEADER = "86400";

[Fact]
public async Task TestHttpResponseOnRestService()
{
Expand All @@ -140,6 +144,44 @@ public async Task TestHttpResponseOnRestService()
Assert.Equal(ACCESS_CONTROL_MAX_AGE_HEADER, values.FirstOrDefault());
}

[Fact]
public async Task TestRestServiceWithSimpleCollectionOutput()
{
server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();
HttpResponseMessage response = await client.PostAsync("rest/apps/getcollection", null);
response.EnsureSuccessStatusCode();
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
string responseBody = await response.Content.ReadAsStringAsync();
Assert.Equal("{\"CliType\":1,\"CliCode\":[1,2]}", responseBody);
}
[Fact]
public async Task TestRestServiceWithBCCollectionOutput()
{
server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();
HttpResponseMessage response = await client.PostAsync("rest/apps/getbccollection", null);
response.EnsureSuccessStatusCode();
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
string responseBody = await response.Content.ReadAsStringAsync();

string expected = "{\"InvoiceDate\":\"2024-02-02\",\"uri\":\"\"}";
Assert.Contains(expected, responseBody, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public async Task TestRestServiceWithSdtCollectionOutput()
{
server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();
HttpResponseMessage response = await client.PostAsync("rest/apps/getsdtcollection", null);
response.EnsureSuccessStatusCode();
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
string responseBody = await response.Content.ReadAsStringAsync();

string expected = "{\"CustomerId\":1,";
Assert.Contains(expected, responseBody, StringComparison.OrdinalIgnoreCase);
}

}

}
114 changes: 114 additions & 0 deletions dotnet/test/DotNetCoreWebUnitTest/apps/getbccollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using GeneXus.Application;
using GeneXus.Data.NTier;
using GeneXus.Procedure;
using GeneXus.Utils;
namespace GeneXus.Programs.apps
{
public class getbccollection : GXProcedure
{
public getbccollection()
{
context = new GxContext();
DataStoreUtil.LoadDataStores(context);
IsMain = true;
context.SetDefaultTheme("GeneXusXEv2", false);
}

public getbccollection(IGxContext context)
{
this.context = context;
IsMain = false;
}

public void execute(DateTime aP0_invoicedate,
short aP1_CustomerId,
string aP2_Customername,
out GXBCCollection<SdtInvoice> aP3_Gxm2rootcol)
{
this.AV6invoicedate = aP0_invoicedate;
this.AV5CustomerId = aP1_CustomerId;
this.AV7Customername = aP2_Customername;
this.Gxm2rootcol = new GXBCCollection<SdtInvoice>(context, "Invoice", "TestRestProcs");
initialize();
ExecuteImpl();
aP3_Gxm2rootcol = this.Gxm2rootcol;
}

public GXBCCollection<SdtInvoice> executeUdp(DateTime aP0_invoicedate,
short aP1_CustomerId,
string aP2_Customername)
{
execute(aP0_invoicedate, aP1_CustomerId, aP2_Customername, out aP3_Gxm2rootcol);
return Gxm2rootcol;
}

public void executeSubmit(DateTime aP0_invoicedate,
short aP1_CustomerId,
string aP2_Customername,
out GXBCCollection<SdtInvoice> aP3_Gxm2rootcol)
{
this.AV6invoicedate = aP0_invoicedate;
this.AV5CustomerId = aP1_CustomerId;
this.AV7Customername = aP2_Customername;
this.Gxm2rootcol = new GXBCCollection<SdtInvoice>(context, "Invoice", "TestRestProcs");
SubmitImpl();
aP3_Gxm2rootcol = this.Gxm2rootcol;
}

protected override void ExecutePrivate()
{
/* GeneXus formulas */
/* Output device settings */
Gxm1invoice = new SdtInvoice(context);
Gxm2rootcol.Add(Gxm1invoice, 0);
Gxm1invoice.gxTpr_Invoiceid = 1;
Gxm1invoice.gxTpr_Invoicedate = context.localUtil.YMDToD(2024, 1, 1);
Gxm1invoice.gxTpr_Customerid = 1;
Gxm3invoice_level = new SdtInvoice_Level(context);
Gxm1invoice.gxTpr_Level.Add(Gxm3invoice_level, 0);
Gxm3invoice_level.gxTpr_Invoicelevelid = 1;
Gxm3invoice_level.gxTpr_Productid = 1;
Gxm3invoice_level.gxTpr_Invoicelevelqty = 10;


Gxm1invoice = new SdtInvoice(context);
Gxm2rootcol.Add(Gxm1invoice, 0);
Gxm1invoice.gxTpr_Invoiceid = 2;
Gxm1invoice.gxTpr_Invoicedate = context.localUtil.YMDToD(2024, 2, 2);
Gxm1invoice.gxTpr_Customerid = 2;
Gxm3invoice_level = new SdtInvoice_Level(context);
Gxm1invoice.gxTpr_Level.Add(Gxm3invoice_level, 0);
Gxm3invoice_level.gxTpr_Invoicelevelid = 2;
Gxm3invoice_level.gxTpr_Productid = 2;
Gxm3invoice_level.gxTpr_Invoicelevelqty = 20;
cleanup();
}

public override void cleanup()
{
CloseCursors();
if (IsMain)
{
context.CloseConnections();
}
ExitApp();
}

public override void initialize()
{
Gxm1invoice = new SdtInvoice(context);
Gxm3invoice_level = new SdtInvoice_Level(context);
/* GeneXus formulas. */
}

private short AV5CustomerId;
private string AV7Customername;
private DateTime AV6invoicedate;
private GXBCCollection<SdtInvoice> Gxm2rootcol;
private SdtInvoice Gxm1invoice;
private SdtInvoice_Level Gxm3invoice_level;
private GXBCCollection<SdtInvoice> aP3_Gxm2rootcol;
}

}
1 change: 1 addition & 0 deletions dotnet/test/DotNetCoreWebUnitTest/apps/getbccollection.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ServiceHost Service= "GeneXus.Programs.apps.getbccollection,getbccollection" %>
81 changes: 81 additions & 0 deletions dotnet/test/DotNetCoreWebUnitTest/apps/getcollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using GeneXus.Application;
using GeneXus.Data.NTier;
using GeneXus.Procedure;
using GeneXus.Utils;
namespace GeneXus.Programs.apps
{
public class getcollection : GXProcedure
{
public getcollection( )
{
context = new GxContext( );
DataStoreUtil.LoadDataStores( context);
IsMain = true;
context.SetDefaultTheme("FromString", true);
}

public getcollection( IGxContext context )
{
this.context = context;
IsMain = false;
}

public void execute( out short aP0_CliType ,
out GxSimpleCollection<int> aP1_CliCode )
{
this.clitype = 0 ;
this.cliCod = new GxSimpleCollection<int>() ;
initialize();
ExecuteImpl();
aP0_CliType=this.clitype;
aP1_CliCode=this.cliCod;
}

public GxSimpleCollection<int> executeUdp( out short aP0_CliType )
{
execute(out aP0_CliType, out aP1_CliCode);
return cliCod ;
}

public void executeSubmit( out short aP0_CliType ,
out GxSimpleCollection<int> aP1_CliCode )
{
this.clitype = 0 ;
this.cliCod = new GxSimpleCollection<int>() ;
SubmitImpl();
aP0_CliType=this.clitype;
aP1_CliCode=this.cliCod;
}

protected override void ExecutePrivate( )
{
/* GeneXus formulas */
/* Output device settings */
clitype = 1;
cliCod.Add(1, 0);
cliCod.Add(2, 0);
this.cleanup();
}

public override void cleanup( )
{
CloseCursors();
if ( IsMain )
{
context.CloseConnections();
}
ExitApp();
}

public override void initialize( )
{
cliCod = new GxSimpleCollection<int>();

}

private short clitype ;
private GxSimpleCollection<int> cliCod ;
private GxSimpleCollection<int> aP1_CliCode ;
}

}
1 change: 1 addition & 0 deletions dotnet/test/DotNetCoreWebUnitTest/apps/getcollection.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ServiceHost Service= "GeneXus.Programs.apps.getcollection,apps.getcollection" %>
Loading