This commit is contained in:
2018-09-26 22:46:22 +00:00
parent 07e1f8b94a
commit 8543ef947b

View File

@@ -46,19 +46,20 @@ namespace AyaNova.Util
DbUtil.PrepareDatabaseForSeeding(log);
//Seed special test data for integration testing
SeedKnownUsers();
log.LogInformation("Seeding known users");
SeedKnownUsers(log);
log.LogInformation("Seeding all other data");
switch (slevel)
{
//This is for a busy but one man shop with a single office person handling stuff back at the shop
case SeedLevel.SmallOneManShopTrialDataSet:
//Generate owner and lead tech
GenSeedUser(1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Schedulable);
GenSeedUser(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Schedulable);
//Generate one office person / secretary
GenSeedUser(1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NonSchedulable);
//200 widgets
GenSeedWidget(200);
@@ -69,37 +70,37 @@ namespace AyaNova.Util
case SeedLevel.MediumLocalServiceCompanyTrialDataSet:
//One IT administrator, can change ops but nothing else
GenSeedUser(1, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable);
//One business administrator, can view ops issues
GenSeedUser(1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
//One owner who doesn't control anything but views stuff
GenSeedUser(1, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
//20 techs
GenSeedUser(20, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
GenSeedUser(log, 20, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
//2 subcontractors
GenSeedUser(2, AuthorizationRoles.SubContractorFull, UserType.Subcontractor);
GenSeedUser(log, 2, AuthorizationRoles.SubContractorFull, UserType.Subcontractor);
//3 sales / generic office people people
GenSeedUser(3, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
GenSeedUser(log, 3, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
//1 dispatch manager
GenSeedUser(1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
//1 Inventory manager
GenSeedUser(1, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NonSchedulable);
//1 accountant / bookkeeper
GenSeedUser(1, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 1, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable);
//10 full on client users
GenSeedUser(10, AuthorizationRoles.ClientLimited, UserType.Client);
GenSeedUser(log, 10, AuthorizationRoles.ClientLimited, UserType.Client);
//10 limited client users
GenSeedUser(10, AuthorizationRoles.ClientLimited, UserType.Client);
GenSeedUser(log, 10, AuthorizationRoles.ClientLimited, UserType.Client);
//2000 widgets
GenSeedWidget(2000);
@@ -109,46 +110,46 @@ namespace AyaNova.Util
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location
case SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
//IT administrator, can change ops but nothing else
GenSeedUser(2, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable);
GenSeedUser(log, 2, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable);
//business administrator, can view ops issues
GenSeedUser(2, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 2, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
//owner / upper management who doesn't control anything but views stuff
GenSeedUser(5, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 5, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
//techs
GenSeedUser(100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
GenSeedUser(log, 100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
//limited techs
GenSeedUser(50, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
GenSeedUser(log, 50, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
//20 subcontractors
GenSeedUser(20, AuthorizationRoles.SubContractorFull, UserType.Subcontractor);
GenSeedUser(log, 20, AuthorizationRoles.SubContractorFull, UserType.Subcontractor);
//10 limited subcontractors
GenSeedUser(10, AuthorizationRoles.SubContractorLimited, UserType.Subcontractor);
GenSeedUser(log, 10, AuthorizationRoles.SubContractorLimited, UserType.Subcontractor);
//30 sales / generic office people people
GenSeedUser(30, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
GenSeedUser(log, 30, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
//5 dispatch manager
GenSeedUser(5, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
GenSeedUser(log, 5, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
//5 Inventory manager
GenSeedUser(5, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NonSchedulable);
GenSeedUser(log, 5, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited, UserType.NonSchedulable);
//10 Inventory manager assistants
GenSeedUser(5, AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
GenSeedUser(log, 5, AuthorizationRoles.InventoryLimited, UserType.NonSchedulable);
//5 accountant / bookkeeper
GenSeedUser(5, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable);
GenSeedUser(log, 5, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable);
//100 full on client users
GenSeedUser(100, AuthorizationRoles.ClientFull, UserType.Client);
GenSeedUser(log, 100, AuthorizationRoles.ClientFull, UserType.Client);
//100 limited client users
GenSeedUser(100, AuthorizationRoles.ClientLimited, UserType.Client);
GenSeedUser(log, 100, AuthorizationRoles.ClientLimited, UserType.Client);
//20000 widgets
GenSeedWidget(20000);
@@ -158,9 +159,10 @@ namespace AyaNova.Util
log.LogInformation("Seeding completed successfully");
}
catch
catch (Exception ex)
{
throw;
log.LogError(ex, "Seeder:SeedDatabase error during ops");
throw ex;
}
finally
{
@@ -175,53 +177,69 @@ namespace AyaNova.Util
//////////////////////////////////////////////////////
//Seed test data for integration tests
//
public static void SeedKnownUsers()
public static void SeedKnownUsers(ILogger log)
{
try
{
//TEST USERS
//one of each role type
GenSeedUser(1, AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable, "BizAdminLimited", "BizAdminLimited");
GenSeedUser(1, AuthorizationRoles.BizAdminFull, UserType.NonSchedulable, "BizAdminFull", "BizAdminFull");
GenSeedUser(1, AuthorizationRoles.DispatchLimited, UserType.NonSchedulable, "DispatchLimited", "DispatchLimited");
GenSeedUser(1, AuthorizationRoles.DispatchFull, UserType.NonSchedulable, "DispatchFull", "DispatchFull");
GenSeedUser(1, AuthorizationRoles.InventoryLimited, UserType.NonSchedulable, "InventoryLimited", "InventoryLimited");
GenSeedUser(1, AuthorizationRoles.InventoryFull, UserType.NonSchedulable, "InventoryFull", "InventoryFull");
GenSeedUser(1, AuthorizationRoles.AccountingFull, UserType.NonSchedulable, "Accounting", "Accounting");
GenSeedUser(1, AuthorizationRoles.TechLimited, UserType.Schedulable, "TechLimited", "TechLimited");
GenSeedUser(1, AuthorizationRoles.TechFull, UserType.Schedulable, "TechFull", "TechFull");
GenSeedUser(1, AuthorizationRoles.SubContractorLimited, UserType.Subcontractor, "SubContractorLimited", "SubContractorLimited");
GenSeedUser(1, AuthorizationRoles.SubContractorFull, UserType.Subcontractor, "SubContractorFull", "SubContractorFull");
GenSeedUser(1, AuthorizationRoles.ClientLimited, UserType.Client, "ClientLimited", "ClientLimited");
GenSeedUser(1, AuthorizationRoles.ClientFull, UserType.Client, "ClientFull", "ClientFull");
GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "OpsAdminLimited", "OpsAdminLimited");
GenSeedUser(1, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable, "OpsAdminFull", "OpsAdminFull");
//TEST USERS
//one of each role type
GenSeedUser(log, 1, AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable, "BizAdminLimited", "BizAdminLimited");
GenSeedUser(log, 1, AuthorizationRoles.BizAdminFull, UserType.NonSchedulable, "BizAdminFull", "BizAdminFull");
GenSeedUser(log, 1, AuthorizationRoles.DispatchLimited, UserType.NonSchedulable, "DispatchLimited", "DispatchLimited");
GenSeedUser(log, 1, AuthorizationRoles.DispatchFull, UserType.NonSchedulable, "DispatchFull", "DispatchFull");
GenSeedUser(log, 1, AuthorizationRoles.InventoryLimited, UserType.NonSchedulable, "InventoryLimited", "InventoryLimited");
GenSeedUser(log, 1, AuthorizationRoles.InventoryFull, UserType.NonSchedulable, "InventoryFull", "InventoryFull");
GenSeedUser(log, 1, AuthorizationRoles.AccountingFull, UserType.NonSchedulable, "Accounting", "Accounting");
GenSeedUser(log, 1, AuthorizationRoles.TechLimited, UserType.Schedulable, "TechLimited", "TechLimited");
GenSeedUser(log, 1, AuthorizationRoles.TechFull, UserType.Schedulable, "TechFull", "TechFull");
//PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs
GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT");
GenSeedUser(log, 1, AuthorizationRoles.SubContractorLimited, UserType.Subcontractor, "SubContractorLimited", "SubContractorLimited");
GenSeedUser(log, 1, AuthorizationRoles.SubContractorFull, UserType.Subcontractor, "SubContractorFull", "SubContractorFull");
GenSeedUser(log, 1, AuthorizationRoles.ClientLimited, UserType.Client, "ClientLimited", "ClientLimited");
GenSeedUser(log, 1, AuthorizationRoles.ClientFull, UserType.Client, "ClientFull", "ClientFull");
//TEST NOT ACTIVE - this is used for a test to see if inactive user can login
GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, false, "TEST_INACTIVE", "TEST_INACTIVE");
GenSeedUser(log, 1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "OpsAdminLimited", "OpsAdminLimited");
GenSeedUser(log, 1, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable, "OpsAdminFull", "OpsAdminFull");
//PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs
GenSeedUser(log, 1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT");
//TEST NOT ACTIVE - this is used for a test to see if inactive user can login
GenSeedUser(log, 1, AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable, false, "TEST_INACTIVE", "TEST_INACTIVE");
}
catch
{
throw;
}
}
/// <summary>
/// Generate seed user with active=true
/// (override to save typing)
/// (override to save typing)
/// </summary>
/// <param name="log"></param>
/// <param name="count"></param>
/// <param name="roles"></param>
/// <param name="userType"></param>
/// <param name="login"></param>
/// <param name="password"></param>
public static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, string login, string password)
public static void GenSeedUser(ILogger log, int count, AuthorizationRoles roles, UserType userType, string login, string password)
{
GenSeedUser(count, roles, userType, true, login, password);
try
{
GenSeedUser(log, count, roles, userType, true, login, password);
}
catch
{
throw;
}
}
public async static void GenSeedUser(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
public async static void GenSeedUser(ILogger log, int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
{
UserBiz Biz = UserBiz.GetBizInternal(ServiceProviderProvider.DBContext);
// Biz.CreateAsync()
@@ -255,7 +273,12 @@ namespace AyaNova.Util
u.UserOptions = new UserOptions(1);
u.UserOptions.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com");
await Biz.CreateAsync(u);
var TheUser = await Biz.CreateAsync(u);
if (TheUser == null)
{
log.LogError($"Seeder::GenSeedUser error creating user {u.Name}\r\n" + Biz.GetErrorsAsString());
throw new System.Exception("Seeder::GenSeedUser error creating user\r\n" + Biz.GetErrorsAsString());
}
}
}