Example #1
0
        public void GenerateRandomStringOnlySpecialCharactersTest()
        {
            // Arrange
            var charactersOne   = (Min : 33, Max : 47);
            var charactersTwo   = (Min : 58, Max : 64);
            var charactersThree = (Min : 91, Max : 96);
            var charactersFour  = (Min : 123, Max : 126);
            var stringLength    = 10;
            var options         = new RandomStringOptions
            {
                IncludeSpecialCharacter = true
            };

            // Act
            var result = StringFactory.GenerateRandomString(stringLength, options);

            // Assert
            result.Should().HaveLength(stringLength);
            result.All(c =>
                       Convert.ToByte(c) >= charactersOne.Min && Convert.ToByte(c) <= charactersOne.Max ||
                       Convert.ToByte(c) >= charactersTwo.Min && Convert.ToByte(c) <= charactersTwo.Max ||
                       Convert.ToByte(c) >= charactersThree.Min && Convert.ToByte(c) <= charactersThree.Max ||
                       Convert.ToByte(c) >= charactersFour.Min && Convert.ToByte(c) <= charactersFour.Max
                       ).Should().BeTrue();
        }
Example #2
0
        public void GenerateRandomStringNoCharactersEnabledTest()
        {
            // Arrange
            var stringLength = 10;
            var options      = new RandomStringOptions();

            // Act
            StringFactory.GenerateRandomString(stringLength, options);
        }
Example #3
0
        [InlineData(@"(((0?\d)|(1[012])):[0-6]\d ?([ap]m)|((2[0-3])|([01] ?\d)):[0-6]\d)", 0)]                         // time
        public void VerifyReproducibilityOfRandomStringsFromRegularExpression(string regexStr, int seed)
        {
            Regex regex = new Regex(regexStr);

            string s1 = StringFactory.GenerateRandomString(regex, seed);
            string s2 = StringFactory.GenerateRandomString(regex, seed);

            Assert.Equal <string>(s1, s2);
        }
Example #4
0
        [InlineData(@"(((0?\d)|(1[012])):[0-6]\d ?([ap]m)|((2[0-3])|([01] ?\d)):[0-6]\d)", 0, @"13:05")]                     // time
        public void GenerateRandomStringFromRegularExpression(string regexStr, int seed, string expectedMatch)
        {
            Regex regex = new Regex(regexStr);

            string s = StringFactory.GenerateRandomString(regex, seed);

            Assert.True(regex.IsMatch(s));
            Assert.True(regex.IsMatch(expectedMatch));
        }
Example #5
0
        public void GeneratePureRandomStrings()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;
            string s1 = StringFactory.GenerateRandomString(properties, 1234);

            Assert.NotNull(s1);
        }
Example #6
0
        public void GenerateRandomStringTest()
        {
            // Arrange
            var stringLength = 10;

            // Act
            var result = StringFactory.GenerateRandomString(stringLength);

            // Assert
            result.Should().HaveLength(stringLength);
        }
Example #7
0
        public void GenerateRandomBidiStringsWithCodePointsFromLatinAndHebrewOnly()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 20;

            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.Arabic));
            properties.UnicodeRanges.Clear();

            properties.UnicodeRanges.Add(new UnicodeRange(0x0030, 0x007A));
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.Hebrew));
            properties.IsBidirectional = true;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if ((Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x007A) ||
                    (Convert.ToInt32(c) >= 0x0590 && Convert.ToInt32(c) <= 0x05FF))
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 20);
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Latin code point is in the string
                if (Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x007A)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Hebrew code point is in the string
                if (Convert.ToInt32(c) >= 0x0590 && Convert.ToInt32(c) <= 0x05FF)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);
        }
Example #8
0
        public void VerifyStringLength()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            properties.MaxNumberOfCodePoints = 30;
            string s1 = StringFactory.GenerateRandomString(properties, 1234);

            properties.MinNumberOfCodePoints = properties.MaxNumberOfCodePoints = 5;
            string s2 = StringFactory.GenerateRandomString(properties, 1234);

            Assert.True(s1.Length >= 20 && s1.Length <= 60);
            Assert.True(s2.Length >= 5 && s2.Length <= 10);
        }
Example #9
0
        public void GenerateRandomString()
        {
            StringProperties sp = new StringProperties();

            Assert.Throws <NotImplementedException>(
                delegate
            {
                string s1 = StringFactory.GenerateRandomString(sp, 75);
                string s2 = StringFactory.GenerateRandomString(sp, 75);

                Assert.NotNull(s1);
                Assert.NotNull(s2);
                Assert.Equal <string>(s1, s2);
            });
        }
        static SortedList <DateTime, string> BuildEntriesList(int seed, ICollection <int> offsets)
        {
            var sp = new StringProperties {
                MinNumberOfCodePoints = 0, MaxNumberOfCodePoints = 1000
            };

            var iterations = new SortedList <DateTime, string>(offsets.Count);

            foreach (var offset in offsets)
            {
                iterations.Add(GetDateByOffset(offset), StringFactory.GenerateRandomString(sp, seed++));
            }

            return(iterations);
        }
