public void MaxBatchSize_is_optional() { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseMySql("Database=Crunchie"); var typeMapper = new MySqlTypeMappingSource( TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(), TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>()); var factory = new MySqlModificationCommandBatchFactory( new RelationalCommandBuilderFactory( new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>(), typeMapper), new MySqlSqlGenerationHelper( new RelationalSqlGenerationHelperDependencies()), new MySqlUpdateSqlGenerator( new UpdateSqlGeneratorDependencies( new MySqlSqlGenerationHelper( new RelationalSqlGenerationHelperDependencies()), typeMapper)), new TypedRelationalValueBufferFactoryFactory( new RelationalValueBufferFactoryDependencies( typeMapper, new CoreSingletonOptions())), optionsBuilder.Options); var batch = factory.Create(); Assert.True(batch.AddCommand(new ModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.True(batch.AddCommand(new ModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, false, null))); }
public void AddCommand_returns_false_when_max_batch_size_is_reached() { var typeMapper = new MySqlTypeMappingSource( TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(), TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>()); var batch = new MySqlModificationCommandBatch( new RelationalCommandBuilderFactory( new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>(), typeMapper), new MySqlSqlGenerationHelper( new RelationalSqlGenerationHelperDependencies()), new MySqlUpdateSqlGenerator( new UpdateSqlGeneratorDependencies( new MySqlSqlGenerationHelper( new RelationalSqlGenerationHelperDependencies()), typeMapper)), new TypedRelationalValueBufferFactoryFactory( new RelationalValueBufferFactoryDependencies( typeMapper)), 1); Assert.True( batch.AddCommand( new ModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, false, null))); Assert.False( batch.AddCommand( new ModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, false, null))); }
public MySqlStringMethodTranslator( MySqlSqlExpressionFactory sqlExpressionFactory, MySqlTypeMappingSource typeMappingSource) { _typeMappingSource = typeMappingSource; _sqlExpressionFactory = sqlExpressionFactory; }
public MySqlStringMethodTranslator( MySqlSqlExpressionFactory sqlExpressionFactory, MySqlTypeMappingSource typeMappingSource, IMySqlOptions options) { _sqlExpressionFactory = sqlExpressionFactory; _typeMappingSource = typeMappingSource; _options = options; }
public GearsOfWarQueryMySqlTest(GearsOfWarQueryMySqlFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture) { using var context = CreateContext(); _typeMappingSource = (MySqlTypeMappingSource)context.GetService <IRelationalTypeMappingSource>(); Fixture.TestSqlLoggerFactory.Clear(); //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); }
protected void Test(Action <ModelBuilder> buildModel, string expectedCode, Action <IModel> assert) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.HasChangeTrackingStrategy(ChangeTrackingStrategy.Snapshot); buildModel(modelBuilder); var typeMappingSource = new MySqlTypeMappingSource( TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(), TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>(), TestServiceFactory.Instance.Create <MySqlOptions>(), TestServiceFactory.Instance.Create <MySqlConnectionInfo>()); var modelValidator = CreateModelValidator(typeMappingSource); modelValidator.Validate( modelBuilder.Model, new DiagnosticsLogger <DbLoggerCategory.Model.Validation>( new ListLoggerFactory(category => category == DbLoggerCategory.Model.Validation.Name), new LoggingOptions(), new DiagnosticListener("Fake"), new MySqlLoggingDefinitions())); var model = modelBuilder.Model; var codeHelper = new CSharpHelper( typeMappingSource); var generator = new CSharpMigrationsGenerator( new MigrationsCodeGeneratorDependencies(typeMappingSource), new CSharpMigrationsGeneratorDependencies( codeHelper, new CSharpMigrationOperationGenerator( new CSharpMigrationOperationGeneratorDependencies( codeHelper)), new CSharpSnapshotGenerator( new CSharpSnapshotGeneratorDependencies( codeHelper, typeMappingSource)))); var code = generator.GenerateSnapshot("RootNamespace", typeof(DbContext), "Snapshot", model); Assert.Equal(expectedCode, code, ignoreLineEndingDifferences: true); var build = new BuildSource { Sources = { @" using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; public static class ModelSnapshot { public static IModel Model { get { var builder = new ModelBuilder(new ConventionSet()); " + code + @" return builder.Model; } } } " } }; foreach (var buildReference in GetReferences()) { build.References.Add(buildReference); } var assembly = build.BuildInMemory(); var factoryType = assembly.GetType("ModelSnapshot"); var property = factoryType.GetTypeInfo().GetDeclaredProperty("Model"); var value = (IModel)property.GetValue(null); Assert.NotNull(value); assert(value); }
public static DateTimeOffset SimulateDatabaseRoundtrip(this DateTimeOffset dateTimeOffset, MySqlTypeMappingSource typeMappingSource) { var dateTimeOffsetTypeMapping = (MySqlDateTimeOffsetTypeMapping)typeMappingSource.GetMappingForValue(dateTimeOffset); var value = DateTimeOffset.ParseExact( dateTimeOffsetTypeMapping.GenerateSqlLiteral(dateTimeOffset) .Trim('\''), dateTimeOffsetTypeMapping.GetFormatString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); return(value); }