コード例 #1
0
        public void GetMaxRequestLength_ValueSet_ReturnsValue()
        {
            var setValue = 1;

            WebConfigurationManagerHelper._maxRequestLength = setValue;

            Assert.Equal(setValue, WebConfigurationManagerHelper.GetMaxRequestLength());
        }
コード例 #2
0
        public void GetMaxUploadSize_ValueSet_ReturnsValue()
        {
            var maxUploadSize = 20;

            WebConfigurationManagerHelper._maxUploadSize = maxUploadSize;

            Assert.Equal(maxUploadSize, WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig));
        }
コード例 #3
0
        public void GetMaxAllowedContentLength_InvalidPath_ReturnsDefault()
        {
            WebConfigurationManagerHelper._maxAllowedContentLength = 0;

            Assert.Equal(
                WebConfigurationManagerHelper.DefaultMaxAllowedContentLength,
                WebConfigurationManagerHelper.GetMaxAllowedContentLength(_webConfig)
                );
        }
コード例 #4
0
        public void GetMaxRequestLength_NotSet_GetsValue()
        {
            WebConfigurationManagerHelper._maxRequestLength = 0;

            Assert.Equal(
                WebConfigurationManagerHelper.DefaultMaxRequestLength,
                WebConfigurationManagerHelper.GetMaxRequestLength()
                );
        }
コード例 #5
0
        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)
                );
        }
コード例 #6
0
        public void GetMaxAllowedContentLength_ValueSet_ReturnsValue()
        {
            var setValue = 10;

            WebConfigurationManagerHelper._maxAllowedContentLength = setValue;

            Assert.Equal(
                setValue,
                WebConfigurationManagerHelper.GetMaxAllowedContentLength(_webConfig)
                );
        }
コード例 #7
0
        public void GetMaxUploadSize_InvalidXml_ReturnsMaxRequestLength()
        {
            _webConfig = new TestWebConfig("<empty></empty>");

            var result = WebConfigurationManagerHelper.GetMaxUploadSize(_webConfig);

            Assert.Equal(
                WebConfigurationManagerHelper.DefaultMaxRequestLength,
                result
                );
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        /// <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
                                         )));
        }