Exemple #1
0
        public void OneToOneWorks()
        {
            var config = new MutableConfiguration(ConnectionString);

            config.Add <OneToOneLeft>();
            config.Add <OneToOneRight>();
            var migrator = MakeMigrator(config);
            IEnumerable <string> errors;
            IEnumerable <string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new Mock <ILogger>().Object,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            Assert.Equal(Regex.Replace(@"create table [OneToOneLefts] ([OneToOneLeftId] int not null identity(1,1) primary key, [RightId] int null, [Name] nvarchar(255) null);
create table [OneToOneRights] ([OneToOneRightId] int not null identity(1,1) primary key, [LeftId] int null, [Name] nvarchar(255) null);
alter table [OneToOneLefts] add constraint fk_OneToOneLeft_OneToOneRight_Right foreign key ([RightId]) references [OneToOneRights]([OneToOneRightId]);
alter table [OneToOneRights] add constraint fk_OneToOneRight_OneToOneLeft_Left foreign key ([LeftId]) references [OneToOneLefts]([OneToOneLeftId]);
create index [idx_OneToOneLeft_Right] on [OneToOneLefts] ([RightId]);
create index [idx_OneToOneRight_Left] on [OneToOneRights] ([LeftId]);",
                                       @"(?<!\r)\n",
                                       Environment.NewLine),
                         script.Trim());
        }
Exemple #2
0
        public void PairWorks()
        {
            var config = new MutableConfiguration(ConnectionString);

            config.Add <Pair>();
            var migrator = MakeMigrator(config);
            IEnumerable <string> errors;
            IEnumerable <string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new Mock <ILogger>().Object,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            Assert.Equal(Regex.Replace(@"create table [Pairs] ([PairId] int not null identity(1,1) primary key, [ReferencesId] int null, [ReferencedById] int null);
alter table [Pairs] add constraint fk_Pair_Pair_References foreign key ([ReferencesId]) references [Pairs]([PairId]);
alter table [Pairs] add constraint fk_Pair_Pair_ReferencedBy foreign key ([ReferencedById]) references [Pairs]([PairId]);
create index [idx_Pair_References] on [Pairs] ([ReferencesId]);
create index [idx_Pair_ReferencedBy] on [Pairs] ([ReferencedById]);",
                                       @"(?<!\r)\n",
                                       Environment.NewLine),
                         script.Trim());
        }
Exemple #3
0
        /// <summary>
        ///     Returns a Configuration object for the connection string that can be fluently configured
        /// </summary>
        /// <param name="connectionStringSettings">connection string settings for the database to be used</param>
        /// <param name="types">Enumerable of types to be mapped</param>
        /// <returns>Mutable configuration object</returns>
        public static MutableConfiguration Configure(ConnectionStringSettings connectionStringSettings, IEnumerable<Type> types) {
            if (connectionStringSettings == null) {
                throw new ArgumentNullException("connectionStringSettings");
            }

            var configuration = new MutableConfiguration(connectionStringSettings);
            configuration.Add(types);
            return configuration;
        }
