Beispiel #1
0
        public void FileExtensionValidation__Invalid__Image()
        {
            //Arrange
            var request = new Mock <HttpRequestBase>();

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

                return(mockFile.Object);
            });

            var file     = request.Object.Files[0];
            var value    = file.FileName;
            var field    = "上傳檔案";
            var expected = "上傳檔案不支援 .doc 檔案格式";

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

            wrapper.FileExtensionValidate(new ImageFileExtensions(), value, true, field);
            var result = wrapper.GetErrorMessage(ErrorOuputType.Text);

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