-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
78 lines (74 loc) · 2.97 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Running;
using DapperEFCorePostgreSQL.Context;
using DapperEFCorePostgreSQL.Entities;
using Microsoft.EntityFrameworkCore;
namespace DapperEFCorePostgreSQL
{
internal class Program
{
private static void Main()
{
Console.Clear();
Console.WriteLine("Operations Menu");
Console.WriteLine("---------------");
Console.WriteLine("1 > Generate test data (Categories: 100)");
Console.WriteLine("2 > Generate test data (Categories: 1.000)");
Console.WriteLine("3 > Generate test data (Categories: 10.000)");
Console.WriteLine("0 > Run tests");
Console.Write("Choice: ");
var input = Console.ReadLine();
switch (input)
{
case "1": GenerateTestData(100); break;
case "2": GenerateTestData(1000); break;
case "3": GenerateTestData(10000); break;
case "0": RunTests(); break;
default: Console.WriteLine("Aborting..."); break;
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
static void GenerateTestData(int categoriesCount)
{
Console.WriteLine("Database is migrating...");
using var sampleDbContext = new SampleDbContext();
sampleDbContext.Database.Migrate();
sampleDbContext.SaveChanges();
Console.WriteLine("Sample data is generating...");
sampleDbContext.Products.RemoveRange(sampleDbContext.Products);
var random = new Random();
var productsCount = 0;
for (var i = 1; i <= categoriesCount; i++)
{
var products = new List<Product>();
for (var j = 1; j <= random.Next(100); j++)
{
productsCount++;
products.Add(new Product
{
Name = $"Product Name {productsCount:000000}",
Description = $"Product Description {productsCount:000000}",
Content = $"Product Content {productsCount:000000}",
});
}
sampleDbContext.Categories.Add(new Category { CategoryName = $"Category {i:000000}", Products = products });
}
sampleDbContext.SaveChanges();
Console.WriteLine($"{categoriesCount} categories generated.");
Console.WriteLine($"{productsCount} products generated.");
Console.WriteLine("Sample data generation completed.");
}
static void RunTests()
{
if (System.Diagnostics.Debugger.IsAttached)
{
var testing = new PerformanceTesting();
testing.Dapper_AutoMapper4();
return;
}
BenchmarkRunner.Run<PerformanceTesting>();
}
}
}