示例#1
0
        public void NameValidation_WhenRegexConstraintsSpecified2_OutputReflectsConstraints()
        {
            var provider  = new DefaultSyllableProvider();
            var validator = new NameValidator();

            validator.DoNotAllowPattern(@"[^aeiouAEIOU]{3,}"); // Rejects 3 or more consecutive consonants

            Assert.IsTrue(validator.IsValidName(new Name()
            {
                Syllables = new List <String>()
                {
                    "bc"
                }
            }));
            Assert.IsFalse(validator.IsValidName(new Name()
            {
                Syllables = new List <String>()
                {
                    "bcd"
                }
            }));
            Assert.IsFalse(validator.IsValidName(new Name()
            {
                Syllables = new List <String>()
                {
                    "bcdf"
                }
            }));

            var generator = new NameGenerator();

            generator.UsingProvider(provider);
            generator.UsingValidator(validator);

            for (int i = 1000; i < 1; i++)
            {
                var original = generator.Next();
                var name     = new StringBuilder(original.ToLower());

                name.Replace("a", " ");
                name.Replace("e", " ");
                name.Replace("i", " ");
                name.Replace("o", " ");
                name.Replace("u", " ");

                var consonantGroups = name.ToString().Split(" ");

                int maxConsonantSequenceLength = 0;
                foreach (var sequence in consonantGroups)
                {
                    if (sequence.Length > maxConsonantSequenceLength)
                    {
                        maxConsonantSequenceLength = sequence.Length;
                    }
                }

                Assert.IsTrue(maxConsonantSequenceLength < 3);
            }
        }
示例#2
0
 public void IsValidNameTest(bool isValidName, string name)
 {
     Assert.AreEqual(isValidName, NameValidator.IsValidName(name));
 }