Skip to content

Commit

Permalink
Json Deserialization method was not applying the correct DateTimeForm…
Browse files Browse the repository at this point in the history
…at (#532)

* Json Deserialization mehotd was not applying the same DateTimeFormat as Serialization method.

* Add unit test for cookie container serialization.
  • Loading branch information
claudiamurialdo authored Feb 2, 2022
1 parent 1c2a57f commit 70481e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Helpers/JSONHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ public static T Deserialize<T>(string kbObject, Encoding encoding, IEnumerable<T
{
try
{
var settings = SerializationSettings(knownTypes);
using (MemoryStream stream = new MemoryStream(encoding.GetBytes(kbObject)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T), knownTypes);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T), settings);
#pragma warning disable SCS0028 // Unsafe deserialization possible from {1} argument passed to '{0}'
return (T)serializer.ReadObject(stream);
#pragma warning restore SCS0028 // Unsafe deserialization possible from {1} argument passed to '{0}'
Expand Down
27 changes: 26 additions & 1 deletion dotnet/test/DotNetCoreUnitTest/Serialization.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GeneXus.Application;
using GeneXus.Encryption;
using GeneXus.Http;
using GeneXus.Utils;
using Microsoft.AspNetCore.Http;
using Xunit;

Expand All @@ -22,6 +22,15 @@ public async Task TestSessionRenew()

await authMiddleware.Invoke(httpContext);
}
[Fact]
public async Task TestSessionCookieContainer()
{
var httpContext = new DefaultHttpContext() { Session = new MockHttpSession() };
var authMiddleware = new MyAuthMiddleware(next: (innerHttpContext) => Task.FromResult(0));

await authMiddleware.SessionCookieContainerSerialization(httpContext);
}

}
public class MyAuthMiddleware
{
Expand All @@ -31,6 +40,22 @@ public MyAuthMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task SessionCookieContainerSerialization(HttpContext context)
{
GxContext gxcontext = new GxContext();
gxcontext.HttpContext = context;
string url = "https://test.net";
CookieContainer container = gxcontext.GetCookieContainer(url, true);
Cookie cookie = new Cookie("ROUTEID", ".http3");
cookie.Path = "/";
cookie.Expires = DateTime.MinValue;
cookie.Domain = "test.net";
container.Add(cookie);
gxcontext.UpdateSessionCookieContainer();
container = gxcontext.GetCookieContainer(url, true);
Assert.Equal(1, container.Count);
await _next(context);
}

public async Task Invoke(HttpContext context)
{
Expand Down

0 comments on commit 70481e3

Please sign in to comment.