This commit is contained in:
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Biz;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Bogus;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using System.Diagnostics;
|
||||
@@ -13,42 +12,47 @@ using System.Diagnostics;
|
||||
namespace AyaNova.Util
|
||||
{
|
||||
|
||||
public static class Seeder
|
||||
public class Seeder
|
||||
{
|
||||
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
public static int SeededUserCount = 0;
|
||||
|
||||
public static SeedLevel StringToSeedLevel(string size)
|
||||
public static class Level
|
||||
{
|
||||
switch (size.ToLowerInvariant())
|
||||
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
public static SeedLevel StringToSeedLevel(string size)
|
||||
{
|
||||
case "small":
|
||||
return SeedLevel.SmallOneManShopTrialDataSet;
|
||||
switch (size.ToLowerInvariant())
|
||||
{
|
||||
case "small":
|
||||
return SeedLevel.SmallOneManShopTrialDataSet;
|
||||
|
||||
case "medium":
|
||||
return SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
||||
case "medium":
|
||||
return SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
||||
|
||||
case "large":
|
||||
return SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
||||
case "large":
|
||||
return SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
||||
|
||||
case "huge":
|
||||
return SeedLevel.HugeForLoadTest;
|
||||
case "huge":
|
||||
return SeedLevel.HugeForLoadTest;
|
||||
|
||||
default:
|
||||
return SeedLevel.NotValid;
|
||||
default:
|
||||
return SeedLevel.NotValid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SeededUserCount = 0;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed database for trial and testing purposes
|
||||
//
|
||||
|
||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Decimal timeZoneOffset)
|
||||
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Decimal timeZoneOffset)
|
||||
{
|
||||
await SeedDatabaseAsync(slevel, Guid.Empty, timeZoneOffset);
|
||||
}
|
||||
|
||||
public static async Task SeedDatabaseAsync(SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||
{
|
||||
bool LogJob = JobId != Guid.Empty;
|
||||
SeededUserCount = 0;
|
||||
@@ -182,7 +186,7 @@ namespace AyaNova.Util
|
||||
//log.LogInformation("Seeding all other data");
|
||||
switch (slevel)
|
||||
{
|
||||
case SeedLevel.SmallOneManShopTrialDataSet:
|
||||
case Level.SeedLevel.SmallOneManShopTrialDataSet:
|
||||
{
|
||||
#region GenSmall
|
||||
//This is for a busy but one man shop with a single office person handling stuff back at the shop
|
||||
@@ -211,7 +215,7 @@ namespace AyaNova.Util
|
||||
#endregion gensmall
|
||||
}
|
||||
break;
|
||||
case SeedLevel.MediumLocalServiceCompanyTrialDataSet:
|
||||
case Level.SeedLevel.MediumLocalServiceCompanyTrialDataSet:
|
||||
{
|
||||
#region GenMedium
|
||||
//This is for a typical AyaNova medium busy shop
|
||||
@@ -273,7 +277,7 @@ namespace AyaNova.Util
|
||||
#endregion genmedium
|
||||
}
|
||||
break;
|
||||
case SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
|
||||
case Level.SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
|
||||
{
|
||||
#region GenLarge
|
||||
//this is a large corporation with multiple branches in multiple locations all in the same country
|
||||
@@ -350,7 +354,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
break;
|
||||
|
||||
case SeedLevel.HugeForLoadTest:
|
||||
case Level.SeedLevel.HugeForLoadTest:
|
||||
{
|
||||
#region GenHuge
|
||||
//this is the HUGE dataset for load and other testing
|
||||
@@ -446,7 +450,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
//Log the status and also job if it's run via job
|
||||
private static async Task LogStatusAsync(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||
private async Task LogStatusAsync(Guid JobId, bool LogJob, ILogger log, string msg)
|
||||
{
|
||||
log.LogInformation(msg);
|
||||
if (LogJob)
|
||||
@@ -454,16 +458,16 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
|
||||
public static long RUNNING_COUNT = 0;
|
||||
public static string Uniquify(string s)
|
||||
public long RUNNING_COUNT = 0;
|
||||
public string Uniquify(string s)
|
||||
{
|
||||
return s + " " + (++RUNNING_COUNT).ToString();
|
||||
}
|
||||
|
||||
|
||||
private static string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
||||
private string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
||||
|
||||
private static List<string> RandomTags(Faker f)
|
||||
private List<string> RandomTags(Faker f)
|
||||
{
|
||||
|
||||
var t = f.PickRandom(TagSet, f.Random.Int(1, 5));//pick up to 5 tags to apply
|
||||
@@ -473,7 +477,7 @@ namespace AyaNova.Util
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed test data for integration tests
|
||||
//
|
||||
public static async Task SeedKnownUsersAsync(ILogger log)
|
||||
public async Task SeedKnownUsersAsync(ILogger log)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -528,7 +532,7 @@ namespace AyaNova.Util
|
||||
/// Generate seed user with active=true
|
||||
/// (override to save typing)
|
||||
/// </summary>
|
||||
public static async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType, string login, string password, List<string> tags = null)
|
||||
public async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType, string login, string password, List<string> tags = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -542,7 +546,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
|
||||
public static async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||
public async Task GenSeedUserAsync(ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||
bool active = true, string login = null, string password = null, long translationId = 0, List<string> tags = null)
|
||||
{
|
||||
if (translationId == 0)
|
||||
@@ -733,7 +737,7 @@ namespace AyaNova.Util
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed widget for testing
|
||||
//
|
||||
public static async Task GenSeedWidgetAsync(ILogger log, int count)
|
||||
public async Task GenSeedWidgetAsync(ILogger log, int count)
|
||||
{
|
||||
//this is 4 times slower than doing it inside the loop below
|
||||
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
||||
|
||||
Reference in New Issue
Block a user