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); } } }
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); } } }
protected void VerifySetsAreInitialized <TContext>( DbCompiledModelContents contents, DbProviderInfo providerInfo = null) where TContext : SimpleModelContextWithNoData { providerInfo = providerInfo ?? ProviderRegistry.Sql2008_ProviderInfo; // 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(providerInfo).Compile(); // Act using (var context = (TContext)Activator.CreateInstance(typeof(TContext), model)) { // Verification as appropriate for the various model content options switch (contents) { case DbCompiledModelContents.IsEmpty: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsNotInModel(); context.Assert <Product>().IsNotInModel(); break; case DbCompiledModelContents.IsSubset: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsInModel(); context.Assert <Product>().IsInModel(); // reachability break; case DbCompiledModelContents.IsSuperset: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); context.Assert <Category>().IsInModel(); context.Assert <Product>().IsInModel(); context.Assert <Login>().IsInModel(); break; case DbCompiledModelContents.Match: Assert.NotNull(context.Categories); Assert.NotNull(context.Products); 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); } } }
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 = "Scenario_Use_SqlCe_AppConfig_connection_string"; break; case ConnectionStringFormat.ProviderConnectionString: connectionString = SimpleCeConnectionString <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.SqlCe4_ProviderInfo). Compile())) { // Assert 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); } } }