Tests: Add PageCommon tests
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using VAR.WebFormsCore.Code;
|
||||
using VAR.WebFormsCore.Tests.Fakes;
|
||||
@@ -17,6 +16,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
@@ -41,6 +42,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(value, result);
|
||||
}
|
||||
|
||||
@@ -54,6 +56,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(value, result);
|
||||
}
|
||||
|
||||
@@ -68,6 +71,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
@@ -82,6 +86,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
string result = fakeWebContext.GetRequestParameter(key);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
|
||||
@@ -96,6 +101,7 @@ public class ExtensionMethodsTests
|
||||
|
||||
fakeWebContext.ResponseObject(new object());
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||
Assert.Equal("{ }", fakeWebContext.FakeWritePackages[0].ToString());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public class ScriptsBundlerTests
|
||||
|
||||
scriptsBundler.ProcessRequest(fakeWebContext);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||
|
||||
// TODO: Verify contents of intrinsic scripts
|
||||
|
||||
@@ -14,6 +14,7 @@ public class StylesBundlerTests
|
||||
|
||||
stylesBundler.ProcessRequest(fakeWebContext);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||
|
||||
// TODO: Verify contents of intrinsic styles
|
||||
|
||||
@@ -41,7 +41,8 @@ public class FakeWebContext : IWebContext
|
||||
|
||||
public void ResponseRedirect(string url)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
ResponseStatusCode = 302;
|
||||
SetResponseHeader("location", url);
|
||||
}
|
||||
|
||||
public void AddResponseCookie(string cookieName, string value, DateTime? expiration = null)
|
||||
@@ -55,14 +56,16 @@ public class FakeWebContext : IWebContext
|
||||
}
|
||||
|
||||
public bool ResponseHasStarted => false;
|
||||
|
||||
public int ResponseStatusCode { get; set; }
|
||||
|
||||
public int ResponseStatusCode { get; set; } = 200;
|
||||
|
||||
public string? ResponseContentType { get; set; }
|
||||
|
||||
|
||||
public Dictionary<string, string> FakeResponseHeaders { get; } = new();
|
||||
|
||||
public void SetResponseHeader(string key, string value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
FakeResponseHeaders.Add(key, value);
|
||||
}
|
||||
|
||||
public void PrepareCacheableResponse()
|
||||
|
||||
@@ -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: """
|
||||
|
||||
@@ -14,6 +14,7 @@ public class FrmErrorTests
|
||||
|
||||
frmError.ProcessRequest(fakeWebContext);
|
||||
|
||||
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||
Assert.Equal(
|
||||
expected: """
|
||||
|
||||
52
VAR.WebFormsCore.Tests/Pages/PageCommonTests.cs
Normal file
52
VAR.WebFormsCore.Tests/Pages/PageCommonTests.cs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user