Tests: Add test for FrmEcho.
This commit is contained in:
@@ -97,7 +97,7 @@ public class ExtensionMethodsTests
|
||||
fakeWebContext.ResponseObject(new object());
|
||||
|
||||
Assert.Single(fakeWebContext.FakeWritePackages);
|
||||
Assert.Equal("{ }", Encoding.UTF8.GetString(fakeWebContext.FakeWritePackages[0].Bin ?? Array.Empty<byte>()));
|
||||
Assert.Equal("{ }", fakeWebContext.FakeWritePackages[0].ToString());
|
||||
}
|
||||
|
||||
#endregion ResponseObject
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Text;
|
||||
using VAR.WebFormsCore.Code;
|
||||
|
||||
namespace VAR.WebFormsCore.Tests.Fakes;
|
||||
@@ -21,12 +22,6 @@ public class FakeWebContext : IWebContext
|
||||
|
||||
public Dictionary<string, string?> RequestForm { get; } = new();
|
||||
|
||||
public struct WritePackage
|
||||
{
|
||||
public string? Text { get; set; }
|
||||
public byte[]? Bin { get; set; }
|
||||
}
|
||||
|
||||
public List<WritePackage> FakeWritePackages { get; } = new();
|
||||
|
||||
public void ResponseWrite(string text)
|
||||
@@ -80,3 +75,35 @@ public class FakeWebContext : IWebContext
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public struct WritePackage
|
||||
{
|
||||
public string? Text { get; set; }
|
||||
public byte[]? Bin { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Text != null)
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
|
||||
if (Bin == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string text = Encoding.UTF8.GetString(Bin ?? Array.Empty<byte>());
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WritePackageExtensions
|
||||
{
|
||||
public static string ToString(this List<WritePackage> list, string separator)
|
||||
{
|
||||
IEnumerable<string> listStrings = list.Select(x => x.ToString());
|
||||
string result = string.Join(separator, listStrings);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
67
VAR.WebFormsCore.Tests/Pages/FrmEchoTests.cs
Normal file
67
VAR.WebFormsCore.Tests/Pages/FrmEchoTests.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using VAR.WebFormsCore.Pages;
|
||||
using VAR.WebFormsCore.Tests.Fakes;
|
||||
using Xunit;
|
||||
|
||||
namespace VAR.WebFormsCore.Tests.Pages;
|
||||
|
||||
public class FrmEchoTests
|
||||
{
|
||||
[Fact]
|
||||
public void ProcessRequest__Empty__Empty()
|
||||
{
|
||||
FakeWebContext fakeWebContext = new();
|
||||
FrmEcho frmEcho = new();
|
||||
|
||||
frmEcho.ProcessRequest(fakeWebContext);
|
||||
|
||||
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||
Assert.Equal(
|
||||
expected: """
|
||||
<pre><code>Header:{ }
|
||||
Query:{ }
|
||||
Form:{ }
|
||||
</code></pre>
|
||||
""",
|
||||
actual: result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessRequest__OneQueryParameterGet__FormData()
|
||||
{
|
||||
FakeWebContext fakeWebContext = new();
|
||||
fakeWebContext.RequestQuery.Add("Test", "Value");
|
||||
FrmEcho frmEcho = new();
|
||||
|
||||
frmEcho.ProcessRequest(fakeWebContext);
|
||||
|
||||
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||
Assert.Equal(
|
||||
expected: """
|
||||
<pre><code>Header:{ }
|
||||
Query:{ "Test": "Value" }
|
||||
Form:{ }
|
||||
</code></pre>
|
||||
""",
|
||||
actual: result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProcessRequest__OneFormParameterPost__FormData()
|
||||
{
|
||||
FakeWebContext fakeWebContext = new(requestMethod: "POST");
|
||||
fakeWebContext.RequestForm.Add("Test", "Value");
|
||||
FrmEcho frmEcho = new();
|
||||
|
||||
frmEcho.ProcessRequest(fakeWebContext);
|
||||
|
||||
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||
Assert.Equal(
|
||||
expected: """
|
||||
<pre><code>Header:{ }
|
||||
Query:{ }
|
||||
Form:{ "Test": "Value" }
|
||||
</code></pre>
|
||||
""",
|
||||
actual: result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user