public void Loading_related_entity_that_overrides_GetHashCode_shouldnt_throw()
 {
     using (var context = new GetHashCodeContext())
     {
         Assert.NotNull(context.Products.First().Skus.First());
     }
 }
        public void Removing_from_Local_entities_that_override_Equals_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                context.Skus.Load();
                Assert.Equal(2, context.Skus.Local.Count());

                context.Skus.Local.ToList().ForEach(s => context.Skus.Remove(s));
                Assert.Equal(0, context.Skus.Local.Count());
            }
        }
        public void Changing_the_value_of_a_complex_property_on_an_entity_that_overrides_GetHashCode_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                var product = context.Products.Single(p => p.Id == "ALFKI");
                product.Details.Name = "New Name";

                ((IObjectContextAdapter)context).ObjectContext.DetectChanges();

                Assert.Equal(EntityState.Modified, context.Entry(product).State);
            }
        }
        public void Serializing_an_entity_that_overrides_GetHashCode_shouldnt_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                var skuProxy = context.Skus.Create();
                skuProxy.Parent = context.Skus.Create();

                var stream    = new MemoryStream();
                var formatter = new BinaryFormatter();

                formatter.Serialize(stream, skuProxy);
            }
        }
        public void Join_query_on_a_collection_of_entities_that_override_GetHashCode_shouldnt_throw()
        {
            using (var db = new GetHashCodeContext())
            {
                var query = from p in db.Products
                            join s in db.Skus on p equals s.Product into ps
                            select new
                {
                    Product = p,
                    Foo     = ps
                };

                Assert.Equal(1, query.Count());
            }
        }
        public void Attach_and_Remove_on_an_entity_that_overrides_GetHashCode_shouldnt_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                var product = context.Products.First();

                var sku = new GetHashCodeSku
                {
                    Name      = "Sprinkled",
                    ProductId = product.Id
                };

                product.DeprecatedSkus.Add(sku);
                context.Products.Attach(product);
                context.Products.Remove(product);
            }
        }
        public void Changing_the_complex_property_on_an_entity_that_overrides_Equals_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                var product = context.Products.Single(p => p.Id == "ALFKI");
                var entry   = context.Entry(product);
                entry.ComplexProperty(b => b.Details).CurrentValue = new GetHashCodeProductDetails
                {
                    Name = "New Details"
                };

                ((IObjectContextAdapter)context).ObjectContext.DetectChanges();

                Assert.Equal(EntityState.Modified, context.Entry(product).State);
                Assert.Equal("New Details", product.Details.Name);
            }
        }
        public void Local_on_an_entitySet_of_entities_that_override_Equals_shouldnt_throw()
        {
            using (var context = new GetHashCodeContext())
            {
                context.Skus.Add(
                    new GetHashCodeSku
                {
                    Name = "Student"
                });
                context.Skus.Add(
                    new GetHashCodeSku
                {
                    Name = "Home"
                });

                Assert.Equal(2, context.Skus.Local.Count());
            }
        }