public void GetMaxUploadSize_ValueSet_ReturnsValue() { var maxUploadSize = 20; WebConfigurationManagerHelper._maxUploadSize = maxUploadSize; Assert.Equal(maxUploadSize, WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig)); }
public void GetMaxUploadSize_MaxRequestLengthLessThan_ReturnsMaxRequestLength() { WebConfigurationManagerHelper._maxAllowedContentLength = MAX_CONTENTLENGTH_GREATER; _webConfig = new TestWebConfig(string.Format(XML_FORMAT, MAX_CONTENTLENGTH_LESS_THAN)); Assert.Equal( WebConfigurationManagerHelper.DefaultMaxRequestLength, WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig) ); }
public void GetMaxUploadSize_InvalidXml_ReturnsMaxRequestLength() { _webConfig = new TestWebConfig("<empty></empty>"); var result = WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig); Assert.Equal( WebConfigurationManagerHelper.DefaultMaxRequestLength, result ); }
public void GetMaxUploadSize_MaxRequestLengthNotLessThan_ReturnsMaxContentLength() { WebConfigurationManagerHelper._maxRequestLength = WebConfigurationManagerHelper.DefaultMaxRequestLength; var xml = string.Format(XML_FORMAT, MAX_CONTENTLENGTH_LESS_THAN); _webConfig = new TestWebConfig(xml); var result = WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig); Assert.Equal(MAX_CONTENTLENGTH_LESS_THAN, result); }
/// <summary> /// File upload HTML, ONLY USE ONCE PER View. You **MUST** pass a /// `HttpPostedFileBase` with parameter name 'fileUploadField' to the /// controller action. E.g.: /// public ActionResult Create(Model model, HttpPostedFileBase fileUploadField) /// </summary> public static MvcHtmlString FileUploadField( this HtmlHelper helper , string buttonText = DefaultButtonText , string[] accept = null ) { ScriptManagerHelper.AddInlineScript(helper, JavaScriptBlock, ScriptKey); ScriptManagerHelper.AddInlineScript(helper, "new FileUploadField().addListeners();"); var maxuploadSize = WebConfigurationManagerHelper.GetMaxUploadSize( new WebConfigHelper(helper.ViewContext.HttpContext.Request.ApplicationPath) ); return(new MvcHtmlString(string.Format( HtmlFormat , maxuploadSize , accept != null ? string.Format("accept='{0}'", string.Join(",", accept)) : string.Empty , buttonText , maxuploadSize / 1024 , accept != null ? string.Format(AcceptFormat, string.Join(",", accept)) : string.Empty ))); }