public void HasTraitReturnsTrueWhenTraitIsDefined()
        {
            MigrationInfo migrationinfo = Create();

            migrationinfo.AddTrait("foo", 42);
            migrationinfo.HasTrait("foo").ShouldBeTrue();
        }
        public void TraitMethodReturnsTraitValue()
        {
            MigrationInfo migrationinfo = Create();
            const string  value         = "bar";

            migrationinfo.AddTrait("foo", value);
            migrationinfo.Trait("foo").ShouldBeSameAs(value);
        }
        private static IMigrationInfo GetMigrationInfoForMigrationImpl(IMigration migration)
        {
            var migrationType      = migration.GetType();
            var migrationAttribute = migrationType.GetCustomAttribute <MigrationAttribute>();
            var migrationInfo      = new MigrationInfo(migrationAttribute.Version, migrationAttribute.Description, migrationAttribute.TransactionBehavior, migrationAttribute.BreakingChange, () => migration);

            foreach (var traitAttribute in migrationType.GetCustomAttributes <MigrationTraitAttribute>(true))
            {
                migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);
            }

            return(migrationInfo);
        }
Esempio n. 4
0
        private static IMigrationInfo GetMigrationInfoForImpl(Type migrationType)
        {
            IMigration CreateMigration()
            {
                return((IMigration)Activator.CreateInstance(migrationType));
            }

            var migrationAttribute = migrationType.GetOneAttribute <MigrationAttribute>();
            var migrationInfo      = new MigrationInfo(migrationAttribute.Version, migrationAttribute.Description, migrationAttribute.TransactionBehavior, migrationAttribute.BreakingChange, CreateMigration);

            foreach (MigrationTraitAttribute traitAttribute in migrationType.GetAllAttributes <MigrationTraitAttribute>())
            {
                migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);
            }

            return(migrationInfo);
        }
Esempio n. 5
0
        private static IMigrationInfo GetPlatformMigrationInfo(Type type)
        {
            Guard.AgainstArgumentIsNull(type, nameof(type));
            Guard.AgainstNull(type.FullName, "type.FullName != null");

            var migrationMetadata           = type.GetOneAttribute <MigrationTimestampAttribute>();
            Func <IMigration> migrationFunc = () => (IMigration)type.Assembly.CreateInstance(type.FullName);
            var description = FormattableString.Invariant($"{migrationMetadata.MigrationDate:g} - {type.FullName}");

            var migrationInfo = new MigrationInfo(migrationMetadata.Version, description, TransactionBehavior.Default, migrationFunc);

            foreach (var allAttribute in type.GetAllAttributes <MigrationTraitAttribute>())
            {
                migrationInfo.AddTrait(allAttribute.Name, allAttribute.Value);
            }
            return(migrationInfo);
        }
Esempio n. 6
0
        private static IMigrationInfo GetMigrationInfoForMigrationImpl(IMigration migration)
        {
            if (typeof(DbSchemaItem).IsAssignableFrom(migration.GetType()))
            {
                var migrationType      = migration.GetType();
                var migrationAttribute = migrationType.GetCustomAttribute <MigrationAttribute>() ?? new MigrationAttribute(number++, "");
                var migrationInfo      = new MigrationInfo(migrationAttribute.Version, migrationAttribute.Description, migrationAttribute.TransactionBehavior, migrationAttribute.BreakingChange, () => migration);

                foreach (var traitAttribute in migrationType.GetCustomAttributes <MigrationTraitAttribute>(true))
                {
                    migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);
                }

                return(migrationInfo);
            }
            return(DefaultMigrationRunnerConventions.Instance.GetMigrationInfoForMigration(migration));
        }
Esempio n. 7
0
            private static IMigrationInfo GetMigrationInfoFor(FluentMigrator.IMigration migration)
            {
                var migrationType      = migration.GetType();
                var migrationAttribute = migrationType.GetOneAttribute <MigrationAttribute>();
                var chunSunMigration   = migration as MigrationBase;

                if (chunSunMigration == null)
                {
                    throw new Exception("迁移提供程序必须继承自 \"" + typeof(MigrationBase).FullName + "\" 类型。");
                }
                var id = chunSunMigration.Feature.Descriptor.Id;

                var version     = migrationAttribute.Version;
                var description = id + "_" + migrationAttribute.Description + "_" + migrationAttribute.Version;

                var migrationInfo = new MigrationInfo(version, description, migrationAttribute.TransactionBehavior, () => migration);
                var allAttributes = migrationType.GetAllAttributes <MigrationTraitAttribute>();

                foreach (var traitAttribute in allAttributes)
                {
                    migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);
                }
                return(migrationInfo);
            }