1 // 2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com) 3 // 4 // Authors: 5 // Andrew Skiba <andrews@mainsoft.com> 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining 8 // a copy of this software and associated documentation files (the 9 // "Software"), to deal in the Software without restriction, including 10 // without limitation the rights to use, copy, modify, merge, publish, 11 // distribute, sublicense, and/or sell copies of the Software, and to 12 // permit persons to whom the Software is furnished to do so, subject to 13 // the following conditions: 14 // 15 // The above copyright notice and this permission notice shall be 16 // included in all copies or substantial portions of the Software. 17 // 18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 // 26 27 using System; 28 using NUnit.Framework; 29 using System.Threading; 30 using System.Web.UI; 31 using System.Web.UI.WebControls; 32 using System.IO; 33 34 namespace MonoTests.System.Web.UI.WebControls 35 { 36 [TestFixture] 37 public class FileUploadTest 38 { 39 class PokerFileUpload : FileUpload 40 { DoRender(HtmlTextWriter writer)41 public void DoRender (HtmlTextWriter writer) 42 { 43 base.Render (writer); 44 } 45 } 46 47 [Test] RenderWithoutPageTest()48 public void RenderWithoutPageTest () 49 { 50 PokerFileUpload fu = new PokerFileUpload (); 51 using (StringWriter sw = new StringWriter ()) { 52 using (HtmlTextWriter htw = new HtmlTextWriter (sw)) { 53 fu.DoRender (htw); 54 } 55 sw.Close (); 56 string res = sw.ToString (); 57 Assert.AreEqual ("<input type=\"file\" />", res); 58 } 59 } 60 61 [Test] RenderWithPageTest()62 public void RenderWithPageTest () 63 { 64 PokerFileUpload fu = new PokerFileUpload (); 65 fu.Page = new Page (); 66 fu.Page.Controls.Add (fu); 67 68 using (StringWriter sw = new StringWriter ()) { 69 using (HtmlTextWriter htw = new HtmlTextWriter (sw)) { 70 fu.DoRender (htw); 71 } 72 sw.Close (); 73 } 74 } 75 76 [Test] RenderControlTest()77 public void RenderControlTest () 78 { 79 FileUpload fu = new FileUpload (); 80 fu.Page = new Page (); 81 string res; 82 using (StringWriter sw = new StringWriter ()) { 83 using (HtmlTextWriter htw = new HtmlTextWriter (sw)) { 84 fu.RenderControl (htw); 85 } 86 sw.Close (); 87 res = sw.ToString (); 88 } 89 Assert.AreEqual ("<input type=\"file\" />", res); 90 } 91 [Test] RenderBeginTagTest()92 public void RenderBeginTagTest () 93 { 94 FileUpload fu = new FileUpload (); 95 fu.Page = new Page (); 96 string res; 97 using (StringWriter sw = new StringWriter ()) { 98 using (HtmlTextWriter htw = new HtmlTextWriter (sw)) { 99 fu.RenderBeginTag (htw); 100 } 101 sw.Close (); 102 res = sw.ToString (); 103 } 104 Assert.AreEqual ("<input type=\"file\" />", res); 105 } 106 [Test] FileContentTest()107 public void FileContentTest () 108 { 109 FileUpload fu = new FileUpload (); 110 Stream s = fu.FileContent; 111 Assert.AreSame (s, Stream.Null); 112 } 113 114 } 115 } 116