Exemplo n.º 1
0
        public void Expression_from_instance_method_with_variable()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products.Where(testInstance.MethodWithVariable());

                products.ToList();
            }
        }
Exemplo n.º 2
0
        public void Expression_from_instance_delegate_with_parameter()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products.Where(testInstance.DelegateWithParameter(1));

                products.ToList();
            }
        }
Exemplo n.º 3
0
        public void Scenario_Query_With_Skip_And_Take_On_SqlCe40()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products.OrderBy(p => p.Name).Skip(3).Take(2).ToList();

                Assert.Equal(2, products.Count);
                Assert.True(products.TrueForAll(p => GetStateEntry(context, p).State == EntityState.Unchanged));
            }
        }
Exemplo n.º 4
0
        public void Expression_from_instance_property()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products.Where(testInstance.Property);

                products.ToList();
            }
        }
Exemplo n.º 5
0
 public void Connection_can_be_obtained_from_DbContext_created_with_existing_ObjectContext()
 {
     using (var outerContext = new SimpleModelContext())
     {
         using (var context = new SimpleModelContext(GetObjectContext(outerContext)))
         {
             Connection_can_be_obtained_after_initializing_the_context(context);
         }
     }
 }
Exemplo n.º 6
0
        public void Connection_name_is_found_in_app_config_when_using_name_keyword()
        {
            EnsureAppConfigDatabaseExists();

            using (var context = new SimpleModelContext("name=SimpleModelInAppConfig"))
            {
                Assert.Equal("SimpleModel.SimpleModel", context.Database.Connection.Database);
                Assert.IsType <SqlConnection>(context.Database.Connection);
            }
        }
Exemplo n.º 7
0
        public void Expression_from_instance_delegate()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products.Where(testInstance.Delegate());

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 8
0
 private void EnsureAppConfigDatabaseExists()
 {
     using (var context = new SimpleModelContext("name=SimpleModelInAppConfig"))
     {
         if (!context.Database.Exists())
         {
             context.Database.Initialize(force: true);
         }
     }
 }
Exemplo n.º 9
0
 public void Connection_can_be_obtained_after_initializing_the_context_when_using_existing_store_connection()
 {
     using (var connection = SimpleConnection <SimpleModelContext>())
     {
         using (var context = new SimpleModelContext(connection))
         {
             Connection_can_be_obtained_after_initializing_the_context(context);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Asserts that an operation on a set throws if the type of the set is not valid for the model.
 /// </summary>
 /// <typeparam name="TEntity"> The type of entity for which a set should be created. </typeparam>
 /// <param name="test"> The test to run on the set. </param>
 private void ThrowsForInvalidType <TEntity>(Action <IDbSet <TEntity> > test) where TEntity : class
 {
     using (var context = new SimpleModelContext())
     {
         var set = context.Set <TEntity>();
         Assert.Throws <InvalidOperationException>(() => test(set)).ValidateMessage(
             "DbSet_EntityTypeNotInModel",
             typeof(TEntity).Name);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 ///     Asserts that an operation on a set throws if the type of the set is not valid for the model.
 /// </summary>
 /// <param name="entityType"> The type of entity for which the set is for. </param>
 /// <param name="test"> The test to run on the set. </param>
 private void ThrowsForInvalidTypeNonGeneric(Type entityType, Action <DbSet> test)
 {
     using (var context = new SimpleModelContext())
     {
         var set = context.Set(entityType);
         Assert.Throws <InvalidOperationException>(() => test(set)).ValidateMessage(
             "DbSet_EntityTypeNotInModel",
             entityType.Name);
     }
 }
Exemplo n.º 12
0
        public void Expression_from_static_method_with_parameter()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products.Where(StaticExpressions.MethodWithParameter(1));

                Assert.DoesNotThrow(() =>
                                    products.ToList());
            }
        }
Exemplo n.º 13
0
        public void Non_expression_embedded_static_method_throws()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => p.Id == StaticExpressions.NonExpressionMethod());

                Assert.Throws <NotSupportedException>(() => products.ToList());
            }
        }
Exemplo n.º 14
0
        public void Expression_from_instance_method_with_parameter()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products.Where(testInstance.MethodWithParameter(1));

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 15
0
        public void Expression_embedded_static_method_with_variable()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => context.Products.Where(StaticExpressions.MethodWithVariable())
                                      .Contains(p));

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 16
0
        public void Expression_embedded_static_delegate_with_parameter()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => context.Products.Where(StaticExpressions.DelegateWithParameter(1))
                                      .Contains(p));

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 17
0
        public void Expression_embedded_static_property()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => context.Products.Where(StaticExpressions.Property)
                                      .Contains(p));

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 18
0
        public void Expression_from_variable()
        {
            Expression <Func <Product, bool> > testExpression = p => p.Id == 1;

            using (var context = new SimpleModelContext(ConnectionString))
            {
                var products = context.Products.Where(testExpression);

                Assert.DoesNotThrow(() => products.ToList());
            }
        }
