Exemple #1
0
        private static IHtmlNode BuildWeekHeader(ICalendarHtmlBuilder renderer)
        {
            IHtmlNode headerTag = renderer.HeaderTag();
            IHtmlNode row       = renderer.RowTag();

            DateTimeFormatInfo dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;

            string[] dayNames            = dateTimeFormat.DayNames;
            string[] abbreviatedDayNames = dateTimeFormat.AbbreviatedDayNames;
            string[] shortestDayNames    = dateTimeFormat.ShortestDayNames;
            int      firstDayIndex       = (int)dateTimeFormat.FirstDayOfWeek;

            var modifiedDayNames = dayNames.Skip(firstDayIndex).Take(dayNames.Length)
                                   .Concat(dayNames.Take(firstDayIndex)).ToList();
            var modifiedAbbreviatedDayNames = abbreviatedDayNames.Skip(firstDayIndex).Take(abbreviatedDayNames.Length)
                                              .Concat(abbreviatedDayNames.Take(firstDayIndex)).ToList();
            var modifiedShortestDayNames = shortestDayNames.Skip(firstDayIndex).Take(shortestDayNames.Length)
                                           .Concat(shortestDayNames.Take(firstDayIndex)).ToList();

            for (int i = 0; i < modifiedDayNames.Count; i++)
            {
                row.Children.Add(renderer.HeaderCellTag(modifiedDayNames[i], modifiedAbbreviatedDayNames[i], modifiedShortestDayNames[i]));
            }

            headerTag.Children.Add(row);

            return(headerTag);
        }
        public static Calendar CreateCalendar(ICalendarHtmlBuilder renderer)
        {
            Mock <HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny <TextWriter>())).Returns(new HtmlTextWriter(TextWriter.Null));

            Mock <ICalendarHtmlBuilderFactory> calendarHtmlBuilderFactory = new Mock <ICalendarHtmlBuilderFactory>();

            Mock <IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock <IClientSideObjectWriterFactory>();

            clientSideObjectWriter = new Mock <IClientSideObjectWriter>();

            Mock <IUrlGenerator> urlGenerator = new Mock <IUrlGenerator>();

            ViewContext viewContext = TestHelper.CreateViewContext();

            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TextWriter>())).Returns(clientSideObjectWriter.Object);

            Calendar calendar = new Calendar(viewContext, clientSideObjectWriterFactory.Object, urlGenerator.Object, calendarHtmlBuilderFactory.Object);

            renderer = renderer ?? new CalendarHtmlBuilder(calendar);
            calendarHtmlBuilderFactory.Setup(f => f.Create(It.IsAny <Calendar>())).Returns(renderer);

            return(calendar);
        }
        public void Should_be_able_to_create_renderer()
        {
            CalendarHtmlBuilderFactory factory = new CalendarHtmlBuilderFactory();

            ICalendarHtmlBuilder renderer = factory.Create(CalendarTestHelper.CreateCalendar(null));

            Assert.IsType <CalendarHtmlBuilder>(renderer);
        }
Exemple #4
0
        protected override void WriteHtml(System.Web.UI.HtmlTextWriter writer)
        {
            ICalendarHtmlBuilder renderer = rendererFactory.Create(this);

            urlFormat = SelectionSettings.GenerateUrl(ViewContext, UrlGenerator);
            if (urlFormat.HasValue())
            {
                urlFormat = HttpUtility.UrlDecode(urlFormat).ToLowerInvariant();
            }

            IHtmlNode rootTag = renderer.Build();

            IHtmlNode contentTag = renderer.ContentTag();

            contentTag.Children.Add(BuildWeekHeader(renderer));
            contentTag.Children.Add(BuildMonthView(renderer));

            rootTag.Children.Add(contentTag);

            rootTag.WriteTo(writer);

            base.WriteHtml(writer);
        }
Exemple #5
0
        private IHtmlNode BuildMonthView(ICalendarHtmlBuilder renderer)
        {
            NormalizeSelectDates();

            IHtmlNode monthTag = renderer.MonthTag();

            DateTime focusedDate = this.DetermineFocusedDate();
            DateTime prevMonth   = GetLastDayOfMonth(focusedDate).AddMonths(-1);
            DateTime startDate   = GetStartOfWeek(prevMonth, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);

            for (int weekRow = 0; weekRow < 6; weekRow++)
            {
                IHtmlNode rowTag = renderer.RowTag();

                for (int day = 0; day < 7; day++)
                {
                    renderer.CellTag(startDate, Value, urlFormat, startDate.Month != focusedDate.Month).AppendTo(rowTag);
                    startDate = startDate.AddDays(1);
                }
                monthTag.Children.Add(rowTag);
            }
            return(monthTag);
        }
        public static Calendar CreateCalendar(ICalendarHtmlBuilder renderer)
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(new HtmlTextWriter(TextWriter.Null));

            Mock<ICalendarHtmlBuilderFactory> calendarHtmlBuilderFactory = new Mock<ICalendarHtmlBuilderFactory>();

            Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>();
            clientSideObjectWriter = new Mock<IClientSideObjectWriter>();

            Mock<IUrlGenerator> urlGenerator = new Mock<IUrlGenerator>();

            ViewContext viewContext = TestHelper.CreateViewContext();

            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter.Object);

            Calendar calendar = new Calendar(viewContext, clientSideObjectWriterFactory.Object, urlGenerator.Object, calendarHtmlBuilderFactory.Object);

            renderer = renderer ?? new CalendarHtmlBuilder(calendar);
            calendarHtmlBuilderFactory.Setup(f => f.Create(It.IsAny<Calendar>())).Returns(renderer);

            return calendar;
        }
 public CalendarHtmlBuilderTests()
 {
     calendar = CalendarTestHelper.CreateCalendar(null);
     calendar.Name = "Calendar";
     renderer = new CalendarHtmlBuilder(calendar);
 }
