Example #1
0
        public IEnumerable <Product> GenerateCatalog(int count = 1000)
        {
            // Adapted from https://weblogs.asp.net/dfindley/Microsoft-Product-Name-Generator
            var prefixes   = new[] { null, "Visual", "Compact", "Embedded", "Expression" };
            var products   = new[] { null, "Windows", "Office", "SQL", "FoxPro", "BizTalk" };
            var terms      = new[] { "Web", "Robotics", "Network", "Testing", "Project", "Small Business", "Team", "Management", "Graphic", "Presentation", "Communication", "Workflow", "Ajax", "XML", "Content", "Source Control" };
            var type       = new[] { null, "Client", "Workstation", "Server", "System", "Console", "Shell", "Designer" };
            var suffix     = new[] { null, "Express", "Standard", "Professional", "Enterprise", "Ultimate", "Foundation", ".NET", "Framework" };
            var components = new[] { prefixes, products, terms, type, suffix };

#if SNIPPET
            var random = new Random();
#else
            TestRandom random = Recording.Random;
#endif
            string RandomElement(string[] values) => values[(int)(random.NextDouble() * values.Length)];
            double RandomPrice() => (random.Next(2, 20) * 100.0) / 2.0 - .01;

            for (int i = 1; i <= count; i++)
            {
                yield return(new Product
                {
                    Id = i.ToString(),
                    Name = string.Join(" ", components.Select(RandomElement).Where(n => n != null)),
                    Price = RandomPrice()
                });
            }
        }
Example #2
0
 private static void HalfRandom(byte[] data)
 {
     for (int nx = 0; nx < 32; nx++)
     {
         data[TestRandom.Next(0, data.Length)] = (byte)TestRandom.Next();
     }
 }