Esempio n. 1
0
        public void RequiredValidateFormat_File()
        {
            //Arrange
            var request = new Mock <HttpRequestBase>();

            request.SetupGet(x => x.Files[0]).Returns(() =>
            {
                //模擬一個無檔案名稱的上傳檔案
                var mockFile = new Mock <HttpPostedFileBase>();
                mockFile.SetupGet(x => x.FileName).Returns("");

                return(mockFile.Object);
            });

            var file = request.Object.Files[0];

            var value    = file.FileName;
            var field    = "上傳檔案";
            var expected = "請選擇上傳檔案";

            //Act
            RequestWrapper wrapper = new RequestWrapper(request.Object);

            wrapper.RequiredValidate(value, field, "請選擇{0}");
            var result = wrapper.GetErrorMessage(ErrorOuputType.Text);

            //Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void RequiredValidateFormat()
        {
            //Arrange
            var request  = new Mock <HttpRequestBase>();
            var value    = "";
            var field    = "使用者";
            var expected = "使用者為必填欄位";

            //Act
            RequestWrapper wrapper = new RequestWrapper(request.Object);

            wrapper.RequiredValidate(value, field, "{0}為必填欄位");
            var result = wrapper.GetErrorMessage(ErrorOuputType.Text);

            //Assert
            Assert.AreEqual(expected, result);
        }