コード例 #1
0
        public bool Equals(AgeDescriptor other)
        {
            if (other == null)
            {
                return(false);
            }

            return((Years == other.Years) &&
                   (Months == other.Months) &&
                   (Days == other.Days));
        }
コード例 #2
0
        public void CalculateDifference_should_output_two_months_if_date_is_the_same_two_months_later_in_same_year()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 3, 5);
            var currentDate = new DateTime(2016, 5, 5);
            var expectedAge = new AgeDescriptor(0, 2, 0);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #3
0
        public void CalculateDifference_should_output_one_month_if_date_is_the_same_on_the_next_very_month()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 1, 10);
            var currentDate = new DateTime(2016, 2, 10);
            var expectedAge = new AgeDescriptor(0, 1, 0);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #4
0
        public void CalculateDifference_should_count_days_if_a_month_hasnt_passed_after_a_30day_month()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 11, 20);
            var currentDate = new DateTime(2016, 12, 1);
            var expectedAge = new AgeDescriptor(0, 0, 11);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #5
0
        public void CalculateDifference_should_work_for_cases_where_dates_are_on_the_very_same_month()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 1, 10);
            var currentDate = new DateTime(2016, 1, 20);
            var expectedAge = new AgeDescriptor(0, 0, 10);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #6
0
        public void CalculateDifference_from_the_first_day_of_a_month_to_the_first_day_of_the_next_theres_on_month_on_leap_years()
        {
            // Arrange
            var pastDate    = new DateTime(2017, 2, 1);
            var currentDate = new DateTime(2017, 3, 1);
            var expectedAge = new AgeDescriptor(0, 1, 0);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #7
0
        public void CalculateDifference_people_born_on_february_29th_have_birthdays_on_feb_29th_on_leap_years()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 2, 29);
            var currentDate = new DateTime(2020, 2, 29);
            var expectedAge = new AgeDescriptor(4, 0, 0);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #8
0
        public void CalculateDifference_should_output_incomplete_years_on_feb_28th_for_people_born_on_feb_29th()
        {
            // Arrange
            var pastDate    = new DateTime(2016, 2, 29);
            var currentDate = new DateTime(2019, 2, 28);
            var expectedAge = new AgeDescriptor(2, 11, 28);

            // Act
            var actualAge = _calculationsService.CalculateDifference(pastDate, currentDate);

            // Assert
            actualAge.Should().Be(expectedAge);
        }
コード例 #9
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            AgeDescriptor other = obj as AgeDescriptor;

            if (other == null)
            {
                return(false);
            }

            return((Years == other.Years) &&
                   (Months == other.Months) &&
                   (Days == other.Days));
        }