Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / RepeatInfoUser.cs
1 //
2 // Authors:
3 //      Ben Maurer <bmaurer@novell.com>
4 //
5 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.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 using System;
27 using System.IO;
28 using System.Web;
29 using System.Web.UI;
30 using System.Web.UI.WebControls;
31
32 namespace MonoTests.Helpers
33 {
34         public class RepeatInfoUser : IRepeatInfoUser
35         {
36                 bool footer;
37                 bool header;
38                 bool separators;
39                 int count;
40                 int counter;
41
42                 public RepeatInfoUser (bool header, bool footer, bool separators, int count)
43                 {
44                         this.footer = footer;
45                         this.header = header;
46                         this.separators = separators;
47                         this.count = count;
48                 }
49
50                 static HtmlTextWriter GetWriter ()
51                 {
52                         StringWriter sw = new StringWriter ();
53                         sw.NewLine = "\n";
54                         return new HtmlTextWriter (sw);
55                 }
56
57                 public static string DoTest (int cols, int cnt, RepeatDirection d, RepeatLayout l, bool OuterTableImplied, bool hdr, bool ftr, bool sep)
58                 {
59                         HtmlTextWriter htw = GetWriter ();
60                         RepeatInfo ri = new RepeatInfo ();
61                         ri.RepeatColumns = cols;
62                         ri.RepeatDirection = d;
63                         ri.RepeatLayout = l;
64                         ri.OuterTableImplied = OuterTableImplied;
65                         // get some variation in if we use style or not
66                         Style s = new Style ();
67                         if (cols != 3)
68                                 s.CssClass = "mainstyle";
69                         
70                         ri.RenderRepeater (htw, new RepeatInfoUser (hdr, ftr, sep, cnt), s, new DataList ());
71                         return htw.InnerWriter.ToString ();
72                 }
73
74
75                 public bool HasFooter {
76                         get { return footer; }
77                 }
78
79                 public bool HasHeader {
80                         get { return header; }
81                 }
82                 
83                 public bool HasSeparators {
84                         get { return separators; }
85                 }
86
87                 public int RepeatedItemCount {
88                         get { return count; }
89                 }
90
91                 public Style GetItemStyle (ListItemType itemType, int repeatIndex)
92                 {
93                         Style s = new Style ();
94                         s.CssClass = String.Format ("{0}{1}", itemType, repeatIndex);
95                         return s;
96                 }
97
98                 public void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
99                 {
100                         writer.Write ("({0},{1},{2})", counter++, itemType, repeatIndex);
101                 }
102         }
103 }