public void Upsert_WhenNoSetExists_TablesAreCreated()
        {
            using(var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false))
            {
                var upserter = new SqlDbSchemaUpserter(dbClient);
                upserter.Upsert(_structureSchema);
            }

            var structureTableExists = DbHelper.TableExists(_structureTableName);
            var indexesTableExists = DbHelper.TableExists(_indexesTableName);

            Assert.IsTrue(structureTableExists);
            Assert.IsTrue(indexesTableExists);
        }
        public void UpsertStructureSet(IStructureSchema structureSchema)
        {
            lock (_upsertedSchemas)
            {
                if (_upsertedSchemas.Contains(structureSchema.Name))
                    return;

                using (var dbClient = new SqlDbClient(_connectionInfo, false))
                {
                    var upserter = new SqlDbSchemaUpserter(dbClient);
                    upserter.Upsert(structureSchema);
                }

                _upsertedSchemas.Add(structureSchema.Name);
            }
        }
        public void Upsert_WhenDbHasOneObsoleteMember_ColumnIsDroppedFromIndexesTable()
        {
            var hashForObsoleteColumn = SisoDbEnvironment.MemberNameGenerator.Generate("ExtraColumn");
            using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false))
            {
                var upserter = new SqlDbSchemaUpserter(dbClient);

                upserter.Upsert(_structureSchema);

                var obsoleteColumnDefinition = string.Format("[{0}] [int] sparse null", hashForObsoleteColumn);
                DbHelper.AddColumns(_indexesTableName, obsoleteColumnDefinition);

                upserter.Upsert(_structureSchema);
            }

            var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForObsoleteColumn);
            Assert.IsFalse(columnExists);
        }
        public void Upsert_WhenClassHasOneNewMember_ColumnIsAddedToIndexesTable()
        {
            var hashForColumn = SisoDbEnvironment.MemberNameGenerator.Generate("IndexableMember2");

            using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false))
            {
                var upserter = new SqlDbSchemaUpserter(dbClient);

                upserter.Upsert(_structureSchema);

                DbHelper.DropColumns(_indexesTableName, hashForColumn);

                upserter.Upsert(_structureSchema);
            }

            var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForColumn);
            Assert.IsTrue(columnExists);
        }