Tests: Add PageCommon tests

This commit is contained in:
2023-05-29 03:27:24 +02:00
parent 2fd6cc5d1d
commit b8ab4766d4
7 changed files with 73 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ public class FrmEchoTests
frmEcho.ProcessRequest(fakeWebContext);
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """
@@ -35,6 +36,7 @@ public class FrmEchoTests
frmEcho.ProcessRequest(fakeWebContext);
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """
@@ -56,6 +58,7 @@ public class FrmEchoTests
frmEcho.ProcessRequest(fakeWebContext);
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """

View File

@@ -14,6 +14,7 @@ public class FrmErrorTests
frmError.ProcessRequest(fakeWebContext);
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """

View File

@@ -0,0 +1,52 @@
using VAR.WebFormsCore.Pages;
using VAR.WebFormsCore.Tests.Fakes;
using Xunit;
namespace VAR.WebFormsCore.Tests.Pages;
public class PageCommonTests
{
#region ProcessRequest TestForm
private class TestEmptyForm : PageCommon
{
public TestEmptyForm(bool mustBeAuthenticated)
{
MustBeAuthenticated = mustBeAuthenticated;
}
}
[Fact]
public void ProcessRequest__TestEmptyForm()
{
FakeWebContext fakeWebContext = new();
TestEmptyForm testEmptyForm = new(mustBeAuthenticated: false);
testEmptyForm.ProcessRequest(fakeWebContext);
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """
<!DOCTYPE html>
<html ><head ><meta content="IE=Edge" http-equiv="X-UA-Compatible" /><meta content="text/html; charset=utf-8" http-equiv="content-type" /><meta name="author" /><meta name="Copyright" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=4, user-scalable=1" /><script type="text/javascript" src="ScriptsBundler?v=1.0.0.0"></script>
<link href="StylesBundler?v=1.0.0.0" type="text/css" rel="stylesheet"/>
</head><body ><form id="formMain" name="formMain" method="post" action="TestEmptyForm"><div class="divHeader"><a href="."><h1 ></h1></a><input type="submit" id="ctl00_btnPostback" name="ctl00_btnPostback" class="button" style="display: none;" value="Postback"></input><div class="divUserInfo"></div></div><div class="divContent"></div></form></body></html>
""",
actual: result);
}
[Fact]
public void ProcessRequest__TestEmptyFormNotAuthenticated__RedirectToFrmLogin()
{
FakeWebContext fakeWebContext = new();
TestEmptyForm testEmptyForm = new(mustBeAuthenticated: true);
testEmptyForm.ProcessRequest(fakeWebContext);
Assert.Equal(302, fakeWebContext.ResponseStatusCode);
Assert.Equal(string.Empty, fakeWebContext.FakeResponseHeaders["location"]);
}
#endregion ProcessRequest TestForm
}