Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GHTBaseWeb.cs « utils « MainsoftWebApp « mainsoft « Test « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff0ff9ae741b70a36464ba6495d231a8ae5fe5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
//
// Authors:
//   Rafael Mizrahi   <rafim@mainsoft.com>
//   Erez Lotan       <erezl@mainsoft.com>
//   Vladimir Krasnov <vladimirk@mainsoft.com>
//   
// 
// Copyright (c) 2002-2005 Mainsoft Corporation.
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using GHTWebControls;

namespace GHTTests
{
    /// <summary>
    /// Summary description for GHTBaseWeb.
    /// </summary>
    public class GHTBaseWeb : System.Web.UI.Page
    {
        public HtmlForm GHTActiveForm;
        public Control GHTActiveSubTest;
        public int GHTActiveSubTestId = 0;

        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);
        }

        /// <summary>
        /// Save a reference to the Form.
        /// </summary>
        public virtual void GHTTestBegin(HtmlForm theForm)
        {
            GHTActiveForm = theForm;
        }

        /// <summary>
        /// not implemented yet. use it as a stub
        /// </summary>
        public void GHTTestEnd()
        {
            
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void GHTSubTestBegin()
        {
            GHTSubTestBegin("");
        }
        public void GHTSubTestBegin(string Description)
        {
            GHTSubTestCreateNew(Description);
        }

        /// <summary>
        /// not implemented yet. use it as a stub
        /// </summary>
        public void GHTSubTestEnd()
        {
            
        }
 
        /// <summary>
        /// Add a result to Sub Test.
        /// </summary>
        /// <param name="SubTestControl">The SubTestControl to add the result to.</param>
        /// <param name="TraceText">The text to add.</param>
        /// <param name="asText">Whether to include as plain text, or to interpret special HTML charachters as HTML.</param>
		public void GHTSubTestAddResult(Control SubTestControl, string TraceText, bool asText)
        {
			if (asText)
			{
				TraceText = GHTHtmlToText(TraceText);
			}
			
			Label lbl = new Label();
			lbl.Text = "<br>" + TraceText;
			SubTestControl.Controls.Add(lbl);

//				TableCell tempCell = new TableCell();
//				TableRow tempRow = new TableRow();
//				tempCell.Controls.Add( new LiteralControl(TraceText));
//				tempRow.Controls.Add(tempCell); 
//				SubTestControl.Controls.Add(tempRow);

        }
		public void GHTSubTestAddResult(string TraceText)
		{
			GHTSubTestAddResult(TraceText, false);
		}
		public void GHTSubTestAddResult(string TraceText, bool asText)
		{
			GHTSubTestAddResult(GHTActiveSubTest, TraceText, asText);
		}
		public void GHTSubTestAddResult(Control SubTestControl, string TraceText)
		{
			GHTSubTestAddResult(SubTestControl, TraceText,false);
		}
		// Replaces Html special charachters to escape charachters in the returned string:
		// Orig --> Result
		//-----		   ------
		//  <				&lt;
		//	 >				&gt;
		//	 "				&quot;
		// &				&amp;
		public string GHTHtmlToText(string a_text)
		{
			string res = string.Empty;
			res = a_text.Replace("<", "&lt;");
			res = res.Replace(">", "&gt;");
			res = res.Replace("\"", "&quot;");
			return res;
		}

		protected void GHTSubTestExpectedExceptionCaught(System.Exception ex)
		{
			GHTSubTestAddResult("Test passed. Expected exception was caught.");
		}
		protected void GHTSubTestExpectedExceptionNotCaught(string ExceptionName)
		{
			GHTSubTestAddResult("Test failed. Expected " + ExceptionName + " exception was not caught.");
		}
		protected void GHTSubTestUnexpectedExceptionCaught(System.Exception ex)
		{
			string traceText = string.Empty;
			traceText += "Test Failed. Unxpected ";
			traceText += ex.GetType().Name;
			traceText += " exception was caught";
			traceText += "<br>Stack Trace: ";
			traceText += ex.ToString();

			GHTSubTestAddResult(traceText);
		}

		protected void Compare(Object Result, Object ExpectedResult)
		{
			if (Result.Equals(ExpectedResult))
				GHTSubTestAddResult("Test Passed.");
			else
				GHTSubTestAddResult("Test Failed. Result:" + GHTNormalizeToString(Result.ToString()) + ". Expected Result:" + GHTNormalizeToString(ExpectedResult.ToString()));
											 
		}
        /// <summary>
        /// Create a new SubTest conteiner.
        /// </summary>
        protected GHTWebControls.GHTSubTest GHTSubTestCreateNew()
        {
            return GHTSubTestCreateNew("");
        }
        protected GHTWebControls.GHTSubTest GHTSubTestCreateNew(string Description)
        {
            return GHTSubTestCreateNew(GHTActiveForm, Description);
        }
        protected GHTWebControls.GHTSubTest GHTSubTestCreateNew(HtmlForm theForm, string Description)
        {
			if (GHTActiveSubTestId == 0)
			{
				GHTActiveSubTestId++;
			}

			while (theForm.FindControl("GHTSubTest" + GHTActiveSubTestId) != null)
			{
				GHTActiveSubTestId++;
			}

            GHTActiveForm = theForm;
            GHTWebControls.GHTSubTest subtest = new GHTWebControls.GHTSubTest();
            subtest.ID = "GHTSubTest" + GHTActiveSubTestId;
			subtest.Description = Description;
			subtest.Attributes.Add("TestName",Description);
            theForm.Controls.Add(subtest);
            GHTActiveSubTest = subtest;
            return subtest;
        }
        
        /// <summary>
        /// Create a new Element (e.g. Control).
        /// </summary>
        protected Object GHTElementClone(Type type)
        {
            return type.GetConstructor(Type.EmptyTypes).Invoke(null);
        }

        /// <summary>
        /// Common Tests of WebControl.
        /// </summary>
        protected void GHTTestCommon_WebControl(WebControl obj, string MemberName)
        {
            WebControl objNew;
            bool bExceptionCaught = false;
            MemberName = MemberName.ToLower();

            //AccessKey
            if (MemberName.CompareTo("AccessKey".ToLower())== 0)
            {
                //Press Alt-Y to get focus here
                obj.AccessKey = ""; //empty is ok
                obj.AccessKey = "Y";
                objNew = (WebControl)GHTElementClone(obj.GetType());
                // test Exceptions
                try
                {
                    objNew.AccessKey = "XX";
                    GHTActiveSubTest.Controls.Add(objNew);
                }
                catch (ArgumentException)
                {
                    bExceptionCaught = true;
                }
                if (bExceptionCaught == true)
                {
                    GHTSubTestAddResult(GHTActiveSubTest, MemberName + " ArgumentException OK");
                }
                bExceptionCaught = false;
                
            }

            //Attributes tested at System.Web.UI.AttributeCollection

            //BackColor
            if (MemberName.CompareTo("BackColor".ToLower())== 0)
            {
                obj.BackColor = System.Drawing.Color.AliceBlue;
                
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.BackColor = System.Drawing.Color.Magenta;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //BorderColor
            if (MemberName.CompareTo("BorderColor".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.BorderColor = System.Drawing.Color.AliceBlue;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //BorderStyle
            if (MemberName.CompareTo("BorderStyle".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.BorderStyle = System.Web.UI.WebControls.BorderStyle.Dotted;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //BorderWidth
            if (MemberName.CompareTo("BorderWidth".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.BorderWidth = 10;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            // ControlStyle
            // ControlStyleCreated
            
            //CssClass
            if (MemberName.CompareTo("CssClass".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.CssClass = "zoobie";
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //Enabled
            if (MemberName.CompareTo("Enabled".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.Enabled = true;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //Font
            if (MemberName.CompareTo("Font".ToLower())== 0)
            {
                GHTSubTestAddResult(GHTActiveSubTest, MemberName + " " + obj.Font.ToString());
            }

            //ForeColor
            if (MemberName.CompareTo("ForeColor".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.ForeColor = System.Drawing.Color.Cornsilk;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //Height
            if (MemberName.CompareTo("Height".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.Height = 30;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //Style
            if (MemberName.CompareTo("Style".ToLower())== 0)
            {
                GHTSubTestAddResult(GHTActiveSubTest, MemberName + " " + obj.Style.ToString());
            }

            //            if (MemberName.CompareTo("TagKey".ToLower())== 0)
            //            {
            //                obj.TagKey = "TagKey";
            //            }
            //            if (MemberName.CompareTo("TagName".ToLower())== 0)
            //            {
            //                obj.TagName = "TagName";
            //            }

            //TabIndex
            if (MemberName.CompareTo("TabIndex".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.TabIndex = 2;
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //ToolTip
            if (MemberName.CompareTo("ToolTip".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.ToolTip = "ToolTip";
                GHTActiveSubTest.Controls.Add(objNew);
            }

            //Width
            if (MemberName.CompareTo("Width".ToLower())== 0)
            {
                objNew = (WebControl)GHTElementClone(obj.GetType());
                objNew.Width = 60;
                GHTActiveSubTest.Controls.Add(objNew);
            }

        }

		protected void GHTHeader(string text)
			{
				Label  header = new Label();
				header.Text = "<br>" + text + "<br>";
				header.Font.Bold = true;
				header.Font.Underline = true;
				header.Font.Size = new FontUnit(FontSize.Larger);
				GHTActiveForm.Controls.Add(header);
			}

		/// <summary>
		/// Removes tarailing @... and preceding '_' from strings if they are found
		/// </summary>
		/// <param name="orig">The original ToString result.</param>
		/// <returns>Normalized string.</returns>
		public string GHTNormalizeToString(string a_toNormalize)
		{
			//Remove the @ at the end of the tostring.
			int atIndex = a_toNormalize.LastIndexOf('@');
			if (atIndex > -1)
			{
				a_toNormalize = a_toNormalize.Remove(atIndex, a_toNormalize.Length - atIndex);
			}
			//remove the preceding '_'
			if (a_toNormalize.StartsWith("_") )
			{
				a_toNormalize = a_toNormalize.Substring(1);
			}
			return a_toNormalize;
		}
		/// <summary>
		/// Returns the normalized to string of this page.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return GHTNormalizeToString(base.ToString());
		}
    }
}