Example #11
0
        public void GenerateRandomNormalizedString()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0x1FFFF);
            properties.NormalizationForm     = NormalizationForm.FormC;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isFormC = s1.IsNormalized(NormalizationForm.FormC);

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 60);
            Assert.True(isFormC);
        }
Example #12
0
        public void GenerateRandomStringOnlyUpperCaseTest()
        {
            // Arrange
            var characters   = (Min : 65, Max : 90);
            var stringLength = 10;
            var options      = new RandomStringOptions
            {
                IncludeUppercase = true
            };

            // Act
            var result = StringFactory.GenerateRandomString(stringLength, options);

            // Assert
            result.Should().HaveLength(stringLength);
            result.All(c => Convert.ToByte(c) >= characters.Min && Convert.ToByte(c) <= characters.Max).Should().BeTrue();
        }
Example #13
0
        public void GenerateRandomStringsWithCodePointsFromTaiLeAndNewTaiLueOnly()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 20;
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.TaiLe));
            properties.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.NewTaiLue));
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if ((Convert.ToInt32(c) >= 0x1950 && Convert.ToInt32(c) <= 0x19DF))
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 20);
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure Tai Le code point is in the string
                if (Convert.ToInt32(c) >= 0x1950 && Convert.ToInt32(c) <= 0x197F)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);

            isInTheRange = false;
            foreach (char c in s1)
            {
                // Make sure New Tai Lue code point is in the string
                if (Convert.ToInt32(c) >= 0x1980 && Convert.ToInt32(c) <= 0x19DF)
                {
                    isInTheRange = true;
                }
            }
            Assert.True(isInTheRange);
        }
Example #14
0
        public void GenerateRandomStringOnlyNumbersTest()
        {
            // Arrange
            var numbers      = (Min : 48, Max : 57);
            var stringLength = 10;
            var options      = new RandomStringOptions
            {
                IncludeNumbers = true
            };

            // Act
            var result = StringFactory.GenerateRandomString(stringLength, options);

            // Assert
            result.Should().HaveLength(stringLength);
            result.All(c => Convert.ToByte(c) >= numbers.Min && Convert.ToByte(c) <= numbers.Max).Should().BeTrue();
        }
Example #15
0
        public void TestConvertHtmlMessageToPlainTextBasic()
        {
            var properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            RandomDataHelper.Ranges.ForEach(properties.UnicodeRanges.Add);
            properties.UnicodeRanges.Remove(new UnicodeRange('<', '<'));
            properties.UnicodeRanges.Remove(new UnicodeRange('>', '>'));

            // Can't have '<' or '>' chars in the content, since it breaks the HTML processing. This is OK, since real HTML should never have these
            // chracters either (they will be escaped as &lt; and &gt;)
            var expectedText =
                StringFactory.GenerateRandomString(properties, _rand.Next()).Trim().Replace("<", "").Replace(">", "");
            var htmlText  = string.Format("<html><head></head><body><p>{0}</p></body></html>", expectedText);
            var plainText = EmailBodyProcessingUtils.ConvertHtmlMessageToPlainText(htmlText);

            Assert.AreEqual(plainText, expectedText);
        }
Example #16
0
        public void VerifySameSeedGeneratesSameString()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;

            string s1 = StringFactory.GenerateRandomString(properties, 1234);
            string s2 = StringFactory.GenerateRandomString(properties, 1234);
            string s3 = StringFactory.GenerateRandomString(properties, 4321);

            Assert.NotNull(s1);
            Assert.NotNull(s2);
            Assert.NotNull(s2);

            Assert.Equal <string>(s1, s2);
            Assert.NotEqual <string>(s1, s3);
        }
Example #17
0
        public override object GetData(DeterministicRandom random)
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                    {
                        instance = new CLRDataItem();
                        StringProperties strProperties = new StringProperties();
                        strProperties.MinNumberOfCodePoints = 0;
                        strProperties.MaxNumberOfCodePoints = 200;
// Fixed build break + notified Microsoft.  Turns out to not be a 3.5/4.0 issue but rather a plain old build break.
//                        strProperties.UnicodeRange = new UnicodeRange(0x0000, 0xffff);
                        string stringValue = StringFactory.GenerateRandomString(strProperties, random.Next());
                        instance.ModifyData(stringValue, random.Next(10), random.NextBool(), random.NextDouble(), (float)random.NextDouble());
                    }
                }
            }

            return(instance);
        }
Example #18
0
        public void GenerateRandomStringsWithProvidedChartOfArabicSupplement()
        {
            StringProperties properties1 = new StringProperties();

            properties1.MinNumberOfCodePoints = 5;
            properties1.MaxNumberOfCodePoints = 10;
            properties1.UnicodeRange          = new UnicodeRange(UnicodeChart.ArabicSupplement);
            string s1 = StringFactory.GenerateRandomString(properties1, 1234);

            bool isInTheRange = true;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) < 0x0750 || Convert.ToInt32(c) > 0x077F)
                {
                    isInTheRange = false;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 5 && s1.Length <= 20);
            Assert.True(isInTheRange);
        }
