예제 #1
0
 public void ConstructorShouldSetMonths()
 {
     var weeks = new[] { new FiscalWeek( new DateTime( 2013, 6, 23 ) ) };
     var months = new Dictionary<int, FiscalMonth>() { { 1, new FiscalMonth( weeks ) } };
     var target = new FiscalYear( months );
     Assert.Equal( 1, target.Months.Count );
 }
예제 #2
0
 public void ToStringShouldReturnExpectedResult()
 {
     var weeks = new[] { new FiscalWeek( new DateTime( 2013, 6, 23 ) ) };
     var months = new Dictionary<int, FiscalMonth>() { { 1, new FiscalMonth( weeks ) } };
     var target = new FiscalYear( months );
     var expected = string.Format( CultureInfo.CurrentCulture, "FirstDay = {0:d}, LastDay = {1:d}", target.FirstDay, target.LastDay );
     var actual = target.ToString();
     Assert.Equal( expected, actual );
 }
예제 #3
0
        public void FirstDayLastDayAndDaysInYearPropertiesShouldBeBasedOnSuppliedMonths()
        {
            var firstDay = new DateTime( 2013, 6, 23 );
            var lastDay = new DateTime( 2013, 6, 29 );
            var weeks = new[] { new FiscalWeek( firstDay ) };
            var months = new Dictionary<int, FiscalMonth>() { { 1, new FiscalMonth( weeks ) } };
            var target = new FiscalYear( months );

            Assert.Equal( firstDay, target.FirstDay );
            Assert.Equal( lastDay, target.LastDay );
            Assert.Equal( 7, target.DaysInYear );
        }
예제 #4
0
 public void FirstAndLastDayPropertiesShouldDefaultToToday()
 {
     var target = new FiscalYear();
     Assert.Equal( DateTime.Today, target.FirstDay );
     Assert.Equal( DateTime.Today, target.LastDay );
 }
        public static FourFourFiveCalendar CreateCalendar()
        {
            var schedule = new List<FiscalYear>();
            var xml = CreateTestData();
            var dates = from year in xml.Descendants( "week" )
                        select new
                        {
                            Year = int.Parse( year.Attribute( "year" ).Value ),
                            Month = int.Parse( year.Attribute( "month" ).Value ),
                            FirstDay = DateTime.Parse( year.Attribute( "start" ).Value ).Date,
                            LastDay = DateTime.Parse( year.Attribute( "end" ).Value ).Date
                        };

            var years = from date in dates
                        orderby date.Year, date.Month, date.FirstDay
                        group date by date.Year into yrs
                        from yr in
                            ( from date in yrs
                              group date by date.Month )
                        group yr by yrs.Key;

            foreach ( var year in years )
            {
                var fiscalYear = new FiscalYear();
                schedule.Add( fiscalYear );

                foreach ( var month in year )
                {
                    var fiscalMonth = new FiscalMonth();
                    fiscalYear.Months.Add( month.Key, fiscalMonth );

                    foreach ( var week in month )
                        fiscalMonth.Weeks.Add( new FiscalWeek( week.FirstDay, week.LastDay ) );
                }
            }

            var target = new FourFourFiveCalendar( schedule );
            return target;
        }