예제 #1
0
 public void Has_Expected_AsTwoDigitString_Property(
     string twoDigitYear)
 {
     TwoThousandsCommonEraYear
     .ParseTwoDigitYear(twoDigitYear)
     .AsTwoDigitString
     .Should()
     .Be(twoDigitYear);
 }
예제 #2
0
 public void Parses_Correctly_From_Two_Digit_Year(
     string twoDigitYear,
     int expectedParsedYear)
 {
     TwoThousandsCommonEraYear
     .ParseTwoDigitYear(twoDigitYear)
     .AsInt
     .Should()
     .Be(expectedParsedYear);
 }
예제 #3
0
 public void Throws_ArgumentException_When_Asked_To_Parse_Invalid_Two_Digit_Year(
     string invalidTwoDigitYear)
 {
     Assert
     .That(
         () => TwoThousandsCommonEraYear.ParseTwoDigitYear(invalidTwoDigitYear),
         Throws
         .Exception
         .TypeOf <ArgumentException>());
 }
예제 #4
0
        public void Is_Equatable_With_Another_TwoThousandsCommonEraYear(
            string left,
            string right,
            bool expectedEqual)
        {
            var leftYear =
                TwoThousandsCommonEraYear
                .ParseTwoDigitYear(left);

            var rightYear =
                TwoThousandsCommonEraYear
                .ParseTwoDigitYear(right);

            leftYear
            .Equals(rightYear)
            .Should()
            .Be(expectedEqual);
        }
        public static Period ParsePeriodString(string periodString)
        {
            if (string.IsNullOrWhiteSpace(periodString))
            {
                throw new ArgumentException($"{periodString} cannot be parsed; should be 4 chars e.g. 1516 to represent period 2015/2016", nameof(periodString));
            }

            if (periodString.Length != 4)
            {
                throw new ArgumentException($"{periodString} cannot be parsed; should be 4 chars e.g. 1516 to represent period 2015/2016", nameof(periodString));
            }

            return(new Period(
                       startYear:
                       TwoThousandsCommonEraYear
                       .ParseTwoDigitYear(periodString.Substring(0, 2)),
                       endYear:
                       TwoThousandsCommonEraYear
                       .ParseTwoDigitYear(periodString.Substring(2, 2))));
        }