public LGAccountFaker(IManageDatabase databaseManager, ILogger logger) { var random = new Random(); int randomNumber = random.Next(); Bogus.Randomizer.Seed = new Random(randomNumber); var roleFaker = new LGRoleFaker(databaseManager, logger); var roleFake = roleFaker.GetOne(); var roleRepository = new LGRoleRepository(databaseManager, new LGRoleRepositorySql(), logger); var roleFakeResult = roleRepository.Create(roleFake); roleFake = roleFakeResult.Model; _faker = new Bogus.Faker <LGAccount>() .StrictMode(false) .Rules((f, m) => { m.LGAccountId = null; m.LastName = f.Name.LastName(0); m.FirstName = f.Name.FirstName(0); m.MiddleName = f.Name.FirstName(0); m.UserName = f.Internet.UserName(m.FirstName, m.LastName); m.Email = f.Internet.Email(m.FirstName, m.LastName); m.Password = f.Lorem.Sentence(10); m.RoleIdRef = roleFake.LGRoleId; }); }
public void CreateUpdateDeleteFetch() { // file system var path = "/shop/randomsilo/modern-web/backends/LoyalGuard"; var project = "LoyalGuard"; var outputPath = $"{path}/{project}.Infrastructure.Test/TestOutput/"; var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod()); // logger ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log"); // database setup // - context IDatabaseContext databaseContext = new DatabaseContext( $"Data Source={databaseFile}" , "TestDb" , "TestSchema" , $"{path}/sql/sqlite/ALL.sql" ); Assert.NotNull(databaseContext); // - manager IManageDatabase databaseManager = new DatabaseManager(databaseContext); Assert.NotNull(databaseManager); // - create tables databaseManager.CreateDatabase(); // - repository var lGRoleRepository = new LGRoleRepository(databaseManager, new LGRoleRepositorySql(), logger); Assert.NotNull(lGRoleRepository); // faker BrashActionResult <LGRole> result = null; var lGRoleFaker = new LGRoleFaker(databaseManager, logger); Assert.NotNull(lGRoleFaker); // create var lGRoleCreateModel = lGRoleFaker.GetOne(); result = lGRoleRepository.Create(lGRoleCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGRoleId > 0); // use model with id lGRoleCreateModel = result.Model; // update var lGRoleUpdateModel = lGRoleFaker.GetOne(); lGRoleUpdateModel.LGRoleId = lGRoleCreateModel.LGRoleId; result = lGRoleRepository.Update(lGRoleUpdateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // delete result = lGRoleRepository.Delete(lGRoleCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // fetch // - make fakes var fakes = lGRoleFaker.GetMany(10); // - add fakes to database List <int?> ids = new List <int?>(); foreach (var f in fakes) { result = lGRoleRepository.Create(f); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGRoleId >= 0); ids.Add(result.Model.LGRoleId); } // - get fakes from database foreach (var id in ids) { var model = new LGRole() { LGRoleId = id }; result = lGRoleRepository.Fetch(model); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGRoleId >= 0); } }