2
0

HtmlImageTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // HtmlImageTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlImage
  4. //
  5. // Author:
  6. // Dick Porter <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.IO;
  31. using System.Web.UI;
  32. using System.Web.UI.HtmlControls;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.UI.HtmlControls {
  35. public class TestHtmlImage : HtmlImage {
  36. public HtmlTextWriter GetWriter ()
  37. {
  38. StringWriter text = new StringWriter ();
  39. HtmlTextWriter writer = new HtmlTextWriter (text);
  40. base.RenderAttributes (writer);
  41. return writer;
  42. }
  43. }
  44. [TestFixture]
  45. public class HtmlImageTest {
  46. [Test]
  47. public void DefaultProperties ()
  48. {
  49. HtmlImage img = new HtmlImage ();
  50. Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
  51. Assert.AreEqual (String.Empty, img.Align, "Align");
  52. Assert.AreEqual (String.Empty, img.Alt, "Alt");
  53. Assert.AreEqual (-1, img.Border, "Border");
  54. Assert.AreEqual (-1, img.Height, "Height");
  55. Assert.AreEqual (String.Empty, img.Src, "Src");
  56. Assert.AreEqual (-1, img.Width, "Width");
  57. Assert.AreEqual ("img", img.TagName, "TagName");
  58. }
  59. [Test]
  60. public void NullProperties ()
  61. {
  62. HtmlImage img = new HtmlImage ();
  63. img.Align = null;
  64. Assert.AreEqual (String.Empty, img.Align, "Align");
  65. img.Alt = null;
  66. Assert.AreEqual (String.Empty, img.Alt, "Alt");
  67. img.Border = -1;
  68. Assert.AreEqual (-1, img.Border, "Border");
  69. img.Height = -1;
  70. Assert.AreEqual (-1, img.Height, "Height");
  71. img.Src = null;
  72. Assert.AreEqual (String.Empty, img.Src, "Src");
  73. img.Width = -1;
  74. Assert.AreEqual (-1, img.Width, "Width");
  75. Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
  76. }
  77. [Test]
  78. public void Negative ()
  79. {
  80. HtmlImage img = new HtmlImage ();
  81. img.Border = 10;
  82. img.Height = 20;
  83. img.Width = 30;
  84. Assert.AreEqual (3, img.Attributes.Count, "First Attributes Count");
  85. img.Border = -10;
  86. img.Height = -20;
  87. img.Width = -30;
  88. Assert.AreEqual (-10, img.Border, "Border");
  89. Assert.AreEqual (-20, img.Height, "Height");
  90. Assert.AreEqual (-30, img.Width, "Width");
  91. Assert.AreEqual (3, img.Attributes.Count, "Second Attributes Count");
  92. }
  93. [Test]
  94. public void RenderAttributes ()
  95. {
  96. TestHtmlImage img = new TestHtmlImage ();
  97. img.Align = "*1*";
  98. img.Alt = "*2*";
  99. img.Border = 3;
  100. img.Height = 4;
  101. img.Src = "*5*";
  102. img.Width = 6;
  103. Assert.AreEqual (6, img.Attributes.Count, "Attributes.Count");
  104. HtmlTextWriter writer = img.GetWriter ();
  105. Assert.AreEqual (" src=\"*5*\" align=\"*1*\" alt=\"*2*\" border=\"3\" height=\"4\" width=\"6\" /", writer.InnerWriter.ToString ());
  106. }
  107. }
  108. }