Files
acceptance-tests
data
debian
docs
eglib
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
packages
src
test
Microsoft.TestCommon
Microsoft.Web.Helpers.Test
Microsoft.Web.Http.Data.Test
Microsoft.Web.Mvc.Test
Controls
ModelBinding
Properties
Test
AjaxOnlyAttributeTest.cs
AreaHelpersTest.cs
AsyncManagerExtensionsTest.cs
ButtonTest.cs
ContentTypeAttributeTest.cs
ControllerExtensionsTest.cs
CookieTempDataProviderTest.cs
CookieValueProviderFactoryTest.cs
CopyAsyncParametersAttributeTest.cs
CreditCardAttributeTest.cs
CssExtensionsTests.cs
DeserializeAttributeTest.cs
DynamicReflectionObjectTest.cs
DynamicViewDataDictionaryTest.cs
DynamicViewPageTest.cs
ElementalValueProviderTest.cs
EmailAddressAttribueTest.cs
ExpressionHelperTest.cs
FileExtensionsAttributeTest.cs
FormExtensionsTest.cs
ImageExtensionsTest.cs
MailToExtensionsTest.cs
ModelCopierTest.cs
MvcSerializerTest.cs
RadioExtensionsTest.cs
ReaderWriterCacheTest.cs
RenderActionTest.cs
ScriptExtensionsTest.cs
SerializationExtensionsTest.cs
ServerVariablesValueProviderFactoryTest.cs
SessionValueProviderFactoryTest.cs
SkipBindingAttributeTest.cs
SubmitButtonExtensionsTest.cs
SubmitImageExtensionsTest.cs
TempDataValueProviderFactoryTest.cs
TypeHelpersTest.cs
UrlAttributeTest.cs
ValueProviderUtilTest.cs
Microsoft.Web.Mvc.Test.csproj
packages.config
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
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
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
ikdasm
ikvm
linker
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
ikvm-native
libgc
llvm
m4
man
mcs
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
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-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/aspnetwebstack/test/Microsoft.Web.Mvc.Test/Test/MailToExtensionsTest.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

135 lines
6.7 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Web.UnitTestUtil;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace Microsoft.Web.Mvc.Test
{
public class MailToExtensionsTest
{
[Fact]
public void MailToWithoutEmailThrowsArgumentNullException()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
Assert.ThrowsArgumentNull(() => html.Mailto("link text", null), "emailAddress");
}
[Fact]
public void MailToWithoutLinkTextThrowsArgumentNullException()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
Assert.ThrowsArgumentNull(() => html.Mailto(null, "somebody@example.com"), "linkText");
}
[Fact]
public void MailToWithLinkTextAndEmailRendersProperElement()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com");
Assert.Equal("<a href=\"mailto:test@example.com\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithLinkTextEmailAndHtmlAttributesRendersAttributes()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", new { title = "this is a test" });
Assert.Equal("<a href=\"mailto:test@example.com\" title=\"this is a test\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithLinkTextEmailAndHtmlAttributesDictionaryRendersAttributes()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", new RouteValueDictionary(new { title = "this is a test" }));
Assert.Equal("<a href=\"mailto:test@example.com\" title=\"this is a test\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithSubjectAndHtmlAttributesRendersAttributes()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", "The subject", new { title = "this is a test" });
Assert.Equal("<a href=\"mailto:test@example.com?subject=The subject\" title=\"this is a test\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithSubjectAndHtmlAttributesDictionaryRendersAttributes()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", "The subject", new RouteValueDictionary(new { title = "this is a test" }));
Assert.Equal("<a href=\"mailto:test@example.com?subject=The subject\" title=\"this is a test\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToAttributeEncodesEmail()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "te\">st@example.com");
Assert.Equal("<a href=\"mailto:te&quot;>st@example.com\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithMultipleRecipientsRendersWithCommas()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "te\">st@example.com,test2@example.com");
Assert.Equal("<a href=\"mailto:te&quot;>st@example.com,test2@example.com\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithSubjectAppendsSubjectQuery()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", "This is the subject");
Assert.Equal("<a href=\"mailto:test@example.com?subject=This is the subject\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithCopyOnlyAppendsCopyQuery()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
MvcHtmlString result = html.Mailto("This is a test", "test@example.com", null, null, "cctest@example.com", null, null);
Assert.Equal("<a href=\"mailto:test@example.com?cc=cctest@example.com\">This is a test</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithMultipartBodyRendersProperMailtoEncoding()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
string body = @"Line one
Line two
Line three";
MvcHtmlString result = html.Mailto("email me", "test@example.com", null, body, null, null, null);
Assert.Equal("<a href=\"mailto:test@example.com?body=Line one%0ALine two%0ALine three\">email me</a>", result.ToHtmlString());
}
[Fact]
public void MailToWithAllValuesProvidedRendersCorrectTag()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
string body = @"Line one
Line two
Line three";
MvcHtmlString result = html.Mailto("email me", "test@example.com", "the subject", body, "cc@example.com", "bcc@example.com", new { title = "email test" });
string expected = @"<a href=""mailto:test@example.com?subject=the subject&amp;cc=cc@example.com&amp;bcc=bcc@example.com&amp;body=Line one%0ALine two%0ALine three"" title=""email test"">email me</a>";
Assert.Equal(expected, result.ToHtmlString());
}
[Fact]
public void MailToWithAttributesWithUnderscores()
{
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
string body = @"Line one
Line two
Line three";
MvcHtmlString result = html.Mailto("email me", "test@example.com", "the subject", body, "cc@example.com", "bcc@example.com", new { foo_bar = "baz" });
string expected = @"<a foo-bar=""baz"" href=""mailto:test@example.com?subject=the subject&amp;cc=cc@example.com&amp;bcc=bcc@example.com&amp;body=Line one%0ALine two%0ALine three"">email me</a>";
Assert.Equal(expected, result.ToHtmlString());
}
}
}