public void CreateCSV(int numberOfRecords) { var r = new Random(500); PersonCollection people = new PersonCollection(); people.GeneratePeople(100, r); var f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "DeleteMeTestPeople.csv")); bool finished = false; int finishedWithRecords = -1; Demography demog = new Demography(r); demog.RowsGenerated += (s, e) => { finished = e.IsFinished; finishedWithRecords = e.RowsWritten; }; demog.GenerateTestDataFile(people, f, numberOfRecords); //one progress task only, should have reported craeting 10,000 rows //one progress task only, should have reported creating the correct number of rows Assert.IsTrue(finished); Assert.AreEqual(numberOfRecords, finishedWithRecords); Assert.GreaterOrEqual(File.ReadAllLines(f.FullName).Length, numberOfRecords);//can be newlines in middle of file f.Delete(); }
/// <summary> /// Prepares to create a new table in the <paramref name="targetDatabase"/> of test data using <see cref="Demography"/>. To actually generate the data /// call <see cref="SetupTestData"/> /// </summary> /// <param name="repository"></param> /// <param name="targetDatabase"></param> /// <param name="numberOfRows"></param> public BulkTestsData(ICatalogueRepository repository, DiscoveredDatabase targetDatabase, int numberOfRows = 10000) { _repository = repository; BulkDataDatabase = targetDatabase; ExpectedNumberOfRowsInTestData = numberOfRows; _dataGenerator = new Demography(new Random(500)); }
// Update is called once per frame void Update() { if (demography == null) { demography = worldController.world.thisCountry.demography; } if (demography != null) { totalPopulationText.text = StringUtilities.longToShortString(demography.population, 1) + " (" + StringUtilities.longToShortString(demography.population - demography.old_population, 1) + ")"; } }
/// <summary> /// Creates a new demography file ready for loading in the ForLoading directory of the load with the specified number of <paramref name="rows"/> /// </summary> /// <param name="filename">Filename to generate in ForLoading e.g. "bob.csv" (cannot be relative)</param> /// <param name="rows"></param> /// <param name="r">Seed random to ensure tests are reproducible</param> protected FileInfo CreateFileInForLoading(string filename, int rows, Random r) { var fi = new FileInfo(Path.Combine(LoadDirectory.ForLoading.FullName, Path.GetFileName(filename))); var demog = new Demography(r); var people = new PersonCollection(); people.GeneratePeople(500, r); demog.GenerateTestDataFile(people, fi, rows); return(fi); }