Exemple #8
0
        private IHtmlNode BuildMonthView(ICalendarHtmlBuilder renderer)
        {
            NormalizeSelectDates();

            IHtmlNode monthTag = renderer.MonthTag();

            DateTime focusedDate = this.DetermineFocusedDate();
            DateTime prevMonth = GetLastDayOfMonth(focusedDate).AddMonths(-1);
            DateTime startDate = GetStartOfWeek(prevMonth, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);

            for (int weekRow = 0; weekRow < 6; weekRow++)
            {
                IHtmlNode rowTag = renderer.RowTag();

                for (int day = 0; day < 7; day++)
                {
                    renderer.CellTag(startDate, Value, urlFormat, startDate.Month != focusedDate.Month).AppendTo(rowTag);
                    startDate = startDate.AddDays(1);
                }
                monthTag.Children.Add(rowTag);
            }
            return monthTag;
        }
Exemple #9
0
        private static IHtmlNode BuildWeekHeader(ICalendarHtmlBuilder renderer)
        {
            IHtmlNode headerTag = renderer.HeaderTag();
            IHtmlNode row = renderer.RowTag();

            DateTimeFormatInfo dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat;
            string[] dayNames = dateTimeFormat.DayNames;
            string[] abbreviatedDayNames = dateTimeFormat.AbbreviatedDayNames;
            string[] shortestDayNames = dateTimeFormat.ShortestDayNames;
            int firstDayIndex = (int)dateTimeFormat.FirstDayOfWeek;

            var modifiedDayNames = dayNames.Skip(firstDayIndex).Take(dayNames.Length)
                                           .Concat(dayNames.Take(firstDayIndex)).ToList();
            var modifiedAbbreviatedDayNames = abbreviatedDayNames.Skip(firstDayIndex).Take(abbreviatedDayNames.Length)
                                                                 .Concat(abbreviatedDayNames.Take(firstDayIndex)).ToList();
            var modifiedShortestDayNames = shortestDayNames.Skip(firstDayIndex).Take(shortestDayNames.Length)
                                                           .Concat(shortestDayNames.Take(firstDayIndex)).ToList();

            for (int i = 0; i < modifiedDayNames.Count; i++)
            {
                row.Children.Add(renderer.HeaderCellTag(modifiedDayNames[i], modifiedAbbreviatedDayNames[i], modifiedShortestDayNames[i]));
            }

            headerTag.Children.Add(row);

            return headerTag;
        }
Exemple #10
0
        private IHtmlNode BuildMonthView(ICalendarHtmlBuilder renderer)
        {
            IHtmlNode monthTag = renderer.MonthTag();

            DateTime? focusedDate = this.DetermineFocusedDate();
            DateTime prevMonth = new DateTime(focusedDate.Value.Year, focusedDate.Value.Month, 1).AddDays(-1);

            int firstDayOfMonthView = DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month) - ((int)(prevMonth).DayOfWeek);

            DateTime startDate = new DateTime(prevMonth.Year, prevMonth.Month, firstDayOfMonthView);
            for (int weekRow = 0; weekRow < 6; weekRow++)
            {
                IHtmlNode rowTag = renderer.RowTag();

                for (int day = 0; day < 7; day++)
                {
                    renderer.CellTag(startDate, urlFormat, startDate.Month != focusedDate.Value.Month).AppendTo(rowTag);
                    startDate = startDate.AddDays(1);
                }
                monthTag.Children.Add(rowTag);
            }
            return monthTag;
        }
Exemple #11
0
        private static IHtmlNode BuildWeekHeader(ICalendarHtmlBuilder renderer)
        {
            IHtmlNode headerTag = renderer.HeaderTag();
            IHtmlNode row = renderer.RowTag();

            foreach (string day in Culture.Current.DateTimeFormat.DayNames)
            {
                row.Children.Add(renderer.HeaderCellTag(day));
            }

            headerTag.Children.Add(row);

            return headerTag;
        }
 public CalendarHtmlBuilderTests()
 {
     calendar      = CalendarTestHelper.CreateCalendar(null);
     calendar.Name = "Calendar";
     renderer      = new CalendarHtmlBuilder(calendar);
 }