public void TearDown() { Utils.CleanUp(true); List <Country> countries = GeopoliticalLocation.Parse(File.ReadAllText(Utilities.Utilities.SolutionLocation + "\\QWest.DataAccess\\res\\geopolitical_location_backup.json")); DAO.Geography.InsertBackup(countries).Wait(); }
public async Task BackUpsCorrectly() { await ConnectionWrapper.Instance.Use("DELETE FROM geopolitical_location", stmt => stmt.ExecuteNonQueryAsync()); List <Country> countries = GeopoliticalLocation.Parse(File.ReadAllText(Utilities.Utilities.SolutionLocation + "\\QWest.DataAccess\\res\\geopolitical_location_backup.json")); await DAO.Geography.InsertBackup(countries); int amount = (await DAO.Geography.FetchEverythingParsed()).Count(); Assert.AreEqual(countries.Count, amount); }
private async Task ApplyMigration(SqlConnection conn) { SqlCommand stmt = conn.CreateCommand(); stmt.CommandText = "select schema_version from info"; int schemaVersion = 0; try { schemaVersion = (await stmt.ExecuteReaderAsync()).ToIterator(x => x.GetSqlInt32(0).Value).FirstOrDefault(); } catch (Exception) { stmt = conn.CreateCommand(); stmt.CommandText = "CREATE TABLE info (schema_version INT NOT NULL)"; await stmt.ExecuteNonQueryAsync(); } foreach ((int numeric, string text) in GetScripts().Where(x => x.numeric > schemaVersion)) { stmt = conn.CreateCommand(); stmt.CommandText = text; Console.WriteLine("migrating: " + numeric); await stmt.ExecuteNonQueryAsync(); schemaVersion = numeric; } stmt = conn.CreateCommand(); stmt.CommandText = "delete from info; insert into info (schema_version) values (@schema_version)"; stmt.Parameters.AddWithValue("@schema_version", schemaVersion); await stmt.ExecuteNonQueryAsync(); stmt = conn.CreateCommand(); stmt.CommandText = "SELECT COUNT(*) FROM geopolitical_location"; bool applyGeopoliticalLocationBackup = false; try { applyGeopoliticalLocationBackup = (await stmt.ExecuteReaderAsync()).ToIterator(reader => reader.GetSqlInt32(0).Value == 0).First(); } catch (Exception) { } if (applyGeopoliticalLocationBackup) { List <Country> countries = GeopoliticalLocation.Parse(File.ReadAllText(Utilities.Utilities.SolutionLocation + "\\QWest.DataAccess\\res\\geopolitical_location_backup.json")); await new Mssql.GeographyImpl(null).InsertBackup(countries, conn); } }