public void Can_log_provider_execution_warnings() { ResetDatabase(); var migrator = CreateMigrator <ShopContext_v1>(); migrator.Update(); var mockLogger = new Mock <MigrationsLogger>(); migrator = CreateMigrator <ShopContext_v1>(new WarningMigration()); var migratorLoggingDecorator = new MigratorLoggingDecorator( migrator, mockLogger.Object); migratorLoggingDecorator.Update(); if (LocalizationTestHelpers.IsEnglishLocale()) { mockLogger .Verify( ml => ml.Warning( "Warning! The maximum key length is 900 bytes. The index 'PK_PkTooLong' has maximum length of 902 bytes. For some combination of large values, the insert/update operation will fail."), Times.Once()); } else { mockLogger.Verify(ml => ml.Warning(It.IsAny <string>()), Times.Once()); } }
public void DbUnexpectedValidationException_parameterless_constructor() { if (LocalizationTestHelpers.IsEnglishLocale()) { var exception = new DbUnexpectedValidationException(); Assert.Equal("Data Exception.", exception.Message); } }
public void WhenBadParameterIndexShouldThrow() { if (LocalizationTestHelpers.IsEnglishLocale()) { migrate::CmdLine.CommandLine.CommandEnvironment = new TestCommandEnvironment(); Assert.Equal( new CustomAttributeFormatException("'ParameterIndex' property specified was not found.").Message, Assert.Throws <CustomAttributeFormatException>(() => migrate::CmdLine.CommandLine.Parse <TypeWithBadParamIndex>()).Message); } }
public void WhenDuplicatePositionShouldThrow() { if (LocalizationTestHelpers.IsEnglishLocale()) { migrate::CmdLine.CommandLine.CommandEnvironment = new TestCommandEnvironment(); Assert.Equal( new migrate::CmdLine.CommandLineException("Duplicate Parameter Index [1] on Property \"S2\"").Message, Assert.Throws <migrate::CmdLine.CommandLineException>( () => migrate::CmdLine.CommandLine.Parse <TypeWithDuplicateParamIndex>()).Message); } }
public void WhenNoPositionOneShouldThrow() { if (LocalizationTestHelpers.IsEnglishLocale()) { migrate::CmdLine.CommandLine.CommandEnvironment = new TestCommandEnvironment(); Assert.Equal( new migrate::CmdLine.CommandLineException( "Out of order parameter \"source\" should have be at parameter index 1 but was found at 2").Message, Assert.Throws <migrate::CmdLine.CommandLineException>(() => migrate::CmdLine.CommandLine.Parse <BadPositionArgNoOne>()). Message); } }
public void Generate_should_throw_when_column_rename() { if (LocalizationTestHelpers.IsEnglishLocale()) { var migrationProvider = new SqlCeMigrationSqlGenerator(); var renameColumnOperation = new RenameColumnOperation("T", "c", "c'"); Assert.Equal( Strings.SqlCeColumnRenameNotSupported, Assert.Throws <MigrationsException>(() => migrationProvider.Generate(new[] { renameColumnOperation }, "4.0").ToList()). Message); } }
public void Using_invalid_facets_on_FunctionImport_enum_parameter_throws() { var funcImportInvalidEnumParamFacets = new string[8, 2]; Array.Copy(invalidEnumPropertyFacets, funcImportInvalidEnumParamFacets, invalidEnumPropertyFacets.Length); funcImportInvalidEnumParamFacets[6, 0] = "Nullable"; funcImportInvalidEnumParamFacets[6, 1] = "false"; funcImportInvalidEnumParamFacets[7, 0] = "DefaultValue"; funcImportInvalidEnumParamFacets[7, 1] = "34"; for (int i = 0; i < funcImportInvalidEnumParamFacets.Length >> 1; i++) { var enumCSDL = XDocument.Parse(enumCsdl); enumCSDL.Root .Descendants(XName.Get("EntityContainer", edmNamespace)) .Single() .Add(XElement.Parse(string.Format( @"<FunctionImport Name=""TestFunc"" xmlns=""http://schemas.microsoft.com/ado/2009/11/edm""> <Parameter Name=""EnumProperty"" Type=""EnumTestModel.Color"" {0}=""{1}"" /> </FunctionImport>", funcImportInvalidEnumParamFacets[i, 0], funcImportInvalidEnumParamFacets[i, 1]))); try { new EdmItemCollection(new XmlReader[] { enumCSDL.CreateReader() }); // Should never get here - exception is expected Assert.True(1 == 2); } catch (MetadataException ex) { if (LocalizationTestHelpers.IsEnglishLocale()) { if (new string[] { "MaxLength", "Precision", "Scale" }.Contains(funcImportInvalidEnumParamFacets[i, 0])) { Assert.True(ex.Message.Contains(funcImportInvalidEnumParamFacets[i, 0] + " facet isn't allowed for properties of type EnumTestModel.Color"), "Unexpected exception\n: " + ex); } else if (funcImportInvalidEnumParamFacets[i, 0] == "Nullable") { Assert.True(ex.Message.Contains("non-nullable"), "Unexpected exception\n: " + ex); } else { Assert.True(ex.Message.Contains("The '" + funcImportInvalidEnumParamFacets[i, 0] + "' attribute is not allowed"), "Unexpected exception\n: " + ex); } } } } }
public void Generate_throws_when_operation_unknown() { if (LocalizationTestHelpers.IsEnglishLocale()) { var migrationSqlGenerator = new SqlCeMigrationSqlGenerator(); var unknownOperation = new Mock <MigrationOperation>(null).Object; var ex = Assert.Throws <InvalidOperationException>( () => migrationSqlGenerator.Generate(new[] { unknownOperation }, "4.0")); Assert.Equal( Strings.SqlServerMigrationSqlGenerator_UnknownOperation( typeof(SqlCeMigrationSqlGenerator).Name, unknownOperation.GetType().FullName), ex.Message); } }
public void Validation_fails_for_enums_with_missing_enum_member_Name() { var csdl = XDocument.Parse(enumCsdl); var enumMember = csdl.Descendants(XName.Get("Member", edmNamespace)).First(); enumMember.Attributes("Name").Remove(); var exceptionMessage = string.Empty; csdl.Validate(csdlSchemaSet, (o, e) => exceptionMessage = e.Message); if (LocalizationTestHelpers.IsEnglishLocale()) { Assert.Equal("The required attribute 'Name' is missing.", exceptionMessage); } else { Assert.False(string.IsNullOrEmpty(exceptionMessage)); } }