Enhance dictionary safety with SafeGet, SafeSet, and SafeRemove methods. Adjust IWebContext and related tests to support nullable value types in dictionary operations. Refactor GetRequestParameter for clarity and consistency.

This commit is contained in:
2025-07-29 02:05:28 +02:00
parent bab8898841
commit b7b7c472af
12 changed files with 55 additions and 34 deletions

View File

@@ -1,3 +1,4 @@
using VAR.WebFormsCore.Code;
using VAR.WebFormsCore.Pages;
using VAR.WebFormsCore.Tests.Fakes;
using Xunit;
@@ -31,7 +32,7 @@ public class FrmEchoTests
public void ProcessRequest__OneQueryParameterGet__FormData()
{
FakeWebContext fakeWebContext = new();
fakeWebContext.RequestQuery.Add("Test", "Value");
fakeWebContext.RequestQuery.SafeSet("Test", "Value");
FrmEcho frmEcho = new();
frmEcho.ProcessRequest(fakeWebContext);
@@ -53,7 +54,7 @@ public class FrmEchoTests
public void ProcessRequest__OneFormParameterPost__FormData()
{
FakeWebContext fakeWebContext = new(requestMethod: "POST");
fakeWebContext.RequestForm.Add("Test", "Value");
fakeWebContext.RequestForm.SafeSet("Test", "Value");
FrmEcho frmEcho = new();
frmEcho.ProcessRequest(fakeWebContext);

View File

@@ -55,7 +55,7 @@ public class PageCommonTests
(GlobalConfig.Get() as FakeGlobalConfig)?.FakeSetLoginHandler(loginHandler);
(GlobalConfig.Get() as FakeGlobalConfig)?.FakeSetAuthenticated(true);
FakeWebContext fakeWebContext = new(requestMethod: "POST");
fakeWebContext.RequestForm.Add("ctl00_ctl02_btnLogout", "Logout");
fakeWebContext.RequestForm.SafeSet("ctl00_ctl02_btnLogout", "Logout");
TestEmptyForm testEmptyForm = new(mustBeAuthenticated: true);
testEmptyForm.ProcessRequest(fakeWebContext);