public YamlConfiguration(string configurationFile) { if (!File.Exists(configurationFile)) { return; } _config = File.ReadAllLines(configurationFile) .Where(l => !l.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(l)) .ToDictionary(ConfigName, ConfigValue); this.Mode = GetTestMode(_config["mode"]); this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(_config["elasticsearch_version"]); this.ForceReseed = bool.Parse(_config["force_reseed"]); this.TestAgainstAlreadyRunningElasticsearch = _config.TryGetValue("test_against_already_running_elasticsearch", out var tar) && bool.Parse(tar); this.ClusterFilter = _config.ContainsKey("cluster_filter") ? _config["cluster_filter"] : null; this.TestFilter = _config.ContainsKey("test_filter") ? _config["test_filter"] : null; this.Seed = _config.TryGetValue("seed", out var seed) ? int.Parse(seed) : 1337; Randomizer.Seed = new Random(this.Seed); var randomizer = new Randomizer(); if (_config.TryGetValue("force_custom_source_serializer", out var v)) { this.UsingCustomSourceSerializer = bool.Parse(v); } else { this.UsingCustomSourceSerializer = randomizer.Bool(); } }
private static bool RandomBoolConfig(string key, Randomizer randomizer) { if (TryGetEnv("NEST_RANDOM_" + key, out var source) && bool.TryParse(source, out var b)) { return(b); } return(randomizer.Bool()); }
public void GlobalSetup() { _luaScriptingEngine = new LuaScriptingEngine("res = dataObject.BoolProp"); _jsScriptingEngine = new JavascriptScriptingEngine("res = dataObject.BoolProp"); _csharpScriptingEngine = new CsharpScriptingEngine("return DataObject.BoolProp;"); var bogus = new Randomizer(); _testClasses = new TestClass[Size]; for (int i = 0; i < Size; i++) { var c = new TestClass(); c.BoolProp = bogus.Bool(); c.DecimalProp = bogus.Decimal(); c.StringProp = bogus.String(10, 200); _testClasses[i] = c; } }
private static void SeedMatchResult(LeagueContext leagueContext, Randomizer randomizer, Match match) { byte firstPlayerWins; byte secondPlayerWins; if (randomizer.Bool()) { SeedMatchResult(randomizer, out firstPlayerWins, out secondPlayerWins); } else { SeedMatchResult(randomizer, out secondPlayerWins, out firstPlayerWins); } match.FirstPlayerWins = firstPlayerWins; match.SecondPlayerWins = secondPlayerWins; leagueContext.Entry(match).Property(m => m.FirstPlayerWins).IsModified = true; leagueContext.Entry(match).Property(m => m.SecondPlayerWins).IsModified = true; leagueContext.SaveChanges(); }
public EnvironmentConfiguration() { //if env var NEST_INTEGRATION_VERSION is set assume integration mode //used by the build script FAKE var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION"); if (!string.IsNullOrEmpty(version)) { Mode = TestMode.Integration; } this.ElasticsearchVersion = ElasticsearchVersion.GetOrAdd(string.IsNullOrWhiteSpace(version) ? DefaultVersion : version); this.ClusterFilter = Environment.GetEnvironmentVariable("NEST_INTEGRATION_CLUSTER"); this.TestFilter = Environment.GetEnvironmentVariable("NEST_TEST_FILTER"); var newRandom = new Random().Next(1, 100000); this.Seed = TryGetEnv("NEST_TEST_SEED", out var seed) ? int.Parse(seed) : newRandom; Randomizer.Seed = new Random(this.Seed); var randomizer = new Randomizer(); this.UsingCustomSourceSerializer = (TryGetEnv("NEST_SOURCE_SERIALIZER", out var source) && bool.Parse(source)) || randomizer.Bool(); }
public static Guid?NullableUuid(this Randomizer r) { return(r.Bool() ? r.Uuid() : (Guid?)null); }
public void PacketStreamWriteBooleanTest() { var booleanValue = _randomizer.Bool(); PacketStreamWritePrimitive(booleanValue, BitConverter.GetBytes(booleanValue)); }
public void random_bool() { r.Bool().Should().BeFalse(); }
private bool RandomBool(string key, Randomizer randomizer) => _config.TryGetValue($"random_{key}", out var v) ? bool.Parse(v) : randomizer.Bool();
public void PacketStreamReadBooleanTest() { var booleanValue = _randomizer.Bool(); PacketStreamReadTest(booleanValue, BitConverter.GetBytes(booleanValue)); }
public void Seed() { _db.DropCollection(nameof(Student)); _db.DropCollection(nameof(Exam)); _db.DropCollection(nameof(Teacher)); Randomizer.Seed = new Random(1454); var rnd = new Randomizer(); var teachers = new Faker <Teacher>("de") .CustomInstantiator(f => { var lastname = f.Name.LastName(); return(new Teacher( shortname: lastname.Length < 3 ? lastname.ToUpper() : lastname.Substring(0, 3).ToUpper(), firstname: f.Name.FirstName(), lastname: lastname) { Email = $"{lastname.ToLower()}@spengergasse.at".OrDefault(f, 0.25f) // using Bogus.Extensions; }); }) .Generate(200) // Take nimmt nur 20 Elemente des Enumerators .GroupBy(g => g.Shortname) .Select(g => g.First()) .Take(20) .ToList(); _db.GetCollection <Teacher>(nameof(Teacher)).InsertMany(teachers); int id = 1000; var subjects = new string[] { "POS", "DBI", "D", "E", "AM" }; var classes = new string[] { "4AHIF", "4BHIF", "4CHIF", "4EHIF" }; var students = new Faker <Student>("de") .CustomInstantiator(f => { var s = new Student( id: id++, firstname: f.Name.FirstName(), lastname: f.Name.LastName(), schoolClass: f.Random.ListItem(classes), dateOfBirth: new DateTime(2003, 1, 1).AddDays(f.Random.Int(0, 4 * 365))); var grades = new Faker <Grade>("de") .CustomInstantiator(f => new Grade( value: f.Random.Int(1, 5), subject: f.Random.ListItem(subjects))) .Generate(5); foreach (var g in grades) { s.UpsertGrade(g); } return(s); }) .Generate(100) .ToList(); _db.GetCollection <Student>(nameof(Student)).InsertMany(students); var negative = students.SelectMany(s => s.NegativeGrades.Select(n => new { Student = s, Grade = n })).ToList(); var exams = rnd .ListItems(negative, negative.Count / 2) .Select(n => { var teacher = rnd.ListItem(teachers); var assistant = rnd.ListItem(teachers); // In 20% der Fälle liefern wir ein GradedExam (schon benotet). var e = new Exam( student: n.Student, teacher: rnd.ListItem(teachers), subject: n.Grade.Subject); return(rnd.Bool(0.5f) && teacher.Shortname != assistant.Shortname ? new GradedExam( exam: e, assistant: rnd.ListItem(teachers), grade: new Grade(value: rnd.Int(3, 5), subject: n.Grade.Subject)) : e); }) .ToList(); _db.GetCollection <Exam>(nameof(Exam)).InsertMany(exams); }