From 23bfda2d756aec0423a34246830cd046fbd0984b Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Thu, 1 Jun 2023 03:41:30 +0200 Subject: [PATCH] Tests: Add more tests to CTextBox. --- .../Controls/CTextBoxTests.cs | 223 ++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs b/VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs index 6069e10..7238eae 100644 --- a/VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs +++ b/VAR.WebFormsCore.Tests/Controls/CTextBoxTests.cs @@ -81,6 +81,229 @@ public class CTextBoxTests actual: result); } + [Fact] + public void MustRenderCorrectly__WithChangedText() + { + string text = "Test"; + string changedValue = "Changed"; + + FakeWebContext fakeWebContext0 = new(); + Page page0 = new(); + CTextBox cTextBox0 = new() { Text = text }; + page0.Controls.Add(cTextBox0); + page0.ProcessRequest(fakeWebContext0); + + FakeWebContext fakeWebContext1 = new(requestMethod: "POST"); + fakeWebContext1.RequestForm.Add(cTextBox0.TxtContent.ClientID, changedValue); + Page page1 = new(); + CTextBox cTextBox1 = new() { Text = text }; + page1.Controls.Add(cTextBox1); + page1.ProcessRequest(fakeWebContext1); + + Assert.Equal(changedValue, cTextBox1.Text); + Assert.Equal(200, fakeWebContext1.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext1.ResponseContentType); + string result = fakeWebContext1.FakeWritePackages.ToString(""); + Assert.Equal( + expected: """ + + """, + actual: result); + } + + [Fact] + public void MustRenderCorrectly_Multiline() + { + FakeWebContext fakeWebContext = new(); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + 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: """ + + + """, + actual: result); + } + + [Fact] + public void MustRenderCorrectly_Multiline__GetClientsideHeight__Null() + { + FakeWebContext fakeWebContext = new(requestMethod: "POST"); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + page.Controls.Add(cTextBox); + + page.ProcessRequest(fakeWebContext); + int? resultHeight = cTextBox.GetClientsideHeight(); + + Assert.Null(resultHeight); + Assert.Equal(200, fakeWebContext.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext.ResponseContentType); + string result = fakeWebContext.FakeWritePackages.ToString(""); + Assert.Equal( + expected: """ + + + """, + actual: result); + } + + [Fact] + public void MustRenderCorrectly_Multiline__GetAndSetClientsideHeight__100() + { + FakeWebContext fakeWebContext = new(requestMethod: "POST"); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + page.Controls.Add(cTextBox); + Button button = new(); + button.Click += (_, _) => + { + cTextBox.SetClientsideHeight(10); + cTextBox.SetClientsideHeight(100); + }; + page.Controls.Add(button); + + fakeWebContext.RequestForm.Add(button.ClientID, "Clicked"); + page.ProcessRequest(fakeWebContext); + int? resultHeight = cTextBox.GetClientsideHeight(); + + Assert.Equal(100, resultHeight); + Assert.Equal(200, fakeWebContext.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext.ResponseContentType); + string result = fakeWebContext.FakeWritePackages.ToString(""); + Assert.Equal( + expected: """ + + + """, + actual: result); + } + + [Fact] + public void MustRenderCorrectly_Multiline__GetAndSetClientsideHeight__Null() + { + FakeWebContext fakeWebContext = new(requestMethod: "POST"); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + page.Controls.Add(cTextBox); + Button button = new(); + button.Click += (_, _) => + { + cTextBox.SetClientsideHeight(null); + }; + page.Controls.Add(button); + + fakeWebContext.RequestForm.Add(button.ClientID, "Clicked"); + page.ProcessRequest(fakeWebContext); + int? resultHeight = cTextBox.GetClientsideHeight(); + + Assert.Null(resultHeight); + Assert.Equal(200, fakeWebContext.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext.ResponseContentType); + string result = fakeWebContext.FakeWritePackages.ToString(""); + Assert.Equal( + expected: """ + + + """, + actual: result); + } + + [Fact] + public void MustRenderCorrectly_Multiline__GetClientsideHeightInjectArray__Null() + { + FakeWebContext fakeWebContext = new(requestMethod: "POST"); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + page.Controls.Add(cTextBox); + Button button = new(); + button.Click += (_, _) => + { + if (cTextBox.HidSize != null) + { + cTextBox.HidSize.Value = "[]"; + } + }; + page.Controls.Add(button); + + fakeWebContext.RequestForm.Add(button.ClientID, "Clicked"); + page.ProcessRequest(fakeWebContext); + int? resultHeight = cTextBox.GetClientsideHeight(); + + Assert.Null(resultHeight); + Assert.Equal(200, fakeWebContext.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext.ResponseContentType); + } + + [Fact] + public void MustRenderCorrectly_Multiline__GetClientsideHeightInjectObject__Null() + { + FakeWebContext fakeWebContext = new(requestMethod: "POST"); + Page page = new(); + CTextBox cTextBox = new() + { + TextMode = TextBoxMode.MultiLine, + KeepSize = true, + }; + page.Controls.Add(cTextBox); + Button button = new(); + button.Click += (_, _) => + { + if (cTextBox.HidSize != null) + { + cTextBox.HidSize.Value = "{}"; + } + }; + page.Controls.Add(button); + + fakeWebContext.RequestForm.Add(button.ClientID, "Clicked"); + page.ProcessRequest(fakeWebContext); + int? resultHeight = cTextBox.GetClientsideHeight(); + + Assert.Null(resultHeight); + Assert.Equal(200, fakeWebContext.ResponseStatusCode); + Assert.Equal("text/html", fakeWebContext.ResponseContentType); + } + #endregion MustRenderCorrectly #region IsEmpty