private static async Task CreateDatabase(string connectionString, CancellationToken ct) { // There is a while true loop here, because sometimes after creating the db, the db is not available always. // There are much better ways of handling this, but I couldn't be bothered right now;) while (true) { try { await Task.Delay(1000); Console.WriteLine("Creating database schema"); await Task.Delay(3000); var mgr = new DatabaseManager(connectionString); mgr.EnsureDatabaseExists(10, 10); await Task.Delay(2000, ct); var msSqlStreamStoreSettings = new MsSqlStreamStoreSettings(connectionString); var store = new MsSqlStreamStore(msSqlStreamStoreSettings); if (!(await store.CheckSchema(ct)).IsMatch()) { await store.CreateSchema(ct); } var repo = new StreamStoreConfigRepository(store); Console.WriteLine("Now generating 20 changes:"); for (int i = 0; i < 20; i++) { await Task.Delay(1000, ct); await repo.Modify(ct, ("setting1", "new value, written at: " + DateTime.Now.ToLongTimeString())); } // Delay for a while, so the latest version can be printed. await Task.Delay(1000, ct); var history = await repo.GetSettingsHistory(ct); Console.WriteLine($"There have historically been:{history.Count} versions: "); foreach (var setting in history) { Console.WriteLine($"\t- Version: {setting.Version}, setting1 = '{setting["setting1"]}', ModifiedKeys: [{string.Join(',', setting.ModifiedKeys)}]"); } Console.WriteLine($"Now reverting back to the first version's data: {history.First().Version}"); // Now revert back to the first version (this actually creates a new version, with the old data in it) await repo.RevertToVersion(history.First(), ct); // Completed succesfully. End the function return; } catch (Exception ex) { Console.WriteLine("error while creating database: " + ex.Message + " (will retry)"); } } }
public ConfigRepositoryTests() { _streamStoreConfigRepository = new StreamStoreConfigRepository(new InMemoryStreamStore(), messageHooks: new Base64Hook()); }