示例#1
0
        public void DetectChanges_does_not_consider_change_tracking_proxies_with_no_complex_types()
        {
            using (var context = new ProxiesContext())
            {
                for (var i = 0; i < 2; i++)
                {
                    var product = context.Products.Create();
                    product.Id = i;
                    product.Name = "Marmite";
                    product.Properties = new ProductProperties
                                             {
                                                 SpecialOfferCode = "YEAST",
                                                 StockCount = 77,
                                                 UnitCost = 1.99m
                                             };

                    var category = context.Categories.Create();
                    category.Id = i;
                    category.Name = "Foods";
                    category.Products.Add(product);

                    context.Categories.Attach(category);
                }

                ProxyCategory.ReadCount = 0;
                ProxyProduct.ReadCount = 0;

                context.ChangeTracker.DetectChanges();

                Assert.Equal(0, ProxyCategory.ReadCount);
                Assert.Equal(2, ProxyProduct.ReadCount);
            }
        }
        public void Change_tracking_of_mutated_complex_types_happens_correctly_for_proxies()
        {
            using (var context = new ProxiesContext())
            {
                var product = context.Products.Create();
                product.Id = 1;
                product.Name = "Marmite";
                product.Properties = new ProductProperties
                                     { SpecialOfferCode = "YEAST", StockCount = 77, UnitCost = 1.99m };

                context.Products.Attach(product);

                product.Properties.StockCount = 75;

                context.ChangeTracker.DetectChanges();

                Assert.Equal(EntityState.Modified, context.Entry(product).State);
                Assert.True(context.Entry(product).Property(p => p.Properties).IsModified);
            }
        }
示例#3
0
        public void Lazy_loading_proxy_can_be_data_contract_deserialized_with_known_types_when_running_under_partial_trust()
        {
            using (var context = new ProxiesContext())
            {
                var proxy = context.MeLazyLoads.Create();
                Assert.False(proxy is IEntityWithRelationships);
                proxy.Id = 77;

                var otherProxy = context.MeTrackChanges.Create();

                var stream     = new MemoryStream();
                var serializer = new DataContractSerializer(
                    proxy.GetType(), new[] { proxy.GetType(), otherProxy.GetType() }, int.MaxValue, false, true, null);

                serializer.WriteObject(stream, proxy);
                stream.Seek(0, SeekOrigin.Begin);
                var deserialized = (MeLazyLoad)serializer.ReadObject(stream);

                Assert.Same(proxy.GetType(), deserialized.GetType());
                Assert.Equal(77, deserialized.Id);
            }
        }
        public void Change_tracking_of_mutated_complex_types_happens_correctly_for_proxies()
        {
            using (var context = new ProxiesContext())
            {
                var product = context.Products.Create();
                product.Id         = 1;
                product.Name       = "Marmite";
                product.Properties = new ProductProperties
                {
                    SpecialOfferCode = "YEAST",
                    StockCount       = 77,
                    UnitCost         = 1.99m
                };

                context.Products.Attach(product);

                product.Properties.StockCount = 75;

                context.ChangeTracker.DetectChanges();

                Assert.Equal(EntityState.Modified, context.Entry(product).State);
                Assert.True(context.Entry(product).Property(p => p.Properties).IsModified);
            }
        }
        public void Lazy_loading_proxy_can_be_data_contract_deserialized_with_known_types_when_running_under_partial_trust()
        {
            using (var context = new ProxiesContext())
            {
                var proxy = context.MeLazyLoads.Create();
                Assert.False(proxy is IEntityWithRelationships);
                proxy.Id = 77;

                var otherProxy = context.MeTrackChanges.Create();

                var stream = new MemoryStream();
                var serializer = new DataContractSerializer(
                    proxy.GetType(), new[] { proxy.GetType(), otherProxy.GetType() }, int.MaxValue, false, true, null);

                serializer.WriteObject(stream, proxy);
                stream.Seek(0, SeekOrigin.Begin);
                var deserialized = (MeLazyLoad)serializer.ReadObject(stream);

                Assert.Same(proxy.GetType(), deserialized.GetType());
                Assert.Equal(77, deserialized.Id);
            }
        }
        public void Lazy_loading_proxy_can_be_data_contract_deserialized_with_resolver_when_running_under_partial_trust()
        {
            using (var context = new ProxiesContext())
            {
                var proxy = context.MeLazyLoads.Create();
                Assert.False(proxy is IEntityWithRelationships);

                proxy.Id = 77;

                var stream = new MemoryStream();
                var serializer = new DataContractSerializer(
                    typeof(MeLazyLoad), null, int.MaxValue, false, true, null, new ProxyDataContractResolver());

                serializer.WriteObject(stream, proxy);
                stream.Seek(0, SeekOrigin.Begin);
                var deserialized = (MeLazyLoad)serializer.ReadObject(stream);

                Assert.IsType<MeLazyLoad>(deserialized); // Resolver returns non-proxy type
                Assert.Equal(77, deserialized.Id);
            }
        }
 public void Resolve_handler_is_added_for_assembly_when_running_under_full_trust()
 {
     using (var context = new ProxiesContext())
     {
         var proxy = context.MeLazyLoads.Create();
         Assert.Same(proxy.GetType(), Type.GetType(proxy.GetType().AssemblyQualifiedName));
     }
 }
 public void Resolve_handler_is_not_added_for_assembly_when_running_under_partial_trust()
 {
     using (var context = new ProxiesContext())
     {
         Assert.Null(Type.GetType(context.MeLazyLoads.Create().GetType().AssemblyQualifiedName));
     }
 }
 public void Change_tracking_proxy_can_be_created_under_partial_trust()
 {
     using (var context = new ProxiesContext())
     {
         var proxy = context.MeTrackChanges.Create();
         Assert.IsNotType<MeTrackChanges>(proxy);
         Assert.True(proxy is IEntityWithChangeTracker);
     }
 }
 public void Lazy_loading_proxy_can_be_created_under_partial_trust()
 {
     using (var context = new ProxiesContext())
     {
         var proxy = context.MeLazyLoads.Create();
         Assert.IsNotType<MeLazyLoad>(proxy);
         Assert.False(proxy is IEntityWithChangeTracker);
     }
 }