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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
|
//
// Tests for System.Web.UI.WebControls.Calendar.cs
//
// Author:
// Jordi Mas i Hernandez (jordi@ximian.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Drawing;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUnit.Framework;
class PokerCalendar : System.Web.UI.WebControls.Calendar
{
public PokerCalendar ()
{
TrackViewState ();
}
public object SaveState ()
{
return SaveViewState ();
}
public void LoadState (object o)
{
LoadViewState (o);
}
public string Render ()
{
StringWriter sw = new StringWriter ();
sw.NewLine = "\n";
HtmlTextWriter writer = new HtmlTextWriter (sw);
base.Render (writer);
return writer.InnerWriter.ToString ();
}
bool cs_called;
public bool CS_Called {
get { return cs_called; }
set { cs_called = value; }
}
protected override Style CreateControlStyle ()
{
cs_called = true;
return base.CreateControlStyle ();
}
}
namespace MonoTests.System.Web.UI.WebControls
{
[TestFixture]
public class CalendarTest
{
[Test]
public void Calendar_DefaultValues ()
{
PokerCalendar c = new PokerCalendar ();
Assert.AreEqual (2, c.CellPadding, "CellPadding");
Assert.AreEqual (0, c.CellSpacing, "CellSpacing");
Assert.AreEqual (DayNameFormat.Short, c.DayNameFormat, "DayNameFormat");
Assert.AreEqual (FirstDayOfWeek.Default, c.FirstDayOfWeek, "FirstDayOfWeek");
Assert.AreEqual (">",c.NextMonthText, "NextMonthText");
Assert.AreEqual (NextPrevFormat.CustomText, c.NextPrevFormat, "NextPrevFormat");
Assert.AreEqual ("<", c.PrevMonthText, "PrevMonthText");
Assert.AreEqual (CalendarSelectionMode.Day, c.SelectionMode, "SelectionMode");
Assert.AreEqual (">>", c.SelectMonthText, "SelectMonthText");
Assert.AreEqual (">", c.SelectWeekText, "SelectWeekText");
Assert.AreEqual (true, c.ShowDayHeader, "ShowDayHeader");
Assert.AreEqual (false, c.ShowGridLines, "ShowGridLines");
Assert.AreEqual (true, c.ShowNextPrevMonth , "ShowNextPrevMonth");
Assert.AreEqual (true, c.ShowTitle, "ShowTitle");
Assert.AreEqual (TitleFormat.MonthYear, c.TitleFormat, "TitleFormat");
Assert.AreEqual (DateTime.Today, c.TodaysDate , "TodaysDate");
Assert.AreEqual (DateTime.MinValue, c.VisibleDate, "VisibleDate");
}
//
// Properties
//
[Test]
public void NextMonthTextProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.NextMonthText = "NextMonthText";
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "NextMonthText");
}
[Test]
public void NextPrevFormatProperty ()
{
DateTimeFormatInfo dateInfo = DateTimeFormatInfo.CurrentInfo;
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
DateTime prevMonth = dateInfo.Calendar.AddMonths (DateTime.Today, -1);
DateTime nextMonth = dateInfo.Calendar.AddMonths (DateTime.Today, 1);
c.NextMonthText = "NextMonthText"; // CustomText
c.PrevMonthText = "PrevMonthText";
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "NextPrevFormat1");
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "NextPrevFormat2");
sw = new StringWriter ();
tw = new HtmlTextWriter (sw);
c.NextPrevFormat = NextPrevFormat.FullMonth; // FullMonth
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString ().IndexOf (dateInfo.GetMonthName (dateInfo.Calendar.GetMonth (prevMonth))) != -1, "NextPrevFormat3:" + sw.ToString () + "|||" + dateInfo.GetMonthName (DateTimeFormatInfo.CurrentInfo.Calendar.GetMonth (prevMonth)));
Assert.AreEqual (true, sw.ToString ().IndexOf (dateInfo.GetMonthName (dateInfo.Calendar.GetMonth (nextMonth))) != -1, "NextPrevFormat4");
sw = new StringWriter ();
tw = new HtmlTextWriter (sw);
c.NextPrevFormat = NextPrevFormat.ShortMonth; // ShortMonth
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString ().IndexOf (dateInfo.GetAbbreviatedMonthName (dateInfo.Calendar.GetMonth (prevMonth))) != -1, "NextPrevFormat5");
Assert.AreEqual (true, sw.ToString ().IndexOf (dateInfo.GetAbbreviatedMonthName (dateInfo.Calendar.GetMonth (nextMonth))) != -1, "NextPrevFormat6");
}
[Test]
public void DayHeaderStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.DayHeaderStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "DayHeaderStyleProperty");
}
[Test]
public void NextPrevStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.NextPrevStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "NextPrevStyleProperty");
}
[Test]
public void SelectorStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.SelectorStyle.BackColor = Color.Green;
c.SelectionMode = CalendarSelectionMode.DayWeek;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "SelectorStyleProperty");
}
//[Test]
public void TitleStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.SelectorStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "TitleStyleProperty");
}
[Test]
public void OtherMonthDayStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.OtherMonthDayStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle");
}
[Test]
public void SelectedDayStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.SelectedDayStyle.BackColor = Color.Green;
c.TodaysDate = new DateTime (2000, 1,1);
((IPostBackEventHandler)c).RaisePostBackEvent ("0001");
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "SelectedDayStyle");
}
[Test]
public void TodayDayStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.TodayDayStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "TodayDayStyle");
}
[Test]
public void WeekendDayStyleProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.WeekendDayStyle.BackColor = Color.Green;
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "WeekendDayStyle");
}
[Test]
[Category ("NotWorking")]
public void SelectDateProperty ()
{
PokerCalendar c = new PokerCalendar ();
DateTime now = DateTime.Now;
DateTime today = now.Date;
c.SelectedDate = today;
Assert.AreEqual (today, c.SelectedDate, "SelectDateProperty #1");
c.SelectedDate = now;
Assert.AreEqual (now, c.SelectedDate, "SelectDateProperty #2");
}
[Test]
public void PrevMonthTextProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.PrevMonthText = "PrevMonthText";
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "PrevMonthText");
}
[Test]
public void ShowNextPrevMonthProperty ()
{
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.NextMonthText = "NextMonthText";
c.PrevMonthText = "PrevMonthText";
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "ShowNextPrevMonth1");
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "ShowNextPrevMonth2");
c.ShowNextPrevMonth = false;
sw = new StringWriter ();
tw = new HtmlTextWriter (sw);
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) == -1, "ShowNextPrevMonth3");
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) == -1, "ShowNextPrevMonth4");
}
[Test]
public void ShowTitleProperty ()
{
String monthName;
DateTimeFormatInfo dateInfo = DateTimeFormatInfo.CurrentInfo;
PokerCalendar c = new PokerCalendar ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.NextMonthText = "NextMonthText";
c.PrevMonthText = "PrevMonthText";
c.RenderControl (tw);
monthName = dateInfo.GetMonthName (dateInfo.Calendar.GetMonth (DateTime.Today));
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) != -1, "ShowTitle1");
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) != -1, "ShowTitle2");
Assert.AreEqual (true, sw.ToString().IndexOf (monthName) != -1, "ShowTitle3");
c.ShowTitle = false;
sw = new StringWriter ();
tw = new HtmlTextWriter (sw);
c.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().IndexOf (c.PrevMonthText) == -1, "ShowTitle4");
Assert.AreEqual (true, sw.ToString().IndexOf (c.NextMonthText) == -1, "ShowTitle5");
Assert.AreEqual (true, sw.ToString().IndexOf (monthName) == -1, "ShowTitle6");
}
//
// Properties exceptions
//
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CellPaddingException ()
{
PokerCalendar p = new PokerCalendar ();
p.CellPadding = -2;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void CellSpacingException ()
{
PokerCalendar c = new PokerCalendar ();
c.CellSpacing = -2;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void DayNameFormatException ()
{
PokerCalendar c = new PokerCalendar ();
c.DayNameFormat = (DayNameFormat) 10;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void FirstDayOfWeekException ()
{
PokerCalendar c = new PokerCalendar ();
c.FirstDayOfWeek = (FirstDayOfWeek) 15;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void NextPrevFormatException ()
{
PokerCalendar c = new PokerCalendar ();
c.NextPrevFormat = (NextPrevFormat) 15;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SelectionModeException ()
{
PokerCalendar c = new PokerCalendar ();
c.SelectionMode = (CalendarSelectionMode) 15;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TitleFormatException ()
{
PokerCalendar c = new PokerCalendar ();
c.TitleFormat = (TitleFormat) 15;
}
//
// Events
//
private bool eventFired;
private void SelectionChangedHandler (object sender, EventArgs e)
{
eventFired = true;
}
private void VisibleMonthChangedHandler (object sender, MonthChangedEventArgs e)
{
eventFired = true;
}
int days;
private void DayRenderEventHandler (object sender, DayRenderEventArgs e)
{
days++;
e.Cell.BackColor = Color.Yellow;
}
[Test]
public void SelectionChanged ()
{
PokerCalendar c = new PokerCalendar ();
c.SelectionChanged += new EventHandler (SelectionChangedHandler);
eventFired = false;
((IPostBackEventHandler)c).RaisePostBackEvent ("0001");
Assert.AreEqual (true, eventFired, "SelectionChanged event");
}
[Test]
public void VisibleMonthChanged ()
{
PokerCalendar c = new PokerCalendar ();
c.VisibleMonthChanged += new MonthChangedEventHandler (VisibleMonthChangedHandler);
eventFired = false;
((IPostBackEventHandler)c).RaisePostBackEvent ("V0001");
Assert.AreEqual (true, eventFired, "VisibleMonthChanged event");
}
[Test]
public void DayRender ()
{
PokerCalendar c = new PokerCalendar ();
c.DayRender += new DayRenderEventHandler (DayRenderEventHandler);
days = 0;
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
c.RenderControl (tw);
Assert.AreEqual (6 * 7, days, "DayRender event");
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("yellow") != -1, "DayRender event change");
}
// ViewState
[Test]
public void Calendar_ViewState ()
{
PokerCalendar p = new PokerCalendar ();
p.CellPadding = 10;
p.CellSpacing = 20;
p.DayNameFormat = DayNameFormat.Short;
p.FirstDayOfWeek = FirstDayOfWeek.Friday;
p.NextMonthText = "NextMonth";
p.NextPrevFormat = NextPrevFormat.ShortMonth;
p.PrevMonthText = "PrevMonth";
p.SelectionMode = CalendarSelectionMode.DayWeek;
p.SelectMonthText = "SelectMonth";
p.SelectWeekText = "SelectWeek";
p.ShowDayHeader = false;
p.ShowGridLines = true;
p.ShowNextPrevMonth = false;
p.ShowTitle = false;
p.TitleFormat = TitleFormat.Month;
p.TodaysDate = new DateTime (1999,1,1);
p.VisibleDate = new DateTime (1998,1,1);
#if NET_2_0
p.Caption = "This is a Caption";
p.CaptionAlign = TableCaptionAlign.Right;
#endif
p.DayHeaderStyle.BackColor = Color.Blue;
p.DayStyle.BackColor = Color.Yellow;
p.NextPrevStyle.BackColor = Color.Red;
p.OtherMonthDayStyle.BackColor = Color.Green;
p.SelectedDayStyle.BackColor = Color.Silver;
p.SelectorStyle.BackColor = Color.Pink;
p.TodayDayStyle.BackColor = Color.White;
p.WeekendDayStyle.BackColor = Color.Brown;
object state = p.SaveState ();
PokerCalendar copy = new PokerCalendar ();
copy.LoadState (state);
Assert.AreEqual (10, copy.CellPadding, "CellPadding");
Assert.AreEqual (20, copy.CellSpacing, "CellSpacing");
Assert.AreEqual (DayNameFormat.Short, copy.DayNameFormat, "DayNameFormat");
Assert.AreEqual (FirstDayOfWeek.Friday, copy.FirstDayOfWeek, "FirstDayOfWeek");
Assert.AreEqual ("NextMonth", copy.NextMonthText, "NextMonthText");
Assert.AreEqual (NextPrevFormat.ShortMonth, copy.NextPrevFormat, "NextPrevFormat");
Assert.AreEqual ("PrevMonth", copy.PrevMonthText, "PrevMonthText");
Assert.AreEqual (CalendarSelectionMode.DayWeek, copy.SelectionMode, "SelectionMode");
Assert.AreEqual ("SelectMonth", copy.SelectMonthText, "SelectMonthText");
Assert.AreEqual ("SelectWeek", copy.SelectWeekText, "SelectWeekText");
Assert.AreEqual (false, copy.ShowDayHeader, "ShowDayHeader");
Assert.AreEqual (true, copy.ShowGridLines, "ShowGridLines");
Assert.AreEqual (false, copy.ShowNextPrevMonth, "ShowNextPrevMonth");
Assert.AreEqual (false, copy.ShowTitle, "ShowTitle");
Assert.AreEqual (TitleFormat.Month, copy.TitleFormat, "TitleFormat");
Assert.AreEqual (new DateTime (1999,1,1), copy.TodaysDate, "TodaysDate");
Assert.AreEqual (new DateTime (1998,1,1), copy.VisibleDate, "VisibleDate");
#if NET_2_0
Assert.AreEqual ("This is a Caption", copy.Caption, "Caption");
Assert.AreEqual (TableCaptionAlign.Right, copy.CaptionAlign, "CaptionAlign");
#endif
copy.ShowDayHeader = true;
copy.ShowNextPrevMonth = true;
copy.ShowTitle = true;
copy.TodaysDate = copy.VisibleDate;
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("blue") != -1, "DayHeaderStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("yellow") != -1, "BackColor");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("red") != -1, "NextPrevStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("silver") != -1, "SelectedDayStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("green") != -1, "OtherMonthDayStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("pink") != -1, "SelectorStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("white") != -1, "TodayDayStyle");
}
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
copy.RenderControl (tw);
Assert.AreEqual (true, sw.ToString().ToLower().IndexOf ("brown") != -1, "WeekendDayStyle");
}
}
string tofind = "";
public void Event_TestDayRenderCellAdd_DayRender(object sender, DayRenderEventArgs e) {
if (e.Day.Date.Day == 1)
e.Cell.Controls.Add (new LiteralControl (tofind));
}
[Test]
public void TestDayRenderCellAdd ()
{
PokerCalendar p = new PokerCalendar ();
tofind = Guid.NewGuid ().ToString ();
p.DayRender += new DayRenderEventHandler(Event_TestDayRenderCellAdd_DayRender);
Assert.IsTrue (p.Render ().IndexOf (tofind) != -1, "control added");
}
//
// Here we test rendering May 2005
// April 2005 May 2005 June 2005
// Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
// 1 2 1 2 3 4 5 6 7 1 2 3 4
// 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
// 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
// 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
// 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
//
// Microsoft renders months like this (where Blah 1st falls on Sunday) by rendering
// the last week of the other month.
//
bool first = true;
public void Event_TestRenderMonthStartsOnSunday_DayRender(object sender, DayRenderEventArgs e) {
if (first) {
Assert.IsTrue (e.Day.IsOtherMonth);
Assert.AreEqual (new DateTime (2005, 4, 24), e.Day.Date);
first = false;
}
}
[Test]
public void TestRenderMonthStartsOnSunday ()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
PokerCalendar p = new PokerCalendar ();
p.TodaysDate = new DateTime (2005, 5, 14);
first = true;
p.DayRender += new DayRenderEventHandler(Event_TestRenderMonthStartsOnSunday_DayRender);
p.Render ();
}
[Test]
public void TestSelectedColorDefault ()
{
PokerCalendar p = new PokerCalendar ();
p.TodaysDate = new DateTime (2005, 8, 4);
p.SelectedDate = p.TodaysDate;
string s = p.Render();
Assert.IsTrue (s.IndexOf ("color:White") != 1 && s.IndexOf ("background-color:Silver") != -1, "A1");
}
[Test]
public void HaveID ()
{
PokerCalendar p = new PokerCalendar ();
p.ID = "hola";
p.TodaysDate = new DateTime (2005, 8, 4);
p.SelectedDate = p.TodaysDate;
string s = p.Render();
Assert.IsTrue (s.IndexOf ("id=\"hola\"") != -1, "#01");
}
/*
* Not meant to be run. Just to get a stack trace.
[Test]
public void NoCreateStyleCollection ()
{
PokerCalendar p = new PokerCalendar ();
p.ID = "hola";
p.TodaysDate = new DateTime (2005, 8, 4);
p.SelectedDate = p.TodaysDate;
string s = p.Render();
Assert.IsTrue (p.CS_Called == false, "#01");
}
*/
[Test]
[Category ("NotWorking")]
public void HaveBaseAttributes ()
{
PokerCalendar p = new PokerCalendar ();
p.ID = "hola";
p.ToolTip = "adios";
p.TodaysDate = new DateTime (2005, 8, 4);
p.SelectedDate = p.TodaysDate;
string s = p.Render();
Assert.IsTrue (s.IndexOf ("adios") != -1, "#01");
Assert.IsTrue (p.CS_Called == true, "#02");
}
}
}
|