Tests: Cover test for FrmError.

This commit is contained in:
2023-05-29 01:52:55 +02:00
parent 82b237f7fd
commit 2fd6cc5d1d
4 changed files with 36 additions and 5 deletions

View File

@@ -72,7 +72,7 @@ public class FakeWebContext : IWebContext
public void PrepareUncacheableResponse() public void PrepareUncacheableResponse()
{ {
throw new NotImplementedException(); // TODO: Mark as Uncacheable response
} }
} }

View File

@@ -17,7 +17,8 @@ public class FrmEchoTests
string result = fakeWebContext.FakeWritePackages.ToString(""); string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal( Assert.Equal(
expected: """ expected: """
<pre><code>Header:{ } <pre><code>
Header:{ }
Query:{ } Query:{ }
Form:{ } Form:{ }
</code></pre> </code></pre>
@@ -37,7 +38,8 @@ public class FrmEchoTests
string result = fakeWebContext.FakeWritePackages.ToString(""); string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal( Assert.Equal(
expected: """ expected: """
<pre><code>Header:{ } <pre><code>
Header:{ }
Query:{ "Test": "Value" } Query:{ "Test": "Value" }
Form:{ } Form:{ }
</code></pre> </code></pre>
@@ -57,7 +59,8 @@ public class FrmEchoTests
string result = fakeWebContext.FakeWritePackages.ToString(""); string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal( Assert.Equal(
expected: """ expected: """
<pre><code>Header:{ } <pre><code>
Header:{ }
Query:{ } Query:{ }
Form:{ "Test": "Value" } Form:{ "Test": "Value" }
</code></pre> </code></pre>

View File

@@ -0,0 +1,28 @@
using VAR.WebFormsCore.Pages;
using VAR.WebFormsCore.Tests.Fakes;
using Xunit;
namespace VAR.WebFormsCore.Tests.Pages;
public class FrmErrorTests
{
[Fact]
public void ProcessRequest__TestException()
{
FakeWebContext fakeWebContext = new();
FrmError frmError = new(new Exception("Test"));
frmError.ProcessRequest(fakeWebContext);
string result = fakeWebContext.FakeWritePackages.ToString("");
Assert.Equal(
expected: """
<!DOCTYPE html>
<html ><head ><title>Application Error</title><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="FrmError"><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"><h2 >Application Error</h2><p><b>Message:</b> Test</p><p><b>Stacktrace:</b></p><div class="divCode"><pre><code></code></pre></div></div></form></body></html>
""",
actual: result);
}
}

View File

@@ -10,7 +10,7 @@ public class FrmEcho : IHttpHandler
public void ProcessRequest(IWebContext context) public void ProcessRequest(IWebContext context)
{ {
context.ResponseContentType = "text/html"; context.ResponseContentType = "text/html";
context.ResponseWrite("<pre><code>"); context.ResponseWrite("<pre><code>\n");
context.ResponseWrite($"Header:{JsonWriter.WriteObject(context.RequestHeader, indent: true)}\n"); context.ResponseWrite($"Header:{JsonWriter.WriteObject(context.RequestHeader, indent: true)}\n");
context.ResponseWrite($"Query:{JsonWriter.WriteObject(context.RequestQuery, indent: true)}\n"); context.ResponseWrite($"Query:{JsonWriter.WriteObject(context.RequestQuery, indent: true)}\n");
context.ResponseWrite($"Form:{JsonWriter.WriteObject(context.RequestForm, indent: true)}\n"); context.ResponseWrite($"Form:{JsonWriter.WriteObject(context.RequestForm, indent: true)}\n");