Exemplo n.º 19
0
        public void Expression_embedded_static_method_with_parameter()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => context.Products.Where(StaticExpressions.MethodWithParameter(1))
                                      .Contains(p));

                products.ToList();
            }
        }
Exemplo n.º 20
0
        public void Generic_DbEntityEntry_can_be_implicitly_converted_to_non_generic_version()
        {
            using (var context = new SimpleModelContext())
            {
                var product = context.Products.Find(1);

                var genericEntry = context.Entry(product);

                NonGenericTestMethod(genericEntry, genericEntry.Entity);
            }
        }
Exemplo n.º 21
0
        public void Non_expression_embedded_instance_delegate_throws()
        {
            using (var context = new SimpleModelContext())
            {
                var testInstance = new InstanceExpressions();
                var products     = context.Products
                                   .Where(p => p.Id == testInstance.NonExpressionDelegate());

                Assert.Throws <NotSupportedException>(() => products.ToList());
            }
        }
Exemplo n.º 22
0
        public void SQL_query_for_non_entity_where_columns_dont_map_throws()
        {
            using (var context = new SimpleModelContext())
            {
                var query = context.Database.SqlQuery <UnMappedProduct>("select * from Categories");

                Assert.Throws <InvalidOperationException>(() => query.ToList()).ValidateMessage(
                    "Materializer_InvalidCastReference", "System.String",
                    "System.Int32");
            }
        }
        /// <summary>
        /// Creates a disposed context.
        /// </summary>
        private SimpleModelContext CreateDisposedContext()
        {
            SimpleModelContext context;

            using (context = new SimpleModelContext())
            {
                // Ensures that the context actually gets initialized.
                var objectContext = GetObjectContext(context);
            }
            return(context);
        }
Exemplo n.º 24
0
 public void DbContext_SaveChangesAsync_does_not_deadlock()
 {
     using (var context = new SimpleModelContext())
     {
         using (context.Database.BeginTransaction())
         {
             context.Products.Add(new Product());
             RunDeadlockTest(context.SaveChangesAsync);
         }
     }
 }
Exemplo n.º 25
0
        public void SQL_query_for_entity_where_columns_dont_map_throws()
        {
            using (var context = new SimpleModelContext())
            {
                var query = context.Products.SqlQuery("select * from Categories");

                Assert.Throws <EntityCommandExecutionException>(() => query.ToList()).ValidateMessage(
                    "ADP_InvalidDataReaderMissingColumnForType",
                    "SimpleModel.Product", "CategoryId");
            }
        }
Exemplo n.º 26
0
        public void Expression_from_variable()
        {
            Expression <Func <Product, bool> > testExpression = p => p.Id == 1;

            using (var context = new SimpleModelContext())
            {
                var products = context.Products.Where(testExpression);

                products.ToList();
            }
        }
Exemplo n.º 27
0
        public void Expression_embedded_static_delegate()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products
                               .Where(p => context.Products.Where(StaticExpressions.Delegate())
                                      .Contains(p));

                products.ToList();
            }
        }
Exemplo n.º 28
0
        public void Scenario_Query()
        {
            using (var context = new SimpleModelContext())
            {
                var products = context.Products.ToList();

                // Scenario ends; simple validation of final state follows
                Assert.Equal(7, products.Count);
                Assert.True(products.TrueForAll(p => GetStateEntry(context, p).State == EntityState.Unchanged));
            }
        }
Exemplo n.º 29
0
        public void Initialization_hooks_are_run_once_on_EF_initialization_in_the_app_domain()
        {
            // Make sure that EF has been used if this happens to be the first test run
            using (var context = new SimpleModelContext())
            {
                context.Database.Initialize(force: false);
            }

            Assert.Equal(
                new[] { "Hook1()", "Hook1(2013, 'December 31')", "Hook2()", "Hook2('January 1', 2014)", "Hook2()", "Hook1(4102, '1 yraunaJ')", "Hook1()" },
                TestLoadedInterceptor.HooksRun.Reverse().ToArray());
        }
Exemplo n.º 30
0
        // TODO: [Fact(Skip = "SDE Merge - No partial trust yet")]
        public void DbEntityEntry_Member_works_for_collections_under_partial_trust()
        {
            using (var context = new SimpleModelContext())
            {
                var category = context.Categories.First();

                var collection = context.Entry(category).Member <ICollection <Product> >("Products");

                Assert.NotNull(collection);
                Assert.IsType <DbCollectionEntry <Category, Product> >(collection);
            }
        }