private POCOMultiTypeObject CreateRandomPoco(bool nullableSetNull = false) { var randomizer = new Bogus.Randomizer(); var poco = new POCOMultiTypeObject() { BoolField = randomizer.Bool(), DateTimeField = DateTime.Now, NDateTimeField = (nullableSetNull) ? (DateTime?)null : DateTime.Now, StrDateTime = (nullableSetNull) ? (string)null : DateTime.Now.ToShortTimeString(), DoubleField = randomizer.Double(), FloatField = randomizer.Float(), GuidField = randomizer.Guid(), NGuidField = (nullableSetNull) ? (Guid?)null : randomizer.Guid(), ID = randomizer.Int(), IntField = randomizer.Int(), LongField = randomizer.Long(), NBoolField = (nullableSetNull) ? (bool?)null : randomizer.Bool(), NDoubleField = (nullableSetNull) ? (double?)null : randomizer.Double(), NFloatField = (nullableSetNull) ? (float?)null : randomizer.Float(), NIntField = (nullableSetNull) ? (int?)null : randomizer.Int(), NLongField = (nullableSetNull) ? (long?)null : randomizer.Long(), //RowID = randomizer.Int(), StringField = randomizer.String2(16), }; return(poco); }
public void Setup() { List <byte[]> bytesList = new List <byte[]>(Size); List <byte[]> bytesList2 = new List <byte[]>(Size); List <byte[]> bytesList3 = new List <byte[]>(Size); List <MyTestClass> testClasses = new List <MyTestClass>(Size); var bogus = new Bogus.Randomizer(); for (int i = 0; i < Size; i++) { MyTestClass myTestClass = new MyTestClass(); myTestClass.BoolProp = bogus.Bool(); myTestClass.IntList = new List <int>(100); for (int j = 0; j < 100; j++) { myTestClass.IntList.Add(bogus.Int()); } myTestClass.StringProp = bogus.String(10, 100); myTestClass.StringProp2 = bogus.String(10, 100); bytesList.Add(JsonSerializer.Serialize(myTestClass)); bytesList3.Add(System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(myTestClass)); bytesList2.Add(MessagePack.MessagePackSerializer.Typeless.Serialize(myTestClass, ContractlessStandardResolver.Options)); testClasses.Add(myTestClass); } _serializedObjectsUtf8Json = bytesList.ToArray(); _serializedObjectsMessagePack = bytesList2.ToArray(); _serializedObjectsTextJson = bytesList3.ToArray(); _testClasses = testClasses.ToArray(); }
public void Setup() { var bogus = new Bogus.Randomizer(); BufferSegment headerBufferSegment = new BufferSegment(Constants.PAGE_SIZE); var headerPage = HeaderPage.CreateHeaderPage(headerBufferSegment); BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); PageHeader header = new PageHeader(1, PageType.Data); header.ToBuffer(bufferSegment.Span, 0); File.Delete(@"C:\Neuer Ordner\test.db"); PageService pageService = new PageService(FileDiskService.Create(new DatatentSettings() { InMemory = false, Path = @"C:\Neuer Ordner\test.db" })); _dataService = new DataService(new NopCompressionService(), pageService); _objects = new List <TestObject>(50); foreach (var i in Enumerable.Range(0, 50)) { TestObject testObject = new TestObject(); testObject.IntProp = bogus.Int(); testObject.StringProp = bogus.String2(1000); _objects.Add(testObject); } }
public async Task SimpleInsertAndGetWithCheckpointTest() { var bogus = new Bogus.Randomizer(); using BufferSegment headerBufferSegment = new BufferSegment(Constants.PAGE_SIZE); var headerPage = HeaderPage.CreateHeaderPage(headerBufferSegment); using BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); PageHeader header = new PageHeader(1, PageType.Data); header.ToBuffer(bufferSegment.Span, 0); PageService pageService = new PageService(new InMemoryDiskService()); DataService dataService = new DataService(new NopCompressionService(), pageService); TestObject testObject = new TestObject(); testObject.IntProp = bogus.Int(); testObject.StringProp = bogus.String2(1000); var address = await dataService.Insert(testObject); address.SlotId.ShouldBe((byte)1); address.PageId.ShouldBe((ushort)1); await pageService.CheckPoint(); var obj = await dataService.Get <TestObject>(address); obj.ShouldNotBeNull(); obj.ShouldBe(testObject); // there should be no second page var secondPage = await pageService.GetPage <BasePage>(2); secondPage.ShouldBeNull(); }
public async Task LargeInsertTest() { var bogus = new Bogus.Randomizer(); using BufferSegment headerBufferSegment = new BufferSegment(Constants.PAGE_SIZE); var headerPage = HeaderPage.CreateHeaderPage(headerBufferSegment); using BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); PageHeader header = new PageHeader(1, PageType.Data); header.ToBuffer(bufferSegment.Span, 0); PageService pageService = new PageService(new InMemoryDiskService()); DataService dataService = new DataService(new NopCompressionService(), pageService); TestObject testObject = new TestObject(); testObject.IntProp = bogus.Int(); testObject.StringProp = bogus.String2(1000); for (int i = 0; i < 10000; i++) { var address = await dataService.Insert(testObject); address.SlotId.ShouldBeGreaterThan((byte)0); address.PageId.ShouldBeGreaterThan((byte)0); if (i > 254) { address.PageId.ShouldBeGreaterThan((uint)1); } var resObject = await dataService.Get <TestObject>(address); resObject.ShouldBe(testObject); } }
public static int GoalsAssistsStatsRandomizer(this Bogus.Randomizer randomizer, Position playerPosition, int minValue, int maxValue) { return(playerPosition switch { Position.Goalkeeper => 0, _ => randomizer.Int(minValue, maxValue) });
public void Setup() { var rand = new Bogus.Randomizer(); // generate input data, e.g.: [ t, f, f, t, t, t, f ] bool[] data = Enumerable .Range(0, Length) .Select(_ => rand.Bool()) .ToArray(); // generate indexes to check, e.g.: [ 5, 2, 0, 6, 9, 1, 8, 3 ] // (we don't really care whether bit is set or not; we need same indexes for all benchmarks) _idx = Enumerable .Range(0, Length) .Select(_ => rand.Int(0, Length - 1)) .ToArray(); // only `true` values are stored, missing value means bit is not set _bitArray = new System.Collections.BitArray(data); _map = new Dictionary <int, bool>( data.Select((v, i) => KeyValuePair.Create(i, v)) .Where(kv => kv.Value)); _set = new HashSet <int>( data.Select((v, i) => (v, i)) .Where(t => t.v) .Select(t => t.i)); }
public async Task ChangeAppPath() { // [Setup] // setup webhost using appsettings with specific path var random = new Bogus.Randomizer(); var randomPathChars = random.Chars('a', 'z', random.Int(1, 10)); var randomPath = new string(randomPathChars); var randomSecret = random.Words(10); var hostbuilder = WebHost .CreateDefaultBuilder() .ConfigureServices(s => { s .AddOurOrders(appSettings => { appSettings.Path = randomPath; appSettings.JwtSecret = randomSecret; }) .UseInMemoryDB(); }) .Configure(appbuilder => { appbuilder .UseOurOrders(); }); var server = new TestServer(hostbuilder); var httpClient = server.CreateClient(); // [Exercise] // send a request to the webhost on the specified path var path = $"/{randomPath}/account/current"; var response = await httpClient.GetAsync(path); // [Verify] // check if request is successful Assert.True(response.IsSuccessStatusCode); // [Teardown] // shut down the server that we setup server.Dispose(); }
public async Task SimpleInsertTest() { var bogus = new Bogus.Randomizer(); using BufferSegment headerBufferSegment = new BufferSegment(Constants.PAGE_SIZE); var headerPage = HeaderPage.CreateHeaderPage(headerBufferSegment); using BufferSegment bufferSegment = new BufferSegment(Constants.PAGE_SIZE); PageHeader header = new PageHeader(1, PageType.Data); header.ToBuffer(bufferSegment.Span, 0); PageService pageService = new PageService(new InMemoryDiskService()); DataService dataService = new DataService(new NopCompressionService(), pageService); TestObject testObject = new TestObject(); testObject.IntProp = bogus.Int(); testObject.StringProp = bogus.String2(1000); var address = await dataService.Insert(testObject); address.SlotId.ShouldBe((byte)1); address.PageId.ShouldBe((ushort)1); }
private async Task <int> CreateUsers(int howMany, bool household, bool quiet) { int created = 0; int[] familyOptions = { 1, 2, 3, 4, 5, FamilyRandomIndicator, GroupRandomIndicator }; float[] familyWeights = { 0.25F, 0.35F, 0.21F, 0.10F, 0.04F, 0.047F, 0.003F }; var issues = new List <string>(); // make the participants var users = await _userDataGenerator.Generate(Site.Id, howMany); var minDateTime = DateTime.MaxValue; var maxDateTime = DateTime.MinValue; if (!quiet) { Console.Write($"Inserting {howMany} users... "); } ProgressBar progress = quiet ? null : new ProgressBar(); try { var rand = new Bogus.Randomizer(); int familyMembers = 0; Domain.Model.User parent = null; // insert the participants foreach (var user in users) { bool currentUserParent = false; // set an appropriate random date and time for insertion var setDateTime = _dateTimeDataGenerator.SetRandom(Site); if (setDateTime < minDateTime) { minDateTime = setDateTime; } if (setDateTime > maxDateTime) { maxDateTime = setDateTime; } if (familyMembers > 0) { // we are processing family members user.User.LastName = parent.LastName; if (rand.Int(1, 100) > 5) { user.User.Username = null; } // insert the family member try { await _facade .UserService .AddHouseholdMemberAsync(parent.Id, user.User); created++; } catch (GraException gex) { issues.Add($"Household username: {user.User.Username} - {gex.Message}"); } familyMembers--; } else { // not processing family members, should this person be a head of household? if (household && rand.Int(1, 100) <= 31) { currentUserParent = true; familyMembers = rand.WeightedRandom <int>(familyOptions, familyWeights); if (familyMembers == FamilyRandomIndicator) { familyMembers = rand.Int(6, 10); } else if (familyMembers == GroupRandomIndicator) { familyMembers = rand.Int(11, 100); } } // insert the created user try { var inserted = await _facade .UserService .RegisterUserAsync(user.User, user.Password); if (currentUserParent) { parent = inserted; } created++; } catch (Exception ex) { issues.Add($"Username: {user.User.Username} - {ex.Message}"); } } if (progress != null) { progress.Report((double)created / howMany); } } } finally { if (progress != null) { progress.Dispose(); } } Console.WriteLine($"Created {created} random users in {Site.Name}."); Console.WriteLine($"Users registered between {minDateTime} and {maxDateTime}."); if (issues.Count > 0) { Console.WriteLine("Some issues were encountered:"); foreach (string issue in issues) { Console.WriteLine($"- {issue}"); } } await DisplayUserCount(); return(howMany == created ? 0 : 1); }
Generate(Site site, int count, int challengePercent, int codePercent, bool quiet) { int[] minuteCeilings = { 60, 120, 500 }; float[] minuteCeilingDistribution = { 0.85F, 0.1F, 0.05F }; var userList = await _userService.GetPaginatedUserListAsync(new UserFilter()); var codeList = await _triggerService.GetPaginatedListAsync(new TriggerFilter { SecretCodesOnly = true }); var challengeList = await _challengeService .GetPaginatedChallengeListAsync(new ChallengeFilter()); var activities = new List <GeneratedActivity>(); var rand = new Bogus.Randomizer(); if (!quiet) { Console.Write($"Generating {count} activity items... "); } ProgressBar progress = quiet ? null : new ProgressBar(); try { for (int i = 0; i < count; i++) { bool addActivity = false; var randomUser = (await _userService.GetPaginatedUserListAsync(new UserFilter { SiteId = site.Id, Skip = rand.Int(0, userList.Count - 1), Take = 1 })).Data.First(); var act = new GeneratedActivity { User = randomUser, }; if (challengePercent > 0 && rand.Int(1, 100) <= challengePercent) { bool isValid = false; int challengeLookupCount = 0; await _configureUserSite.Lookup(randomUser.Id); _challengeService.ClearCachedUserContext(); DataWithCount <IEnumerable <Challenge> > randomChallenge = null; while (!isValid) { challengeLookupCount++; var filter = new ChallengeFilter() { Take = rand.Int(0, challengeList.Count - 1), Skip = 1 }; randomChallenge = await _challengeService.GetPaginatedChallengeListAsync(filter); if (randomChallenge.Data != null && randomChallenge.Data.FirstOrDefault() != null) { isValid = randomChallenge.Data.First().IsValid; } if (challengeLookupCount > 20) { _logger.LogError($"Unable to find an eligible challenge for user id {randomUser.Id} after 20 tries, giving up."); randomChallenge = null; addActivity = false; break; } } if (randomChallenge != null) { var randomTasks = await _challengeService .GetChallengeTasksAsync(randomChallenge.Data.First().Id); var randomTask = randomTasks .Skip(rand.Int(0, randomTasks.Count() - 1)).First(); randomTask.IsCompleted = true; act.ActivityType = ActivityType.ChallengeTasks; act.ChallengeId = randomChallenge.Data.First().Id; act.ChallengeTasks = new List <ChallengeTask> { randomTask }; addActivity = true; } } else { if (codePercent > 0 && rand.Int(1, 100) <= codePercent) { var randomCode = (await _triggerService.GetPaginatedListAsync(new TriggerFilter { SiteId = site.Id, Skip = rand.Int(0, codeList.Count - 1), Take = 1, SecretCodesOnly = true })).Data.First(); act.ActivityType = ActivityType.SecretCode; act.SecretCode = randomCode.SecretCode; addActivity = true; } else { act.ActivityAmount = rand.Int(1, rand .WeightedRandom <int>(minuteCeilings, minuteCeilingDistribution)); act.ActivityType = ActivityType.Default; addActivity = true; } } if (addActivity) { activities.Add(act); } if (progress != null) { progress.Report((double)i / count); } } } finally { if (progress != null) { progress.Dispose(); Console.WriteLine(); } } return(activities); }