Files
data
debian
docs
eglib
external
Lucene.Net
Newtonsoft.Json
aspnetwebstack
packages
src
test
Microsoft.TestCommon
Microsoft.Web.Helpers.Test
Microsoft.Web.Http.Data.Test
Microsoft.Web.Mvc.Test
Microsoft.Web.WebPages.OAuth.Test
SPA.Test
System.Json.Test.Integration
System.Json.Test.Unit
System.Net.Http.Formatting.Test.Integration
System.Net.Http.Formatting.Test.Unit
System.Web.Helpers.Test
Properties
TestFiles
ChartTest.cs
ConversionUtilTest.cs
CryptoTest.cs
DynamicDictionary.cs
DynamicHelperTest.cs
DynamicWrapper.cs
HelperResultTest.cs
JsonTest.cs
ObjectInfoTest.cs
PreComputedGridDataSourceTest.cs
ServerInfoTest.cs
System.Web.Helpers.Test.csproj
WebCacheTest.cs
WebGridDataSourceTest.cs
WebGridTest.cs
WebImageTest.cs
WebMailTest.cs
XhtmlAssert.cs
packages.config
System.Web.Http.Integration.Test
System.Web.Http.SelfHost.Test
System.Web.Http.Test
System.Web.Http.WebHost.Test
System.Web.Mvc.Test
System.Web.Razor.Test
System.Web.WebPages.Administration.Test
System.Web.WebPages.Deployment.Test
System.Web.WebPages.Razor.Test
System.Web.WebPages.Test
WebMatrix.Data.Test
WebMatrix.WebData.Test
Settings.StyleCop
tools
.gitattributes
.gitignore
License.txt
README.md
Runtime.msbuild
Runtime.sln
Runtime.xunit
Settings.StyleCop
build.cmd
cecil
debian-snapshot
entityframework
ikdasm
ikvm
rx
ikvm-native
libgc
m4
man
mcs
mono
msvc
po
runtime
samples
scripts
support
tools
AUTHORS
COPYING.LIB
ChangeLog.REMOVED.git-id
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
build-mingw32.sh
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-core.spec
mono-core.spec.in
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/aspnetwebstack/test/System.Web.Helpers.Test/HelperResultTest.cs

75 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.IO;
using System.Web.WebPages;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Helpers.Test
{
/// <summary>
///This is a test class for Util is intended
///to contain all HelperResult Unit Tests
///</summary>
public class HelperResultTest
{
[Fact]
public void HelperResultConstructorNullTest()
{
Assert.ThrowsArgumentNull(() => { var helper = new HelperResult(null); }, "action");
}
[Fact]
public void ToStringTest()
{
var text = "Hello";
Action<TextWriter> action = tw => tw.Write(text);
var helper = new HelperResult(action);
Assert.Equal(text, helper.ToString());
}
[Fact]
public void WriteToTest()
{
var text = "Hello";
Action<TextWriter> action = tw => tw.Write(text);
var helper = new HelperResult(action);
var writer = new StringWriter();
helper.WriteTo(writer);
Assert.Equal(text, writer.ToString());
}
[Fact]
public void ToHtmlStringDoesNotEncode()
{
// Arrange
string text = "<strong>This is a test & it uses html.</strong>";
Action<TextWriter> action = writer => writer.Write(text);
HelperResult helperResult = new HelperResult(action);
// Act
string result = helperResult.ToHtmlString();
// Assert
Assert.Equal(result, text);
}
[Fact]
public void ToHtmlStringReturnsSameResultAsWriteTo()
{
// Arrange
string text = "<strong>This is a test & it uses html.</strong>";
Action<TextWriter> action = writer => writer.Write(text);
HelperResult helperResult = new HelperResult(action);
StringWriter stringWriter = new StringWriter();
// Act
string htmlString = helperResult.ToHtmlString();
helperResult.WriteTo(stringWriter);
// Assert
Assert.Equal(htmlString, stringWriter.ToString());
}
}
}