public async Task <IActionResult> Populate() { // this method will populate the Couchbase bucket with a bunch of randomish user profiles var users = new List <User>(); for (var i = 0; i < 100; i++) { var user = FakeUser.Create(); _userRepository.Save(user); users.Add(user); } // also add some Alex, Allex, and Alec users _userRepository.Save(FakeUser.Create(firstName: "Alex", enabled: true, countryCode: "US")); _userRepository.Save(FakeUser.Create(firstName: "Allex", enabled: true, countryCode: "US")); _userRepository.Save(FakeUser.Create(firstName: "Alec", enabled: true, countryCode: "US")); // also add some randomish User Events for (var i = 0; i < 100; i++) { // I'm only pulling from the first 10 users just to increase event density var randomUser = users[Faker.RandomNumber.Next(0, 10)]; var fakeUserActivity = UserEventGenerator.Create(randomUser.Id); await _userRepository.AddEventAsync(fakeUserActivity); } return(Ok()); }
static void Main(string[] args) { // basic settings var numberOfUserProfilesToGenerate = 25000; var fileToCreate = "user-profile-sample.json"; var camelCaseSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; // start a new file if necessary if (File.Exists(fileToCreate)) { File.Delete(fileToCreate); } // this will be "list" format, so start an array File.AppendAllText(fileToCreate, "["); for (var i = 0; i < numberOfUserProfilesToGenerate; i++) { // this will be "list" format, so put a comma before each object (except the first one) if (i != 0) { File.AppendAllText(fileToCreate, ","); } // create randomish user, serialize to json, write to the file var user = FakeUser.Create(); var userJson = JsonConvert.SerializeObject(user, camelCaseSettings); File.AppendAllText(fileToCreate, userJson); } // this will be "list" format, so end the array File.AppendAllText(fileToCreate, "]"); }
static void AddUsers(int userCount, bool addEvents) { var users = new List <User>(); for (var i = 0; i < userCount; i++) { var user = FakeUser.Create(); UserRepository.Save(user); System.Console.WriteLine($"Added user - Id={user.Id}"); users.Add(user); } if (users?.Count > 0) { if (addEvents) { AddEventsToUsers(users); } System.Console.WriteLine($"{users.Count} users saved successfully!"); } }
static void AddUser(string firstName, bool enabled, string countryCode) { var user = FakeUser.Create(firstName, enabled, countryCode); UserRepository.Save(user); System.Console.WriteLine($"User {firstName} saved successfully!"); }