public MultipleFetchManyWithNonRootAndThenFetchSqlServerFixture() {
            this.config = new MultipleFetchManyWithNonRootAndThenFetchConfig();
            this.DatabaseName = "DashingIntegration_" + Guid.NewGuid().ToString("D").Substring(0, 8);

            // load the data
            using (var transactionLessSession = this.config.BeginTransactionLessSession()) {
                var dialect = new SqlServer2012Dialect();
                var migrator = new Migrator(
                    dialect,
                    new CreateTableWriter(dialect),
                    new AlterTableWriter(dialect),
                    new DropTableWriter(dialect),
                    new StatisticsProvider(null, dialect));
                IEnumerable<string> warnings, errors;
                var createStatement = migrator.GenerateSqlDiff(
                    new List<IMap>(),
                    this.config.Maps,
                    null,
                    new Mock<ILogger>().Object,
                    new string[0],
                    out warnings,
                    out errors);
                transactionLessSession.Dapper.Execute("create database " + this.DatabaseName);
                transactionLessSession.Dapper.Execute("use " + this.DatabaseName);
                transactionLessSession.Dapper.Execute(createStatement);
            }

            this.Session = this.config.BeginSession();
            this.Session.Dapper.Execute("use " + this.DatabaseName);
            this.InsertData();
        }
Пример #2
0
        public void DropOneToOneRightTable() {
            var configTo = new CustomConfig();
            var configFrom = new CustomConfig();

            // remove onetooneleft from the config
            var mappedTypes =
                (IDictionary<Type, IMap>)
                typeof(ConfigurationBase).GetField("mappedTypes", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(configTo);
            mappedTypes.Remove(typeof(OneToOneRight));
            configTo.GetMap<OneToOneLeft>().Columns.Remove("Right");

            var dialect = new SqlServer2012Dialect();
            var migrator = new Migrator(
                dialect,
                new CreateTableWriter(dialect),
                new AlterTableWriter(dialect),
                new DropTableWriter(dialect),
                GetMockStatisticsProvider(configFrom));
            IEnumerable<string> warnings;
            IEnumerable<string> errors;
            var script = migrator.GenerateSqlDiff(
                configFrom.Maps,
                configTo.Maps,
                null,
                new Mock<ILogger>().Object,
                new string[0],
                out warnings,
                out errors);

            var dropColIdx = script.IndexOf("alter table [OneToOneLefts] drop column [RightId];", StringComparison.Ordinal);
            var dropTableIdx = script.IndexOf("drop table [OneToOneRights];", StringComparison.Ordinal);
            Assert.True(dropColIdx > -1);
            Assert.True(dropTableIdx > -1);
            Assert.True(dropColIdx < dropTableIdx);
        }
Пример #3
0
        public void DropSelfReferencedWorks() {
            var configTo = new CustomConfig();
            var configFrom = new CustomConfig();

            // remove onetooneleft from the config
            var mappedTypes =
                (IDictionary<Type, IMap>)
                typeof(ConfigurationBase).GetField("mappedTypes", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(configTo);
            mappedTypes.Remove(typeof(Pair));

            var dialect = new SqlServer2012Dialect();
            var migrator = new Migrator(
                dialect,
                new CreateTableWriter(dialect),
                new AlterTableWriter(dialect),
                new DropTableWriter(dialect),
                GetMockStatisticsProvider(configFrom));
            IEnumerable<string> warnings;
            IEnumerable<string> errors;
            var script = migrator.GenerateSqlDiff(
                configFrom.Maps,
                configTo.Maps,
                null,
                new Mock<ILogger>().Object,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            Assert.Equal(@"drop table [Pairs];", script.Trim());
        }