public void Sets_are_initialized_but_do_not_change_model_using_name_and_model_constructor_on_DbContext() { var model = new DbModelBuilder().Build(ProviderRegistry.Sql2008_ProviderInfo).Compile(); using (var context = new SimpleModelContextWithNoData(DefaultDbName<EmptyContext>(), model)) { Assert.NotNull(context.Products); Assert.NotNull(context.Categories); context.Assert<Product>().IsNotInModel(); context.Assert<Category>().IsNotInModel(); } }
private void Verify_DbContext_construction_using_connection_string_ctor(string nameOrConnectionString, string expectedDatabaseName = "SimpleModel.SimpleModelContextWithNoData") { using (var context = new SimpleModelContextWithNoData(nameOrConnectionString)) { Assert.NotNull(context.Products); Assert.NotNull(context.Categories); context.Assert<Product>().IsInModel(); context.Assert<Category>().IsInModel(); Assert.Equal(expectedDatabaseName, context.Database.Connection.Database); } }
private void DbContext_construction_using_connection_string_and_model_Ctor( ConnectionStringFormat connStringFormat, DbCompiledModelContents modelContents) { // Act // Setup connection string string connectionString = null; string dbName = null; switch (connStringFormat) { case ConnectionStringFormat.DatabaseName: connectionString = dbName = DefaultDbName<SimpleModelContextWithNoData>(); break; case ConnectionStringFormat.NamedConnectionString: connectionString = "SimpleModelWithNoDataFromAppConfig"; dbName = "SimpleModel.SimpleModelWithNoData"; break; case ConnectionStringFormat.ProviderConnectionString: connectionString = SimpleConnectionString<SimpleModelContextWithNoData>(); dbName = "SimpleModel.SimpleModelContextWithNoData"; break; default: throw new ArgumentException("Invalid ConnectionStringFormat enum supplied " + connStringFormat); } // Setup DbCompiledModel var builder = new DbModelBuilder(); switch (modelContents) { case DbCompiledModelContents.IsEmpty: // Do nothing as builder has already been initialized break; case DbCompiledModelContents.IsSubset: // Product is not defined here builder.Entity<Category>(); break; case DbCompiledModelContents.IsSuperset: builder.Entity<Category>(); builder.Entity<Product>(); builder.Entity<Login>(); break; case DbCompiledModelContents.Match: builder.Entity<Category>(); builder.Entity<Product>(); break; case DbCompiledModelContents.DontMatch: builder.Entity<FeaturedProduct>(); builder.Entity<Login>(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + modelContents); } // Act using ( var context = new SimpleModelContextWithNoData(connectionString, builder.Build(ProviderRegistry.Sql2008_ProviderInfo). Compile())) { // Assert Assert.Equal(context.Database.Connection.Database, dbName); switch (modelContents) { case DbCompiledModelContents.IsEmpty: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsNotInModel(); context.Assert<Product>().IsNotInModel(); break; case DbCompiledModelContents.IsSubset: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); // reachability break; case DbCompiledModelContents.IsSuperset: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); context.Assert<Login>().IsInModel(); break; case DbCompiledModelContents.Match: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); context.Assert<Login>().IsNotInModel(); break; case DbCompiledModelContents.DontMatch: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert<Login>().IsInModel(); context.Assert<FeaturedProduct>().IsInModel(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + modelContents); } } }
private void Verify_DbContext_construction_using_connection_and_model_Ctor( DbConnection connection, DbCompiledModelContents contents) { // Arrange // DbCompiledModel creation as appropriate for the various model content options var builder = new DbModelBuilder(); switch (contents) { case DbCompiledModelContents.IsEmpty: // Do nothing as builder has already been initialized break; case DbCompiledModelContents.IsSubset: // Product is not defined here builder.Entity<Category>(); break; case DbCompiledModelContents.IsSuperset: builder.Entity<Category>(); builder.Entity<Product>(); builder.Entity<Login>(); break; case DbCompiledModelContents.Match: builder.Entity<Category>(); builder.Entity<Product>(); break; case DbCompiledModelContents.DontMatch: builder.Entity<FeaturedProduct>(); builder.Entity<Login>(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + contents); } var model = builder.Build(connection).Compile(); // Act using (var context = new SimpleModelContextWithNoData(connection, model)) { // Verification as appropriate for the various model content options switch (contents) { case DbCompiledModelContents.IsEmpty: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsNotInModel(); context.Assert<Product>().IsNotInModel(); break; case DbCompiledModelContents.IsSubset: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); // Reachability break; case DbCompiledModelContents.IsSuperset: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); context.Assert<Login>().IsInModel(); break; case DbCompiledModelContents.Match: Assert.NotNull(context.Categories); Assert.NotNull(context.Categories); context.Assert<Category>().IsInModel(); context.Assert<Product>().IsInModel(); context.Assert<Login>().IsNotInModel(); break; case DbCompiledModelContents.DontMatch: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert<Login>().IsInModel(); context.Assert<FeaturedProduct>().IsInModel(); break; default: throw new ArgumentException("Invalid DbCompiledModelContents Arguments passed in, " + contents); } } }