/test/System.Web.Mvc.Test/Ajax/Test/AjaxExtensionsTest.cs
C# | 1122 lines | 728 code | 203 blank | 191 comment | 0 complexity | c549ba408efb84a2a3853749a1e72a9e MD5 | raw file
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Threading;
- using System.Web.Mvc.Html;
- using System.Web.Routing;
- using Microsoft.Web.UnitTestUtil;
- using Moq;
- using Xunit;
- using Assert = Microsoft.TestCommon.AssertEx;
- namespace System.Web.Mvc.Ajax.Test
- {
- public class AjaxExtensionsTest
- {
- // Guards
- [Fact]
- public void ActionLinkWithNullOrEmptyLinkTextThrows()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- // Act & Assert
- Assert.ThrowsArgumentNullOrEmpty(
- delegate { MvcHtmlString actionLink = ajaxHelper.ActionLink(String.Empty, String.Empty, null, null, null, null); },
- "linkText");
- }
- [Fact]
- public void RouteLinkWithNullOrEmptyLinkTextThrows()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- // Act & Assert
- Assert.ThrowsArgumentNullOrEmpty(
- delegate { MvcHtmlString actionLink = ajaxHelper.RouteLink(String.Empty, String.Empty, null, null, null); },
- "linkText");
- }
- // Form context setup and cleanup
- [Fact]
- public void BeginFormSetsAndRestoresToDefault()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- ajaxHelper.ViewContext.FormContext = null;
- FormContext defaultFormContext = ajaxHelper.ViewContext.FormContext;
- // Act & assert - push
- MvcForm theForm = ajaxHelper.BeginForm(new AjaxOptions());
- Assert.NotNull(ajaxHelper.ViewContext.FormContext);
- Assert.NotEqual(defaultFormContext, ajaxHelper.ViewContext.FormContext);
- // Act & assert - pop
- theForm.Dispose();
- Assert.Equal(defaultFormContext, ajaxHelper.ViewContext.FormContext);
- }
- [Fact]
- public void DisposeWritesClosingFormTag()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- AjaxOptions ajaxOptions = new AjaxOptions { UpdateTargetId = "some-id" };
- StringWriter writer = new StringWriter();
- ajaxHelper.ViewContext.Writer = writer;
- // Act
- IDisposable form = ajaxHelper.BeginForm("Action", "Controller", ajaxOptions);
- form.Dispose();
- // Assert
- Assert.True(writer.ToString().EndsWith("</form>"));
- }
- // GlobalizationScript
- [Fact]
- public void GlobalizationScriptWithNullCultureInfoThrows()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- // Act & Assert
- Assert.ThrowsArgumentNull(
- delegate { ajaxHelper.GlobalizationScript(null); },
- "cultureInfo");
- }
- [Fact]
- public void GlobalizationScriptUsesCurrentCultureAsDefault()
- {
- CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
- try
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- AjaxHelper.GlobalizationScriptPath = null;
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
- // Act
- MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript();
- // Assert
- Assert.Equal(@"<script src=""~/Scripts/Globalization/en-GB.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
- }
- finally
- {
- Thread.CurrentThread.CurrentCulture = currentCulture;
- }
- }
- [Fact]
- public void GlobalizationScriptWithCultureInfo()
- {
- CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
- try
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper();
- AjaxHelper.GlobalizationScriptPath = null;
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
- // Act
- MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript(CultureInfo.GetCultureInfo("en-CA"));
- // Assert
- Assert.Equal(@"<script src=""~/Scripts/Globalization/en-CA.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
- }
- finally
- {
- Thread.CurrentThread.CurrentCulture = currentCulture;
- }
- }
- [Fact]
- public void GlobalizationScriptEncodesSource()
- {
- // Arrange
- Mock<CultureInfo> xssCulture = new Mock<CultureInfo>("en-US");
- xssCulture.Setup(culture => culture.Name).Returns("evil.example.com/<script>alert('XSS!')</script>");
- string globalizationPath = "~/Scripts&Globalization";
- string expectedScriptTag = @"<script src=""~/Scripts&Globalization/evil.example.com%2f%3cscript%3ealert(%27XSS!%27)%3c%2fscript%3e.js"" type=""text/javascript""></script>";
- // Act
- MvcHtmlString globalizationScript = AjaxExtensions.GlobalizationScriptHelper(globalizationPath, xssCulture.Object);
- // Assert
- Assert.Equal(expectedScriptTag, globalizationScript.ToHtmlString());
- }
- [Fact]
- public void GlobalizationScriptWithNullCultureName()
- {
- // Arrange
- Mock<CultureInfo> xssCulture = new Mock<CultureInfo>("en-US");
- xssCulture.Setup(culture => culture.Name).Returns((string)null);
- AjaxHelper ajaxHelper = GetAjaxHelper();
- AjaxHelper.GlobalizationScriptPath = null;
- // Act
- MvcHtmlString globalizationScript = ajaxHelper.GlobalizationScript(xssCulture.Object);
- // Assert
- Assert.Equal(@"<script src=""~/Scripts/Globalization/.js"" type=""text/javascript""></script>", globalizationScript.ToHtmlString());
- }
- // ActionLink (traditional JavaScript)
- [Fact]
- public void ActionLinkWithNullActionName()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithNullActionName_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithNullActionNameAndNullOptions()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, null);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithNullActionNameAndNullOptions_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", null, null);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLink()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLink_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkAnonymousValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object values = new { controller = "Controller" };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkAnonymousValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object values = new { controller = "Controller" };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkAnonymousValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
- object values = new { controller = "Controller" };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkAnonymousValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
- object values = new { controller = "Controller" };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkTypedValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkTypedValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkTypedValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkTypedValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkController()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkController_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerAnonymousValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object values = new { id = 5 };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerAnonymousValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object values = new { id = 5 };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerAnonymousValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
- object values = new { id = 5 };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerAnonymousValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object htmlAttributes = new { foo = "bar", baz = "quux", foo_bar = "baz_quux" };
- object values = new { id = 5 };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerTypedValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "id", 5 }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerTypedValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "id", 5 }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerTypedValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "id", 5 }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkControllerTypedValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "id", 5 }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.ActionLink("Some Text", "Action", "Controller", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action/5"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithOptions()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", new AjaxOptions { UpdateTargetId = "some-id" });
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'some-id' });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithOptions_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "some-id" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithNullHostName()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller",
- null, null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'some-id' });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithNullHostName_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller",
- null, null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithProtocol()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", "https", null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
- // Assert
- Assert.Equal(@"<a href=""https://foo.bar.baz" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'some-id' });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void ActionLinkWithProtocol_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.ActionLink("linkText", "Action", "Controller", "https", null, null, null, new AjaxOptions { UpdateTargetId = "some-id" }, null);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#some-id"" href=""https://foo.bar.baz" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- // RouteLink
- [Fact]
- public void RouteLinkWithNullOptions()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString routeLink = ajaxHelper.RouteLink("Some Text", new RouteValueDictionary(), null);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">Some Text</a>", routeLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkWithNullOptions_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString routeLink = ajaxHelper.RouteLink("Some Text", new RouteValueDictionary(), null);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/home/oldaction"">Some Text</a>", routeLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkAnonymousValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString routeLink = helper.RouteLink("Some Text", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", routeLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkAnonymousValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString routeLink = helper.RouteLink("Some Text", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", routeLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkAnonymousValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkAnonymousValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkTypedValues()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options);
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkTypedValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options);
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkTypedValuesAndAttributes()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkTypedValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper helper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object>
- {
- { "foo", "bar" },
- { "baz", "quux" },
- { "foo_bar", "baz_quux" }
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = helper.RouteLink("Some Text", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRoute()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRoute_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteAnonymousAttributes()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteAnonymousAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteTypedAttributes()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteTypedAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/home/oldaction"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteWithAnonymousValues()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteWithAnonymousValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteAnonymousValuesAndAttributes()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteAnonymousValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- object values = new
- {
- action = "Action",
- controller = "Controller"
- };
- object htmlAttributes = new
- {
- foo = "bar",
- baz = "quux",
- foo_bar = "baz_quux"
- };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax-update=""#update-div"" foo=""bar"" foo-bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteWithTypedValues()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteWithTypedValues_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("linkText", "namedroute", values, new AjaxOptions());
- // Assert
- Assert.Equal(@"<a data-ajax=""true"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"">linkText</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteTypedValuesAndAttributes()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: false);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" foo=""bar"" foo_bar=""baz_quux"" href=""" + MvcHelper.AppPathModifier + @"/app/named/Controller/Action"" onclick=""Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'update-div' });"">Some Text</a>", actionLink.ToHtmlString());
- }
- [Fact]
- public void RouteLinkNamedRouteTypedValuesAndAttributes_Unobtrusive()
- {
- // Arrange
- AjaxHelper ajaxHelper = GetAjaxHelper(unobtrusiveJavaScript: true);
- RouteValueDictionary values = new RouteValueDictionary
- {
- { "controller", "Controller" },
- { "action", "Action" }
- };
- Dictionary<string, object> htmlAttributes = new Dictionary<string, object> { { "foo", "bar" }, { "baz", "quux" }, { "foo_bar", "baz_quux" } };
- AjaxOptions options = new AjaxOptions { UpdateTargetId = "update-div" };
- // Act
- MvcHtmlString actionLink = ajaxHelper.RouteLink("Some Text", "namedroute", values, options, htmlAttributes);
- // Assert
- Assert.Equal(@"<a baz=""quux"" data-ajax=""true"" data-ajax-mode=""replace"" data-ajax