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() }); } }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call NextDouble to check the Sample works"); try { TestRandom random = new TestRandom(-55); double value = random.NextDouble(); if ((value < 0.0) || (value >= 1.0)) { TestLibrary.TestFramework.LogError("001.1", "NextDouble returns a value less than 0 or equal to 1.0"); TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value); retVal = false; } value = random.CallSample(); if ((value < 0.0) || (value >= 1.0)) { TestLibrary.TestFramework.LogError("001.2", "NextDouble returns a value less than 0 or equal to 1.0"); TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Call NextDouble to check the Sample works"); try { TestRandom random = new TestRandom(-55); double value = random.NextDouble(); if ((value < 0.0) || (value >= 1.0)) { TestLibrary.TestFramework.LogError("001.1", "NextDouble returns a value less than 0 or equal to 1.0"); TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value); retVal = false; } value = random.CallSample(); if ((value < 0.0) || (value >= 1.0)) { TestLibrary.TestFramework.LogError("001.2", "NextDouble returns a value less than 0 or equal to 1.0"); TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }