public void DisposeTwiceRendersCloseFormTagOnce() { // Arrange Mock <HttpResponseBase> mockHttpResponse = GetHttpResponseForForm(); MvcForm form = new MvcForm(mockHttpResponse.Object); // Act form.Dispose(); form.Dispose(); // Assert mockHttpResponse.Verify(); }
public void DisposeTwiceRendersCloseFormTagOnce() { // Arrange StringWriter writer = new StringWriter(); ViewContext viewContext = GetViewContext(writer); MvcForm form = new MvcForm(viewContext); // Act form.Dispose(); form.Dispose(); // Assert Assert.Equal("</form>", writer.ToString()); }
public void DisposeTwiceRendersCloseFormTagOnce() { // Arrange StringWriter writer = new StringWriter(); ViewContext viewContext = GetViewContext(writer); MvcForm form = new MvcForm(viewContext); // Act form.Dispose(); form.Dispose(); // Assert Assert.Equal("</form>", writer.ToString()); }
public void BeginFormWithClientValidationEnabled() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); htmlHelper.ViewContext.ClientValidationEnabled = true; htmlHelper.ViewContext.FormContext = null; FormContext defaultFormContext = htmlHelper.ViewContext.FormContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.NotNull(htmlHelper.ViewContext.FormContext); Assert.NotEqual(defaultFormContext, htmlHelper.ViewContext.FormContext); Assert.Equal("form_id", htmlHelper.ViewContext.FormContext.FormId); // Act & assert - pop theForm.Dispose(); Assert.Equal(defaultFormContext, htmlHelper.ViewContext.FormContext); Assert.Equal(@"<form action=""/some/path"" id=""form_id"" method=""post""></form><script type=""text/javascript""> //<![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({""Fields"":[],""FormId"":""form_id"",""ReplaceValidationSummary"":false}); //]]> </script>", writer.ToString()); }
public void BeginFormWithClientValidationEnabled() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); FormContext originalContext = new FormContext(); htmlHelper.ViewContext.ClientValidationEnabled = true; htmlHelper.ViewContext.FormContext = originalContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.IsNotNull(htmlHelper.ViewContext.FormContext); Assert.AreNotEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext should have been set to a new instance."); Assert.AreEqual("form_id", htmlHelper.ViewContext.FormContext.FormId); // Act & assert - pop theForm.Dispose(); Assert.AreEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext was not properly restored."); Assert.AreEqual(@"<form action=""/some/path"" id=""form_id"" method=""post""></form><script type=""text/javascript""> //<![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({""Fields"":[],""FormId"":""form_id"",""ReplaceValidationSummary"":false}); //]]> </script>", writer.ToString()); }
protected override string ClosingHtml() { if (_form != null) { _form.Dispose(); } return(null); }
public void Dispose() { //_helper.ViewContext.Writer.Write("</form>"); if (frm != null) { frm.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (!string.IsNullOrEmpty(_endTags)) { _viewContext.Writer.Write(_endTags); } _form.Dispose(); } }
public void BeginFormWithClientValidationAndUnobtrusiveJavaScriptEnabled() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); htmlHelper.ViewContext.ClientValidationEnabled = true; htmlHelper.ViewContext.UnobtrusiveJavaScriptEnabled = true; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.Null(htmlHelper.ViewContext.FormContext.FormId); // Act & assert - pop theForm.Dispose(); Assert.Equal(@"<form action=""/some/path"" method=""post""></form>", writer.ToString()); }
public void BeginFormSetsAndRestoresFormContext() { // Arrange AjaxHelper ajaxHelper = GetAjaxHelper(); FormContext originalContext = new FormContext(); ajaxHelper.ViewContext.FormContext = originalContext; // Act & assert - push MvcForm theForm = ajaxHelper.BeginForm(new AjaxOptions()); Assert.IsNotNull(ajaxHelper.ViewContext.FormContext); Assert.AreNotEqual(originalContext, ajaxHelper.ViewContext.FormContext, "FormContext should have been set to a new instance."); // Act & assert - pop theForm.Dispose(); Assert.AreEqual(originalContext, ajaxHelper.ViewContext.FormContext, "FormContext was not properly restored."); }
public void BeginFormSetsAndRestoresToDefault() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); htmlHelper.ViewContext.FormContext = null; FormContext defaultFormContext = htmlHelper.ViewContext.FormContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.NotNull(htmlHelper.ViewContext.FormContext); Assert.NotEqual(defaultFormContext, htmlHelper.ViewContext.FormContext); // Act & assert - pop theForm.Dispose(); Assert.Equal(defaultFormContext, htmlHelper.ViewContext.FormContext); Assert.Equal(@"<form action=""/some/path"" method=""post""></form>", writer.ToString()); }
public void BeginFormSetsAndRestoresFormContext() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); FormContext originalContext = new FormContext(); htmlHelper.ViewContext.FormContext = originalContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.IsNotNull(htmlHelper.ViewContext.FormContext); Assert.AreNotEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext should have been set to a new instance."); // Act & assert - pop theForm.Dispose(); Assert.AreEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext was not properly restored."); Assert.AreEqual(@"<form action=""/some/path"" method=""post""></form>", writer.ToString()); }
/// <summary> /// Finish writing the HTML for the form. /// </summary> public void Dispose() { _form.Dispose(); }