private static void TestCsvFormatters() { var action = new Action(() => { var test01FilePath = SwanRuntime.GetDesktopFilePath("csv-writer-test-01.csv"); var test02FilePath = SwanRuntime.GetDesktopFilePath("csv-writer-test-02.csv"); var generatedRecords = SampleCsvRecord.CreateSampleSet(100); $"Generated {generatedRecords.Count} sample records.".Info(nameof(TestCsvFormatters)); var savedRecordCount = CsvWriter.SaveRecords(generatedRecords, test01FilePath); $"Saved {savedRecordCount} records (including header) to file: {Path.GetFileName(test01FilePath)}." .Info(nameof(TestCsvFormatters)); var loadedRecords = CsvReader.LoadRecords <SampleCsvRecord>(test01FilePath); $"Loaded {loadedRecords.Count} records from file: {Path.GetFileName(test01FilePath)}.".Info( nameof(TestCsvFormatters)); savedRecordCount = CsvWriter.SaveRecords(generatedRecords, test02FilePath); $"Saved {savedRecordCount} records (including header) to file: {Path.GetFileName(test02FilePath)}." .Info(nameof(TestCsvFormatters)); var sourceObject = loadedRecords[generatedRecords.Count / 2]; var targetObject = new SampleCopyTarget(); var copiedProperties = sourceObject.CopyPropertiesTo(targetObject); $"{nameof(Extensions.CopyPropertiesTo)} method copied {copiedProperties} properties from one object to another" .Info(nameof(TestCsvFormatters)); }); var elapsed = Benchmark.BenchmarkAction(action); $"Elapsed: {Math.Round(elapsed.TotalMilliseconds, 3)} milliseconds".Trace(); }
public void WithEmptyAction_ReturnsTimeSpan() { var action = new Action(() => { }); var result = Benchmark.BenchmarkAction(action); Assert.IsNotNull(result); }
public void WithAction_ReturnsTimeSpan() { const int total = 0; var action = new Action(() => { if (total < 2) { throw new Exception(); } }); var result = Benchmark.BenchmarkAction(action); Assert.IsNotNull(result); }
public void WithNullAction_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => Benchmark.BenchmarkAction(NullAction)); }