private void Test(Action <ModelBuilder> buildModel, string expectedCode, Action <IModel> assert) { var modelBuilder = TestHelpers.Instance.CreateConventionBuilder(); buildModel(modelBuilder); var model = modelBuilder.Model; var generator = new CSharpModelGenerator(new CSharpHelper()); var builder = new IndentedStringBuilder(); generator.Generate(model, builder); var code = builder.ToString(); Assert.Equal(expectedCode, code); var build = new BuildSource { References = { BuildReference.ByName("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("EntityFramework.Core"), BuildReference.ByName("EntityFramework.Relational") }, Sources = { @" using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Metadata.Conventions; using Microsoft.Data.Entity.Migrations.Infrastructure; public static class ModelSnapshot { public static IModel Model { get { var builder = new ModelBuilder(new ConventionSet()); " + code + @" return builder.Model; } } } " } }; var assembly = build.BuildInMemory(); var factoryType = assembly.GetType("ModelSnapshot"); var property = factoryType.GetProperty("Model"); var value = (IModel)property.GetValue(null); Assert.NotNull(value); assert(value); }
public CSharpMigrationGenerator( [NotNull] CSharpHelper code, [NotNull] CSharpMigrationOperationGenerator operationGenerator, [NotNull] CSharpModelGenerator modelGenerator) { Check.NotNull(code, nameof(code)); Check.NotNull(operationGenerator, nameof(operationGenerator)); Check.NotNull(modelGenerator, nameof(modelGenerator)); _code = code; _operationGenerator = operationGenerator; _modelGenerator = modelGenerator; }
private void Test(Action<ModelBuilder> buildModel, string expectedCode, Action<IModel> assert) { var modelBuilder = TestHelpers.Instance.CreateConventionBuilder(); buildModel(modelBuilder); var model = modelBuilder.Model; var generator = new CSharpModelGenerator(new CSharpHelper()); var builder = new IndentedStringBuilder(); generator.Generate("builder", model, builder); var code = builder.ToString(); Assert.Equal(expectedCode, code); var build = new BuildSource { References = { #if !DNXCORE50 BuildReference.ByName("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), BuildReference.ByName("System.Linq.Expressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), BuildReference.ByName("System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), #endif BuildReference.ByName("EntityFramework.Core"), BuildReference.ByName("EntityFramework.Relational") }, Sources = { @" using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Metadata.Conventions; public static class ModelSnapshot { public static IModel Model { get { var builder = new ModelBuilder(new ConventionSet()); " + code + @" return builder.Model; } } } " } }; 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); }