Tests: Add tests:
* Control * Button * HiddenField * HtmlForm * HyperLink * Label * LiteralControl * Panel * TextBox * CTextBox
This commit is contained in:
69
VAR.WebFormsCore.Tests/Controls/ButtonTests.cs
Normal file
69
VAR.WebFormsCore.Tests/Controls/ButtonTests.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class ButtonTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
Button button = new();
|
||||||
|
page.Controls.Add(button);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<input type=""submit"" class=""button"" value=""""></input>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithOnClientClick()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
Button button = new()
|
||||||
|
{
|
||||||
|
OnClientClick = "alert(1)",
|
||||||
|
};
|
||||||
|
page.Controls.Add(button);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<input type=""submit"" class=""button"" value="""" onclick=""alert(1)""></input>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__ClickWithCommandArgument()
|
||||||
|
{
|
||||||
|
string commandArgument = "Test";
|
||||||
|
FakeWebContext fakeWebContext = new(requestMethod: "POST");
|
||||||
|
Page page = new();
|
||||||
|
Button button = new()
|
||||||
|
{
|
||||||
|
CommandArgument = commandArgument,
|
||||||
|
};
|
||||||
|
string? result = null;
|
||||||
|
button.Click += (o, _) =>
|
||||||
|
{
|
||||||
|
result = (o as Button)?.CommandArgument;
|
||||||
|
};
|
||||||
|
page.Controls.Add(button);
|
||||||
|
|
||||||
|
fakeWebContext.RequestForm.Add(button.ClientID, "Clicked");
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(commandArgument, result);
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
154
VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs
Normal file
154
VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class CTextBoxTests
|
||||||
|
{
|
||||||
|
#region MustRenderCorrectly
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
CTextBox cTextBox = new();
|
||||||
|
page.Controls.Add(cTextBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00_ctl00" name="ctl00_ctl00" class="textBox" onchange="ElementRemoveClass(this, 'textBoxInvalid');"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithMostProperties()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
CTextBox cTextBox = new()
|
||||||
|
{
|
||||||
|
CssClassExtra = "extraClass",
|
||||||
|
PlaceHolder = "Placeholder",
|
||||||
|
MarkedInvalid = true,
|
||||||
|
TextMode = TextBoxMode.Normal,
|
||||||
|
AllowEmpty = true,
|
||||||
|
KeepSize = true,
|
||||||
|
Text = "Test",
|
||||||
|
};
|
||||||
|
page.Controls.Add(cTextBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00_ctl00" name="ctl00_ctl00" class="textBox extraClass textBoxInvalid" onchange="ElementRemoveClass(this, 'textBoxInvalid');" placeholder="Placeholder" value="Test"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithNextFocusOnEnter()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
CTextBox cTextBox = new();
|
||||||
|
page.Controls.Add(cTextBox);
|
||||||
|
CTextBox cTextBox2 = new();
|
||||||
|
page.Controls.Add(cTextBox2);
|
||||||
|
cTextBox.NextFocusOnEnter = cTextBox2;
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00_ctl00" name="ctl00_ctl00" class="textBox" onchange="ElementRemoveClass(this, 'textBoxInvalid');" onkeydown="if(event.keyCode==13){document.getElementById('ctl01').focus(); return false;}"></input><input type="text" id="ctl01_ctl00" name="ctl01_ctl00" class="textBox" onchange="ElementRemoveClass(this, 'textBoxInvalid');"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion MustRenderCorrectly
|
||||||
|
|
||||||
|
#region IsEmpty
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__Empty__True()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = string.Empty, };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsEmpty();
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__Text__False()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = "Text", };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsEmpty();
|
||||||
|
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IsEmpty
|
||||||
|
|
||||||
|
#region IsValid
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__EmptyAllowEmptyFalse__False()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = string.Empty, AllowEmpty = false, };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsValid();
|
||||||
|
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__TextAllowEmptyFalse__True()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = "Text", AllowEmpty = false, };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsValid();
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__EmptyAllowEmptyTrue__True()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = string.Empty, AllowEmpty = true, };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsValid();
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsEmpty__TextAllowEmptyTrue__True()
|
||||||
|
{
|
||||||
|
CTextBox cTextBox = new() { Text = "Text", AllowEmpty = true, };
|
||||||
|
|
||||||
|
bool result = cTextBox.IsValid();
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion IsEmpty
|
||||||
|
|
||||||
|
}
|
||||||
25
VAR.WebFormsCore.Tests/Controls/ControlTests.cs
Normal file
25
VAR.WebFormsCore.Tests/Controls/ControlTests.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class ControlTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__Empty()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
Control control = new();
|
||||||
|
page.Controls.Add(control);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal("", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
VAR.WebFormsCore.Tests/Controls/HiddenFieldTests.cs
Normal file
63
VAR.WebFormsCore.Tests/Controls/HiddenFieldTests.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class HiddenFieldTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
HiddenField hiddenField = new();
|
||||||
|
page.Controls.Add(hiddenField);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<input type=""hidden"" id=""ctl00"" name=""ctl00""></input>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithValue()
|
||||||
|
{
|
||||||
|
string value = "Test";
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
HiddenField hiddenField = new() { Value = value };
|
||||||
|
page.Controls.Add(hiddenField);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(value, hiddenField.Value);
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<input type=""hidden"" id=""ctl00"" name=""ctl00"" value=""Test""></input>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithChangedValue()
|
||||||
|
{
|
||||||
|
string value = "Test";
|
||||||
|
string changedValue = "Changed";
|
||||||
|
FakeWebContext fakeWebContext = new(requestMethod: "POST");
|
||||||
|
Page page = new();
|
||||||
|
HiddenField hiddenField = new() { Value = value };
|
||||||
|
page.Controls.Add(hiddenField);
|
||||||
|
|
||||||
|
fakeWebContext.RequestForm.Add(hiddenField.ClientID, changedValue);
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(changedValue, hiddenField.Value);
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<input type=""hidden"" id=""ctl00"" name=""ctl00"" value=""Changed""></input>", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
VAR.WebFormsCore.Tests/Controls/HtmlFormTests.cs
Normal file
42
VAR.WebFormsCore.Tests/Controls/HtmlFormTests.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class HtmlFormTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
HtmlForm htmlForm = new();
|
||||||
|
page.Controls.Add(htmlForm);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<form method=""post"" action=""Page""></form>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithQueryParameters()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
fakeWebContext.RequestQuery.Add("test", "value");
|
||||||
|
Page page = new();
|
||||||
|
HtmlForm htmlForm = new();
|
||||||
|
page.Controls.Add(htmlForm);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<form method=""post"" action=""Page?&test=value""></form>", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ public class HtmlHeadTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MustRenderCorrectlyWithTitle()
|
public void MustRenderCorrectly__WithTitle()
|
||||||
{
|
{
|
||||||
FakeWebContext fakeWebContext = new();
|
FakeWebContext fakeWebContext = new();
|
||||||
Page page = new();
|
Page page = new();
|
||||||
@@ -41,7 +41,7 @@ public class HtmlHeadTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MustRenderCorrectlyWithMeta()
|
public void MustRenderCorrectly__WithMeta()
|
||||||
{
|
{
|
||||||
FakeWebContext fakeWebContext = new();
|
FakeWebContext fakeWebContext = new();
|
||||||
Page page = new();
|
Page page = new();
|
||||||
|
|||||||
45
VAR.WebFormsCore.Tests/Controls/HyperLinkTests.cs
Normal file
45
VAR.WebFormsCore.Tests/Controls/HyperLinkTests.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class HyperLinkTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
HyperLink hyperLink = new();
|
||||||
|
page.Controls.Add(hyperLink);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal("<a ></a>", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithTextAndUrl()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
HyperLink hyperLink = new()
|
||||||
|
{
|
||||||
|
NavigateUrl = "http://example.com",
|
||||||
|
Text = "Example.com"
|
||||||
|
};
|
||||||
|
page.Controls.Add(hyperLink);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"<a href=""http://example.com"">Example.com</a>", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
VAR.WebFormsCore.Tests/Controls/LabelTests.cs
Normal file
25
VAR.WebFormsCore.Tests/Controls/LabelTests.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class LabelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
Label label = new();
|
||||||
|
page.Controls.Add(label);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal("<span ></span>", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
VAR.WebFormsCore.Tests/Controls/LiteralControlTests.cs
Normal file
42
VAR.WebFormsCore.Tests/Controls/LiteralControlTests.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class LiteralControlTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__Empty()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
LiteralControl literalControl = new();
|
||||||
|
page.Controls.Add(literalControl);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(@"", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__AnyContent()
|
||||||
|
{
|
||||||
|
string anyContent = "AnyContent<script>alert(1)</script>";
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
LiteralControl literalControl = new(anyContent);
|
||||||
|
page.Controls.Add(literalControl);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(anyContent, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
VAR.WebFormsCore.Tests/Controls/PanelTests.cs
Normal file
25
VAR.WebFormsCore.Tests/Controls/PanelTests.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class PanelTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
Panel panel = new();
|
||||||
|
page.Controls.Add(panel);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal("<div ></div>", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
154
VAR.WebFormsCore.Tests/Controls/TextBoxTests.cs
Normal file
154
VAR.WebFormsCore.Tests/Controls/TextBoxTests.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using VAR.WebFormsCore.Controls;
|
||||||
|
using VAR.WebFormsCore.Pages;
|
||||||
|
using VAR.WebFormsCore.Tests.Fakes;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace VAR.WebFormsCore.Tests.Controls;
|
||||||
|
|
||||||
|
public class TextBoxTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__Normal()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new();
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00" name="ctl00"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__NormalWithText()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() { Text = "Text", };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00" name="ctl00" value="Text"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__Password()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() {TextMode = TextBoxMode.Password, };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="password" id="ctl00" name="ctl00"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__PasswordWithText()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() { TextMode = TextBoxMode.Password, Text = "Password", };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="password" id="ctl00" name="ctl00" value="Password"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__MultiLine()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() {TextMode = TextBoxMode.MultiLine, };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<textarea id="ctl00" name="ctl00"></textarea>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__MultiLineWithText()
|
||||||
|
{
|
||||||
|
FakeWebContext fakeWebContext = new();
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() { TextMode = TextBoxMode.MultiLine, Text = "Multi\nLine", };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<textarea id="ctl00" name="ctl00">Multi
|
||||||
|
Line</textarea>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MustRenderCorrectly__WithChangedText()
|
||||||
|
{
|
||||||
|
string text = "Test";
|
||||||
|
string changedValue = "Changed";
|
||||||
|
FakeWebContext fakeWebContext = new(requestMethod: "POST");
|
||||||
|
Page page = new();
|
||||||
|
TextBox textBox = new() { Text = text };
|
||||||
|
page.Controls.Add(textBox);
|
||||||
|
|
||||||
|
fakeWebContext.RequestForm.Add(textBox.ClientID, changedValue);
|
||||||
|
page.ProcessRequest(fakeWebContext);
|
||||||
|
|
||||||
|
Assert.Equal(changedValue, textBox.Text);
|
||||||
|
Assert.Equal(200, fakeWebContext.ResponseStatusCode);
|
||||||
|
Assert.Equal("text/html", fakeWebContext.ResponseContentType);
|
||||||
|
string result = fakeWebContext.FakeWritePackages.ToString("");
|
||||||
|
Assert.Equal(
|
||||||
|
expected: """
|
||||||
|
<input type="text" id="ctl00" name="ctl00" value="Changed"></input>
|
||||||
|
""",
|
||||||
|
actual: result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,7 +113,7 @@ public class CTextBox : Control, INamingContainer, IValidableControl
|
|||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
|
|
||||||
private bool IsEmpty() { return string.IsNullOrEmpty(_txtContent.Text); }
|
public bool IsEmpty() { return string.IsNullOrEmpty(_txtContent.Text); }
|
||||||
|
|
||||||
public bool IsValid() { return AllowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false); }
|
public bool IsValid() { return AllowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false); }
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class Control
|
|||||||
foreach (Control control in Controls) { control.OnInit(e); }
|
foreach (Control control in Controls) { control.OnInit(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public event EventHandler? Load;
|
public event EventHandler? Load;
|
||||||
|
|
||||||
protected virtual void Process() { }
|
protected virtual void Process() { }
|
||||||
|
|||||||
Reference in New Issue
Block a user