Example #19
0
        public void GenerateRandomStringsWithCombiningMarks()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 30;
            properties.UnicodeRanges.Add(new UnicodeRange(0x0000, 0x03FF));
            properties.MinNumberOfCombiningMarks = 5;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) <= 0x03FF)
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 30);
            Assert.True(isInTheRange);
        }
Example #20
0
        public void GenerateRandomStringsWithNumbers()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            properties.MaxNumberOfCodePoints = 30;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0x1FFFF);
            properties.HasNumbers            = true;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool hasNumber = false;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x0039)
                {
                    hasNumber = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 20 && s1.Length <= 60);
            Assert.True(hasNumber);
        }
Example #21
0
        public void GenerateRandomStringsWithEndUserDefinedCodePoints()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 20;
            properties.MaxNumberOfCodePoints = 30;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0xFFFF);
            properties.MinNumberOfEndUserDefinedCodePoints = 5;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            int numOfEUDC = 0;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0xE000 && Convert.ToInt32(c) <= 0xF8FF)
                {
                    numOfEUDC++;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 20 && s1.Length <= 30);
            Assert.True(numOfEUDC >= 5);
        }
Example #22
0
        public void GenerateRandomStringsWithSegmentation()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 40;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0xFFFF);
            properties.MinNumberOfTextSegmentationCodePoints = 5;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool isInTheRange = false;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) <= 0xFFFF)
                {
                    isInTheRange = true;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 40);
            Assert.True(isInTheRange);
        }
Example #23
0
        public void GenerateRandomStringsWithSurrogates()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints     = 20;
            properties.MaxNumberOfCodePoints     = 30;
            properties.UnicodeRange              = new UnicodeRange(0x0000, 0x1FFFF);
            properties.MinNumberOfSurrogatePairs = 5;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            int numOfSurrogates = 0;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0xD800 && Convert.ToInt32(c) <= 0xDBFF)
                {
                    numOfSurrogates++;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 20 && s1.Length <= 60);
            Assert.True(numOfSurrogates >= 5);
        }
Example #24
0
        public void GenerateRandomStringsWithEndUserDefinedCharactersAndHasNumber()
        {
            StringProperties properties = new StringProperties();

            properties.MinNumberOfCodePoints = 10;
            properties.MaxNumberOfCodePoints = 40;
            properties.UnicodeRange          = new UnicodeRange(0x0000, 0xFFFF);
            properties.MinNumberOfEndUserDefinedCodePoints = 6;
            properties.HasNumbers = true;
            String s1 = StringFactory.GenerateRandomString(properties, 1234);

            bool hasNumbers = false;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0x0030 && Convert.ToInt32(c) <= 0x0039)
                {
                    hasNumbers = true;
                }
            }
            Assert.True(hasNumbers);

            int numOfEUDCs = 0;

            foreach (char c in s1)
            {
                if (Convert.ToInt32(c) >= 0xE000 && Convert.ToInt32(c) <= 0xF8FF)
                {
                    numOfEUDCs++;
                }
            }

            Assert.NotNull(s1);
            Assert.True(s1.Length >= 10 && s1.Length <= 40);
            Assert.True(numOfEUDCs >= 6);
        }
Example #25
0
        public void VerifyOnlyLatinChartGivenForBidiProperty()
        {
            StringProperties sp = new StringProperties();

            sp.MinNumberOfCodePoints = 5;
            sp.MaxNumberOfCodePoints = 10;
            sp.UnicodeRanges.Add(new UnicodeRange(UnicodeChart.Latin));
            sp.IsBidirectional = true;
            Random rand = new Random();

            bool exceptionCaught = false;

            try
            {
                string s = StringFactory.GenerateRandomString(sp, rand.Next());
            }
            catch (ArgumentOutOfRangeException e)
            {
                Assert.True(e.Message.Contains("Refer to Arabic and Hebrew ranges"));
                exceptionCaught = true;
            }

            Assert.True(exceptionCaught);
        }
Example #26
0
 public void GenerateRandomStringNegativeStringLenghtTest()
 {
     // Act
     StringFactory.GenerateRandomString(-10);
 }
Example #27
0
 public void GenerateRandomStringZeroStringLenghtTest()
 {
     // Act
     StringFactory.GenerateRandomString(0);
 }
Example #28
0
 public static string GetBody(int seed)
 {
     return(StringFactory.GenerateRandomString(BodyProperties, seed));
 }
Example #29
0
 public static string GetSubject(int seed)
 {
     return(StringFactory.GenerateRandomString(SubjectProperties, seed));
 }
Example #30
0
 public static string GetAlias(int seed)
 {
     return(StringFactory.GenerateRandomString(AliasProperties, seed));
 }