public LGPrivilegeFaker(IManageDatabase databaseManager, ILogger logger) { var random = new Random(); int randomNumber = random.Next(); Bogus.Randomizer.Seed = new Random(randomNumber); var parentFaker = new LGAccountFaker(databaseManager, logger); var parent = parentFaker.GetOne(); var parentRepository = new LGAccountRepository(databaseManager, new LGAccountRepositorySql(), logger); var parentAddResult = parentRepository.Create(parent); parent = parentAddResult.Model; var featureFaker = new LGFeatureFaker(databaseManager, logger); var featureFake = featureFaker.GetOne(); var featureRepository = new LGFeatureRepository(databaseManager, new LGFeatureRepositorySql(), logger); var featureFakeResult = featureRepository.Create(featureFake); featureFake = featureFakeResult.Model; var abilityFaker = new LGAbilityFaker(databaseManager, logger); var abilityFake = abilityFaker.GetOne(); var abilityRepository = new LGAbilityRepository(databaseManager, new LGAbilityRepositorySql(), logger); var abilityFakeResult = abilityRepository.Create(abilityFake); abilityFake = abilityFakeResult.Model; _faker = new Bogus.Faker <LGPrivilege>() .StrictMode(false) .Rules((f, m) => { m.LGPrivilegeId = null; m.LGAccountId = parent.LGAccountId; m.Starts = f.Date.Past(); m.Ends = f.Date.Past(); m.FeatureIdRef = featureFake.LGFeatureId; m.AbilityIdRef = abilityFake.LGAbilityId; }); }
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 lGFeatureRepository = new LGFeatureRepository(databaseManager, new LGFeatureRepositorySql(), logger); Assert.NotNull(lGFeatureRepository); // faker BrashActionResult <LGFeature> result = null; var lGFeatureFaker = new LGFeatureFaker(databaseManager, logger); Assert.NotNull(lGFeatureFaker); // create var lGFeatureCreateModel = lGFeatureFaker.GetOne(); result = lGFeatureRepository.Create(lGFeatureCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGFeatureId > 0); // use model with id lGFeatureCreateModel = result.Model; // update var lGFeatureUpdateModel = lGFeatureFaker.GetOne(); lGFeatureUpdateModel.LGFeatureId = lGFeatureCreateModel.LGFeatureId; result = lGFeatureRepository.Update(lGFeatureUpdateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // delete result = lGFeatureRepository.Delete(lGFeatureCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // fetch // - make fakes var fakes = lGFeatureFaker.GetMany(10); // - add fakes to database List <int?> ids = new List <int?>(); foreach (var f in fakes) { result = lGFeatureRepository.Create(f); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGFeatureId >= 0); ids.Add(result.Model.LGFeatureId); } // - get fakes from database foreach (var id in ids) { var model = new LGFeature() { LGFeatureId = id }; result = lGFeatureRepository.Fetch(model); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.LGFeatureId >= 0); } }