public void ParseThrowsWhenValueDoesNotEndWithDigits()
        {
            var generator = new Generator <char>(_fixture);
            var roadType  = generator
                            .First(
                candidate =>
                NumberedRoadNumber.RoadTypes.Any(
                    letter => letter.Equals(candidate)));
            var not_a_digit_position      = _fixture.Create <int>() % 6;
            var all_digits_except_for_one = new char[6];

            for (var index = 0; index < 6; index++)
            {
                if (index == not_a_digit_position)
                {
                    all_digits_except_for_one[index] = generator.First(candidate => !char.IsDigit(candidate));
                }
                else
                {
                    all_digits_except_for_one[index] = generator.First(char.IsDigit);
                }
            }
            var value =
                new string(new [] { roadType }.Concat(all_digits_except_for_one).Concat(new [] { '1' }).ToArray());

            Assert.Throws <FormatException>(() => NumberedRoadNumber.Parse(value));
        }
        private static NumberedRoadNumber[] ReadAllFromResource()
        {
            using (var stream = Assembly
                                .GetAssembly(typeof(NumberedRoadNumbers))
                                .GetManifestResourceStream(typeof(NumberedRoadNumbers), "ident8.txt"))
            {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        var numbers = new List <NumberedRoadNumber>(5807);
                        var line    = reader.ReadLine();
                        while (line != null)
                        {
                            numbers.Add(NumberedRoadNumber.Parse(line));
                            line = reader.ReadLine();
                        }

                        return(numbers.ToArray());
                    }
                }

                return(Array.Empty <NumberedRoadNumber>());
            }
        }
        public void ParseThrowsWhenValueIsNot8CharactersLong()
        {
            var value =
                new Generator <string>(_fixture)
                .First(candidate => candidate.Length != 8);

            Assert.Throws <FormatException>(() => NumberedRoadNumber.Parse(value));
        }
        public void ToStringReturnsExpectedResult()
        {
            var value  = _knownValues[new Random().Next(0, _knownValues.Length)];
            var sut    = NumberedRoadNumber.Parse(value);
            var result = sut.ToString();

            Assert.Equal(value, result);
        }
        public void TryParseReturnsExpectedResultWhenValueIsWellFormed()
        {
            var value  = _knownValues[new Random().Next(0, _knownValues.Length)];
            var result = NumberedRoadNumber.TryParse(value, out var parsed);

            Assert.True(result);
            Assert.Equal(value, parsed.ToString());
        }
        public void TryParseReturnsExpectedResultWhenValueIsNot8CharactersLong()
        {
            var value =
                new Generator <string>(_fixture)
                .First(candidate => candidate.Length != 8);

            var result = NumberedRoadNumber.TryParse(value, out var parsed);

            Assert.False(result);
            Assert.Equal(default, parsed);
        public void ParseThrowsWhenValueDoesNotStartWithAcceptableRoadType()
        {
            var value =
                new string(new []
            {
                new Generator <char>(_fixture)
                .First(
                    candidate =>
                    !NumberedRoadNumber.RoadTypes.Any(letter => letter.Equals(candidate))),
                '1', '1', '1', '1', '1', '1', '1'
            });

            Assert.Throws <FormatException>(() => NumberedRoadNumber.Parse(value));
        }
        public void ParseThrowsWhenValueDoesNotEndWithDigitThatIsOneOrTwo()
        {
            var generator = new Generator <char>(_fixture);
            var roadType  = generator
                            .First(
                candidate =>
                NumberedRoadNumber.RoadTypes.Any(
                    letter => letter.Equals(candidate)));
            var all_digits = new char[6];

            for (var index = 0; index < 6; index++)
            {
                all_digits[index] = generator.First(char.IsDigit);
            }
            var not_one_nor_two = generator
                                  .First(candidate =>
                                         char.IsDigit(candidate) && candidate != '1' && candidate != '2');
            var value =
                new string(new [] { roadType }.Concat(all_digits).Concat(new [] { not_one_nor_two }).ToArray());

            Assert.Throws <FormatException>(() => NumberedRoadNumber.Parse(value));
        }
        public void ParseReturnsExpectedResultWhenValueIsWellFormed()
        {
            var value = _knownValues[new Random().Next(0, _knownValues.Length)];

            Assert.Equal(value, NumberedRoadNumber.Parse(value).ToString());
        }
 public void ParseValueCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => NumberedRoadNumber.Parse(null));
 }