/// <summary> /// Ensures the app is initialized with the appropriate set of data. If we're /// already initialized that way we don't re-initialize. /// </summary> private void Init(DbState requiredState) { if (_dbstate != requiredState) { Version.AssertInstalled(); switch (requiredState) { case DbState.OarApp: using (var output = ProcessOutput.Run(Version.InterpreterPath, new [] {"manage.py", "syncdb", "--noinput"}, DebuggerTestPath, null, false, null)) { output.Wait(); Console.WriteLine(" ** stdout **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardOutputLines)); Console.WriteLine(" ** stderr **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardErrorLines)); Assert.AreEqual(0, output.ExitCode); } using (var output = ProcessOutput.Run(Version.InterpreterPath, new [] {"manage.py", "loaddata", "data.json"}, DebuggerTestPath, null, false, null)) { output.Wait(); Console.WriteLine(" ** stdout **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardOutputLines)); Console.WriteLine(" ** stderr **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardErrorLines)); Assert.AreEqual(0, output.ExitCode); } break; } _dbstate = requiredState; } }
/// <summary> /// Создать Состояние секции бд. /// </summary> /// <param name="dbState">Состояние бд.</param> /// <param name="canResolve">Можно ли разрешить конфликт бд. </param> /// <remarks>Используется, если состояние секции бд не важно.</remarks> public DbSectionState(DbState dbState, bool canResolve = false) : this() { DbState = dbState; CanResolve = canResolve; DbSectionStatus = DbSectionStatus.Unknown; }
private static DbState AndTheDbHasAtLeast2NonEmptyTablesWithDifferentNumberOfRowsAndFirstTableShouldntHaveTheHighestRowCount(IDataBase db) { var state = new DbState(db); int? firstNonEmptyNumberOfRows = null; foreach (var rowCount in state.Values) { if (rowCount == 0) { continue; } if (firstNonEmptyNumberOfRows == null) { firstNonEmptyNumberOfRows = rowCount; } else { if (firstNonEmptyNumberOfRows.Value < rowCount) { return state; } } } Assert.Fail("Test setup is wrong: should have at least 2 tables with different rowcount and bigger than zero, and the first table shouldn't be the one with the highest rowcount..."); return null; }
public static DbState GetTestDbRandomState(int n) { var dbEntryList = GetTestDbEntryRandomList(n, 2 * n); var dbState = new DbState(GetTestDbView(), dbEntryList); return(dbState); }
/// <summary> /// Создать Состояние секции бд. /// </summary> /// <param name="dbState">Состояние бд. </param> /// <param name="dbSectionStatus">Статус секции бд.</param> /// <param name="message">Сообщение.</param> /// <param name="canResolve">Можно ли разрешить конфликт бд.</param> /// <param name="sectionVersion">Версия секции.</param> public DbSectionState(DbState dbState, DbSectionStatus dbSectionStatus, ScoutVersion? sectionVersion = null, bool canResolve = false, string message = null) : this() { DbState = dbState; DbSectionStatus = dbSectionStatus; Message = message; CanResolve = canResolve; SectionVersion = sectionVersion; }
public IActionResult CheckDatabase() { if (DbState.IsDatabaseAvailable()) { ViewBag.State = "Available"; return(View()); } else { ViewBag.State = "Not available"; return(View()); } }
protected static EntityState ConvertEntityState(DbState state) { switch (state) { case DbState.Added: return EntityState.Added; case DbState.Modified: return EntityState.Modified; case DbState.Deleted: return EntityState.Deleted; default: return EntityState.Unchanged; } }
static protected EntityState ConvertEntityState(DbState state) { switch (state) { case DbState.Added: return(EntityState.Added); case DbState.Modified: return(EntityState.Modified); case DbState.Deleted: return(EntityState.Deleted); default: return(EntityState.Unchanged); } }
private void ThenTheTableSelectedIsTheOneWithTheHighestNumberOfRows(Table table, DbState dbState) { KeyValuePair<string, int>? highest = null; foreach (var tableToRowCount in dbState) { if (highest == null) { highest = tableToRowCount; continue; } if (tableToRowCount.Value > highest.Value.Value) { highest = tableToRowCount; } } Assert.That(highest, Is.Not.Null); Assert.That(highest.Value.Key, Is.EqualTo(table.Name)); }
public Table ChooseTableToBisect(IDataBase db) { var state = new DbState(db); var candidateTables = new HashSet<string>(state.Keys); foreach (Table table in db.Tables) { foreach (ForeignKey fk in table.ForeignKeys) { candidateTables.Remove(fk.ReferencedTable); } if (IsBackUpTable(table.Name) || state.Keys.Contains(GetBackupTableName(table.Name))) { candidateTables.Remove(table.Name); } } KeyValuePair<string, int>? highest = null; foreach (var table in candidateTables) { var rowCount = state[table]; if (state[table] > 0) { if (highest == null || highest.Value.Value < rowCount) { highest = new KeyValuePair<string, int>(table, rowCount); } } } if (highest == null) return null; return db.Tables[highest.Value.Key]; }
/// <summary> /// Ensures the app is initialized with the appropriate set of data. If we're /// already initialized that way we don't re-initialize. /// </summary> private void Init(DbState requiredState) { if (_dbstate != requiredState) { Version.AssertInstalled(); switch (requiredState) { case DbState.OarApp: using (var output = ProcessOutput.Run(Version.InterpreterPath, new [] { "manage.py", "syncdb", "--noinput" }, DebuggerTestPath, null, false, null)) { output.Wait(); Console.WriteLine(" ** stdout **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardOutputLines)); Console.WriteLine(" ** stderr **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardErrorLines)); Assert.AreEqual(0, output.ExitCode); } using (var output = ProcessOutput.Run(Version.InterpreterPath, new [] { "manage.py", "loaddata", "data.json" }, DebuggerTestPath, null, false, null)) { output.Wait(); Console.WriteLine(" ** stdout **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardOutputLines)); Console.WriteLine(" ** stderr **"); Console.WriteLine(string.Join(Environment.NewLine, output.StandardErrorLines)); Assert.AreEqual(0, output.ExitCode); } break; } _dbstate = requiredState; } }
public static IDb Create() { var validator = new DocumentValidator(); var commands = new List <ICommand> { new InsertCommand(new InsertCommandParser(validator)), new ReplaceCommand(new ReplaceCommandParser(validator)), new FindCommand(new IFindCommandExecutor[] { new FindByIdCommandExecutor(), new FindByFieldCommandExecutor() }), new DeleteCommand(), //new BackupCommand(), //new RestoreCommand(new RestoreCommandParser(validator)), //new UpdateCommand(), new AddIndexCommand(), new DropIndexCommand() }; var parser = new DbCommandParser(); var state = new DbState(); return(new Db(state, parser, commands)); }
private static bool GetCanResolve(DbState dbState) { return dbState.Status == DbStatus.NotExists || dbState.Status == DbStatus.Outdated || dbState.Status == DbStatus.NoSchema; }
private DbSectionState GetNotExistDbSectionState(DbState dbState, ScoutVersion? requiredVersion) { return new DbSectionState(dbState, DbSectionStatus.NotExists, requiredVersion, true); }
private DbSectionState GetSectionState(DbState dbState, ScoutVersion? currentSectionVersion, ScoutVersion? requiredVersion) { if (dbState.Status == DbStatus.Unknown) return GetDefaultDbSectionState(); if (currentSectionVersion == null && requiredVersion != null) { return GetNotExistDbSectionState(dbState, requiredVersion); } if (currentSectionVersion == null || requiredVersion == null) { return new DbSectionState(dbState, DbSectionStatus.Error, currentSectionVersion, message: "Не удалось определить версию секции бд."); } try { if (currentSectionVersion.Value < requiredVersion.Value) { return new DbSectionState(dbState, DbSectionStatus.Outdated, currentSectionVersion, true, "Версия секции базы данных ниже требуемой."); } if (currentSectionVersion.Value > requiredVersion.Value) { return new DbSectionState(dbState, DbSectionStatus.Newer, currentSectionVersion, message: "Версия секции базы данных не совместима для работы расширения."); } return new DbSectionState(dbState, DbSectionStatus.Ok, currentSectionVersion, message: "Версия секции базы данных корректна"); } catch (Exception) { return new DbSectionState(dbState, DbSectionStatus.Error, currentSectionVersion, message: "Не удалось определить версию секции бд."); } }
public IDictionary<Guid, DbSectionState> GetSectionsState(DbState currentDbState, IList<DbSectionInfo> registeredSections) { var sectionsVersions = GetSectionsVersions(); var result = new Dictionary<Guid, DbSectionState>(); foreach (var registeredSection in registeredSections) { ScoutVersion? currentSectionVersion = null; ScoutVersion currentVersion; if (sectionsVersions.TryGetValue(registeredSection.DbSectionId, out currentVersion)) currentSectionVersion = currentVersion; var requiredVersion = registeredSection.RequiredVersion; var sectionState = GetSectionState(currentDbState, currentSectionVersion, requiredVersion); result[registeredSection.DbSectionId] = sectionState; } return result; }
private void ThenTheTableSelectedIsNotAnEmptyOne(Table table, DbState state) { Assert.That(state[table.Name], Is.GreaterThan(0)); }
void IDbState.DeleteFromDb() { _dbState = DbState.Deleted; }
void IDbState.ChangeDbState(DbState state) { _dbState = state; }
private static bool IsDbOk(DbState dbState) { return dbState.Status == DbStatus.Ok; }
private void ThenMoreThanOneBisectTableOperationHasBeenPerformed(DbState originalDbState, IDataBase db) { ThereIsMoreThanOneBackupTable(originalDbState, db); }
private void ThereIsMoreThanOneBackupTable(DbState originalDbState, IDataBase db) { Assert.That(new DbState(db).Keys.Count, Is.GreaterThan(originalDbState.Keys.Count + 1)); }