コード例 #1
0
        public void UploadFor_should_generate_expected_html_code()
        {
            var helper        = MockFactories.CreateFakeHtmlHelper <DummyViewModel>();
            var mvcHtmlString = UploadExtensions.UploadFor(helper, model => model.TheFile);
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input id=\"TheFile\" name=\"TheFile\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }
コード例 #2
0
        public void Upload_should_generate_expected_html_code()
        {
            var helper        = MockFactories.CreateFakeHtmlHelper();
            var mvcHtmlString = UploadExtensions.Upload(helper, "myfile");
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input id=\"myfile\" name=\"myfile\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }
コード例 #3
0
        public void UploadFor_should_generate_expected_html_code_and_attributes_when_attributes_are_specified_using_anonymous_type()
        {
            var helper        = MockFactories.CreateFakeHtmlHelper <DummyViewModel>();
            var attributes    = new { @class = "fake", style = "text-align: left;" };
            var mvcHtmlString = UploadExtensions.UploadFor(helper, model => model.TheFile, attributes);
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input class=\"fake\" id=\"TheFile\" name=\"TheFile\" style=\"text-align: left;\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }
コード例 #4
0
        public void Upload_method_should_throw_ArgumentException_if_name_parameter_is_whitespace()
        {
            var helper = MockFactories.CreateFakeHtmlHelper();

            Executing.This(() => UploadExtensions.Upload(helper, "   "))
            .Should()
            .Throw <ArgumentException>()
            .And
            .ValueOf
            .ParamName
            .Should()
            .Be
            .EqualTo("name");
        }
コード例 #5
0
        public void UploadFor_should_generate_expected_html_code_when_nested_model_property_validation_is_required()
        {
            var helper = MockFactories.CreateFakeHtmlHelper <DummyParentViewModel>();

            helper.ViewContext.ClientValidationEnabled      = true;
            helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
            helper.ViewContext.FormContext = new FormContext();

            var mvcHtmlString = UploadExtensions.UploadFor(helper, model => model.Nested.TheRequestedFile);
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input data-val=\"true\" data-val-required=\"The TheRequestedFile field is required.\" id=\"Nested_TheRequestedFile\" name=\"Nested.TheRequestedFile\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }
コード例 #6
0
        public void UploadFor_method_should_throw_ArgumentNullException_if_expression_parameter_is_null()
        {
            var helper = MockFactories.CreateFakeHtmlHelper <object>();

            Executing.This(() => UploadExtensions.UploadFor(helper, (Expression <Func <object, bool> >)null))
            .Should()
            .Throw <ArgumentNullException>()
            .And
            .ValueOf
            .ParamName
            .Should()
            .Be
            .EqualTo("expression");
        }
コード例 #7
0
        public void Upload_should_generate_expected_html_code_and_attributes_when_attributes_are_specified_using_dictionary()
        {
            var helper     = MockFactories.CreateFakeHtmlHelper();
            var attributes = new Dictionary <string, object>()
            {
                { "class", "fake" },
                { "style", "text-align: left;" }
            };
            var mvcHtmlString = UploadExtensions.Upload(helper, "myfile", attributes);
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input class=\"fake\" id=\"myfile\" name=\"myfile\" style=\"text-align: left;\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }
コード例 #8
0
        public void UploadFor_should_generate_expected_html_code_and_attributes_when_nested_model_property_and_attributes_are_specified_using_anonymous_type_and_validation_is_required()
        {
            var helper = MockFactories.CreateFakeHtmlHelper <DummyParentViewModel>();

            helper.ViewContext.ClientValidationEnabled      = true;
            helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
            helper.ViewContext.FormContext = new FormContext();

            var attributes    = new { @class = "fake", style = "text-align: left;" };
            var mvcHtmlString = UploadExtensions.UploadFor(helper, model => model.Nested.TheRequestedFile, attributes);
            var generatedHtml = mvcHtmlString.ToString();
            var expectedHtml  = "<input class=\"fake\" data-val=\"true\" data-val-required=\"The TheRequestedFile field is required.\" id=\"Nested_TheRequestedFile\" name=\"Nested.TheRequestedFile\" style=\"text-align: left;\" type=\"file\" />";

            Assert.AreEqual <string>(expectedHtml, generatedHtml);
        }