예제 #1
0
        /// <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;
            }
        }
예제 #2
0
 /// <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;
        }
예제 #4
0
        public static DbState GetTestDbRandomState(int n)
        {
            var dbEntryList = GetTestDbEntryRandomList(n, 2 * n);
            var dbState     = new DbState(GetTestDbView(), dbEntryList);

            return(dbState);
        }
예제 #5
0
 /// <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;
 }
예제 #6
0
 public IActionResult CheckDatabase()
 {
     if (DbState.IsDatabaseAvailable())
     {
         ViewBag.State = "Available";
         return(View());
     }
     else
     {
         ViewBag.State = "Not available";
         return(View());
     }
 }
예제 #7
0
 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;
     }
 }
예제 #8
0
        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));
 }
예제 #10
0
        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];
        }
예제 #11
0
        /// <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;
            }
        }
예제 #12
0
        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));
        }
예제 #13
0
 private static bool GetCanResolve(DbState dbState)
 {
     return dbState.Status == DbStatus.NotExists || dbState.Status == DbStatus.Outdated || dbState.Status == DbStatus.NoSchema;
 }
예제 #14
0
 private DbSectionState GetNotExistDbSectionState(DbState dbState, ScoutVersion? requiredVersion)
 {
     return new DbSectionState(dbState, DbSectionStatus.NotExists, requiredVersion, true);
 }
예제 #15
0
        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: "Не удалось определить версию секции бд.");
            }
        }
예제 #16
0
 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));
 }
예제 #18
0
파일: Entity.cs 프로젝트: sxkote/DemoTools
 void IDbState.DeleteFromDb()
 {
     _dbState = DbState.Deleted;
 }
예제 #19
0
파일: Entity.cs 프로젝트: sxkote/DemoTools
 void IDbState.ChangeDbState(DbState state)
 {
     _dbState = state;
 }
예제 #20
0
 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));
 }