Exemple #4
0
        /// <summary>
        ///     Returns a Configuration object for the connection string that can be fluently configured
        /// </summary>
        /// <param name="connectionStringSettings">connection string settings for the database to be used</param>
        /// <param name="types">Enumerable of types to be mapped</param>
        /// <returns>Mutable configuration object</returns>
        public static MutableConfiguration Configure(ConnectionStringSettings connectionStringSettings, IEnumerable <Type> types)
        {
            if (connectionStringSettings == null)
            {
                throw new ArgumentNullException("connectionStringSettings");
            }

            var configuration = new MutableConfiguration(connectionStringSettings);

            configuration.Add(types);
            return(configuration);
        }
        public void SelfReferencingWorks() {
            var config = new MutableConfiguration(ConnectionString);
            config.Add<Category>();
            var migrator = MakeMigrator(config);
            IEnumerable<string> errors;
            IEnumerable<string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new Mock<ILogger>().Object,
                new string[0],
                out warnings,
                out errors);
            Assert.Equal(Regex.Replace(@"create table [Categories] ([CategoryId] int not null identity(1,1) primary key, [ParentId] int null, [Name] nvarchar(255) null);
alter table [Categories] add constraint fk_Category_Category_Parent foreign key ([ParentId]) references [Categories]([CategoryId]);
create index [idx_Category_Parent] on [Categories] ([ParentId]);",
                @"(?<!\r)\n",
                Environment.NewLine),
                script.Trim());
        }
        public void GuidPrimaryKeyWorks()
        {
            var config = new MutableConfiguration();

            config.Add <EntityWithGuidPk>();
            var migrator = MakeMigrator(config);
            IEnumerable <string> errors;
            IEnumerable <string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            this.output.WriteLine(script);
            Assert.Equal(
                "create table [EntityWithGuidPks] ([Id] uniqueidentifier not null DEFAULT NEWSEQUENTIALID() primary key, [Name] nvarchar(255) null);",
                script.Trim());
        }
        public void VersionedEntityWorks()
        {
            var config = new MutableConfiguration();

            config.Add <VersionedEntity>();
            var migrator = MakeMigrator(config);
            IEnumerable <string> errors;
            IEnumerable <string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            this.output.WriteLine(script);
            Assert.Equal(
                "create table [VersionedEntities] ([Id] uniqueidentifier not null DEFAULT NEWSEQUENTIALID() primary key, [Name] nvarchar(255) null, [SessionUser]  as (cast(SESSION_CONTEXT(N'UserId') as nvarchar(255))), [CreatedBy] nvarchar(255) NULL DEFAULT (cast(SESSION_CONTEXT(N'UserId') as nvarchar(255))), [SysStartTime] datetime2(2) GENERATED ALWAYS AS ROW START HIDDEN DEFAULT GETUTCDATE(), [SysEndTime] datetime2(2) GENERATED ALWAYS AS ROW END HIDDEN DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'), PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime)) WITH (SYSTEM_VERSIONING = ON ( HISTORY_TABLE = dbo.[VersionedEntitiesHistory]));",
                script.Trim());
        }
        public void PairWorks() {
            var config = new MutableConfiguration(ConnectionString);
            config.Add<Pair>();
            var migrator = MakeMigrator(config);
            IEnumerable<string> errors;
            IEnumerable<string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new Mock<ILogger>().Object,
                new string[0],
                out warnings,
                out errors);
            Assert.Equal(Regex.Replace(@"create table [Pairs] ([PairId] int not null identity(1,1) primary key, [ReferencesId] int null, [ReferencedById] int null);
alter table [Pairs] add constraint fk_Pair_Pair_References foreign key ([ReferencesId]) references [Pairs]([PairId]);
alter table [Pairs] add constraint fk_Pair_Pair_ReferencedBy foreign key ([ReferencedById]) references [Pairs]([PairId]);
create index [idx_Pair_References] on [Pairs] ([ReferencesId]);
create index [idx_Pair_ReferencedBy] on [Pairs] ([ReferencedById]);",
                @"(?<!\r)\n",
                Environment.NewLine),
                script.Trim());
        }
        public void SelfReferencingWorks()
        {
            var config = new MutableConfiguration();

            config.Add <Category>();
            var migrator = MakeMigrator(config);
            IEnumerable <string> errors;
            IEnumerable <string> warnings;
            var script = migrator.GenerateSqlDiff(
                new IMap[] { },
                config.Maps,
                null,
                new string[0],
                new string[0],
                out warnings,
                out errors);

            Assert.Equal(Regex.Replace(@"create table [Categories] ([CategoryId] int not null identity(1,1) primary key, [ParentId] int null, [Name] nvarchar(255) null);
alter table [Categories] add constraint fk_Category_Category_Parent foreign key ([ParentId]) references [Categories]([CategoryId]);
create index [idx_Category_Parent] on [Categories] ([ParentId]);",
                                       @"(?<!\r)\n",
                                       Environment.NewLine),
                         script.Trim());
        }