Exemplo n.º 1
0
        public void Will_throw_exception_if_end_date_not_Friday_when_calculating_weeks_between_dates()
        {
            // Arrange
            DateTime start_date        = new DateTime(2020, 7, 11);
            DateTime end_date          = new DateTime(2020, 7, 30);
            var      mock_input_output = new Mock <IInputOutput>();
            var      week_getter       = new WeekGetter(mock_input_output.Object, new Mock <IClock>().Object);
            bool     exception_thrown  = false;
            var      exception_message = "";

            // Act
            try
            {
                week_getter.Num_weeks_between_dates(start_date, end_date);
            }
            catch (Exception exception)
            {
                exception_thrown  = true;
                exception_message = exception.Message;
            }

            // Assert
            Assert.AreEqual(true, exception_thrown);
            Assert.IsTrue(exception_message.Contains("Friday"), "Exception message should refer to Friday");
        }
        private void Update_weekly_item(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            BudgetingMonths budgeting_months,
            string item,
            string budget_code,
            string expected_out_code)
        {
            var week_getter = new WeekGetter(input_output, new Clock());
            var weeks       = week_getter.Decide_num_weeks(item, budgeting_months);

            spreadsheet.Update_expected_out(weeks.NumWeeks, budget_code, expected_out_code);
        }
Exemplo n.º 3
0
        public void Will_find_previous_Friday(
            int this_day,
            int this_month,
            int expected_day,
            int expected_month)
        {
            // Arrange
            DateTime today             = new DateTime(2020, this_month, this_day);
            var      mock_input_output = new Mock <IInputOutput>();
            var      week_getter       = new WeekGetter(mock_input_output.Object, new Mock <IClock>().Object);

            // Act
            DateTime result = week_getter.Find_previous_Friday(today);

            // Assert
            Assert.AreEqual(expected_day, result.Day);
            Assert.AreEqual(expected_month, result.Month);
        }
Exemplo n.º 4
0
        public void Will_ask_user_which_Friday_to_end_on_when_deciding_num_weeks()
        {
            // Arrange
            var mock_input_output = new Mock <IInputOutput>();
            var mock_clock        = new Mock <IClock>();

            mock_clock.Setup(x => x.Today_date_time()).Returns(new DateTime(2020, 6, 1));
            var week_getter = new WeekGetter(mock_input_output.Object, mock_clock.Object);
            var budgeting_months_not_ending_friday = new BudgetingMonths {
                Start_year = 2020, Next_unplanned_month = 6, Last_month_for_budget_planning = 6
            };

            // Act
            week_getter.Decide_num_weeks("Testing, testing...", budgeting_months_not_ending_friday);

            // Assert
            mock_input_output.Verify(x => x.Get_input(
                                         It.Is <string>(y => y.Contains("Friday")), ""));
        }
Exemplo n.º 5
0
        public void Will_calculate_num_weeks_between_dates(
            int start_day,
            int start_month,
            int start_year,
            int end_day,
            int end_month,
            int end_year,
            int expected_result)
        {
            // Arrange
            DateTime start_date        = new DateTime(start_year, start_month, start_day);
            DateTime end_date          = new DateTime(end_year, end_month, end_day);
            var      mock_input_output = new Mock <IInputOutput>();
            var      week_getter       = new WeekGetter(mock_input_output.Object, new Mock <IClock>().Object);

            // Act
            int result = week_getter.Num_weeks_between_dates(start_date, end_date);

            // Assert
            Assert.AreEqual(expected_result, result, $"Expected {expected_result} but got {result}");
        }
Exemplo n.º 6
0
        public void Will_calculate_correct_start_date_according_to_user_input(
            int start_day,
            int start_month,
            bool choose_first_saturday,
            int expected_day,
            int expected_month)
        {
            // Arrange
            const int year              = 2020;
            DateTime  start_date        = new DateTime(year, start_month, start_day);
            var       mock_input_output = new Mock <IInputOutput>();
            var       mock_clock        = new Mock <IClock>();
            var       week_getter       = new WeekGetter(mock_input_output.Object, mock_clock.Object);
            var       budgeting_months_not_ending_friday = new BudgetingMonths
            {
                Start_year                     = year,
                Next_unplanned_month           = start_month,
                Last_month_for_budget_planning = start_month
            };

            mock_input_output.Setup(x => x.Get_input(
                                        It.Is <string>(y => y.Contains("Sat")),
                                        It.IsAny <string>()))
            .Returns(choose_first_saturday ? "1" : "2");
            mock_input_output.Setup(x => x.Get_input(
                                        It.Is <string>(y => y.Contains("Fri")),
                                        It.IsAny <string>()))
            .Returns("1");
            mock_clock.Setup(x => x.Today_date_time()).Returns(start_date);

            // Act
            var result = week_getter.Decide_num_weeks("Testing, testing...", budgeting_months_not_ending_friday);

            // Assert
            Assert.AreEqual(expected_day, result.FirstSaturday.Day);
            Assert.AreEqual(expected_month, result.FirstSaturday.Month);
            Assert.AreEqual(year, result.FirstSaturday.Year);
        }