Inheritance: IMigrationReport
Example #1
0
        public void VerifyUnsupportedDataTypesAreReported()
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.String, 255, 0), false, false), // ok
                new UsedDataType(new DataType(DbType.Currency, 0, 0), false, false), // not supported
                new UsedDataType(new DataType(DbType.Int32, 0, 0), false, false), // ok
                new UsedDataType(new DataType(DbType.Decimal, 20, 10), false, false), // exceeds size and scale
                new UsedDataType(new DataType(DbType.String, 0, 0), false, false), // ok (should not override the primary key status of this DbType)

                new UsedDataType(new DataType(DbType.String, 0, 0), true, false), // as primary key -> *not* ok w/o size
                new UsedDataType(new DataType(DbType.String, 255, 0), true, false), // as primary key -> ok

                new UsedDataType(new DataType(DbType.Decimal, 8, 2), false, true), // as identity -> *not* ok with scale
                new UsedDataType(new DataType(DbType.Decimal, 8, 0), false, true), // as identity -> ok without scale
            };
            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.DataTypes).Return(dataTypes);
            migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            string expected = string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.", MigrationName, DbType.Currency, ProviderName) + Environment.NewLine +
                              string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(20,10)' which exceeds the maximum size of 10 supported by '{2}'.", MigrationName, DbType.Decimal, ProviderName) + Environment.NewLine +
                              string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(20,10)' which exceeds the maximum scale of 5 supported by '{2}'.", MigrationName, DbType.Decimal, ProviderName) + Environment.NewLine +
                              string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' for a primary key which is not supported by '{2}'.", MigrationName, DbType.String, ProviderName) + Environment.NewLine +
                              string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(8,2)' for an identity column which is not supported by '{2}'.", MigrationName, DbType.Decimal, ProviderName);
            Assert.AreEqual(expected, errors);
        }
Example #2
0
        public void VerifyUnsupportedMethodsAreReported()
        {
            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.DataTypes).Return(Enumerable.Empty<UsedDataType>());
            migration.Expect(m => m.Methods).Return(new[] { "CreateTable", "DropTable" });
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' calls the '{1}' method which is not supported by '{2}': DropTable is not supported because this is just a test.", MigrationName, "DropTable", ProviderName),
                errors);
            Assert.IsNullOrEmpty(warnings);
        }
Example #3
0
        public IMigrationReport Report(IMigrationContext context)
        {
            Database database = GetDatabaseContainingMigrationChanges(_metadata.Direction, context);

            return(MigrationReport.Create(database, MigrationName));
        }
Example #4
0
        public void VerifyViolatingMaximumDbObjectNameLengthIsReported()
        {
            const string longestName = "Some very long name";

            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.NewObjectNames).Return(new[] { longestName, longestName.Substring(1) });
            migration.Expect(m => m.DataTypes).Return(Enumerable.Empty<UsedDataType>());
            migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            var report = new MigrationReport(MigrationName, "Some other validation error.", migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Error in migration '{0}': Some other validation error.", MigrationName) + Environment.NewLine +
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' contains object names that are longer than what is supported by '{1}' ('{2}': {3}, supported: {4}).", MigrationName, ProviderName, longestName, longestName.Length, MaximumSupportedLength),
                errors);
            Assert.IsNullOrEmpty(warnings);
        }
Example #5
0
        private static string GetWarnings(MigrationOptions options, out string warnings)
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.Guid, 0, 0), false, false),
                new UsedDataType(new DataType(DbType.String, 0, 0), false, false),
            };
            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.DataTypes).Return(dataTypes);
            migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            Validate(options, report, out errors, out warnings);
            return errors;
        }
Example #6
0
        public void VerifyWronglyUsedOfSizeAreReported()
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.Int32, 666, 0), false, false),
                new UsedDataType(new DataType(DbType.String, 0, 666), false, false),
                new UsedDataType(new DataType(DbType.Decimal, 0, 0), false, false),
            };
            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.DataTypes).Return(dataTypes);
            migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(666)' with a non-zero size and a zero scale which is not supported by '{2}'.", MigrationName, DbType.Int32, ProviderName) + Environment.NewLine +
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(0,666)' with a zero size and a non-zero scale which is not supported by '{2}'.", MigrationName, DbType.String, ProviderName) + Environment.NewLine +
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' with a zero size and a zero scale which is not supported by '{2}'.", MigrationName, DbType.Decimal, ProviderName),
                errors);
            Assert.IsNullOrEmpty(warnings);
        }
Example #7
0
        public void VerifyWarningsForOdbc()
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.Int64, 0, 0), false, false),
            };
            IRecordedMigration migration = MockRepository.GenerateStub<IRecordedMigration>();
            migration.Expect(m => m.DataTypes).Return(dataTypes);
            migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.IsNullOrEmpty(errors);
            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which is not fully supported by '{2}': Int64 is not supported for DbParameters with ODBC; requires calling ToString to directly inline the value in the CommandText.", MigrationName, DbType.Int64, ProviderName),
                warnings);
        }
Example #8
0
        public void VerifyUnsupportedMethodsAreReported()
        {
            IRecordedMigration migration = A.Fake<IRecordedMigration>();
            //migration.Expect(m => m.DataTypes).Return(Enumerable.Empty<UsedDataType>());
            A.CallTo(() => migration.Methods).Returns(new[] { "CreateTable", "AddColumn" });
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' calls the '{1}' method which is not supported by '{2}': AddColumn is not supported because this is just a test.", MigrationName, "AddColumn", Platform),
                errors);
            Assert.IsNullOrEmpty(warnings);
        }
Example #9
0
        private static string GetWarnings(IEnumerable<ProviderInfo> providerInfos, MigrationOptions options, out string warnings)
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.Guid), false, false),
                new UsedDataType(new DataType(DbType.String), false, false),
            };
            IRecordedMigration migration = A.Fake<IRecordedMigration>();
            A.CallTo(() => migration.DataTypes).Returns(dataTypes);
            //migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            Validate(providerInfos, options, report, out errors, out warnings);
            return errors;
        }
Example #10
0
        public void VerifyWronglyUsedOfSizeAreReported()
        {
            var dataTypes = new List<UsedDataType>
            {
                new UsedDataType(new DataType(DbType.Int32, 777), false, false),
                new UsedDataType(new DataType(DbType.String, null, 777), false, false),
                new UsedDataType(new DataType(DbType.Decimal), false, false),
            };
            IRecordedMigration migration = A.Fake<IRecordedMigration>();
            A.CallTo(() => migration.DataTypes).Returns(dataTypes);
            //migration.Expect(m => m.Methods).Return(Enumerable.Empty<string>());
            MigrationReport report = new MigrationReport(MigrationName, string.Empty, migration);

            string errors;
            string warnings;
            Validate(report, out errors, out warnings);

            Assert.AreEqual(
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(777)' which is not supported by '{2}'.", MigrationName, DbType.Int32, Platform) + Environment.NewLine +
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}(null,777)' which is not supported by '{2}'.", MigrationName, DbType.String, Platform) + Environment.NewLine +
                string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.", MigrationName, DbType.Decimal, Platform),
                errors);
            Assert.IsNullOrEmpty(warnings);
        }