public void NoSurrogateSample()
        {
            var tester = new XmlDataContractSerializerTester <Person>(
                new DataContractSerializer(typeof(Person)), true);

            tester.SerializeAndDeserialize(person);
        }
Beispiel #2
0
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            OrderDetailSurrogate orderDetailSurrogate = new OrderDetailSurrogate();
            SurrogateSelector    selector             = new SurrogateSelector();

            selector.AddSurrogate(typeof(Order_Detail), new StreamingContext(StreamingContextStates.All), orderDetailSurrogate);

            var serializer = new NetDataContractSerializer
            {
                SurrogateSelector = selector
            };

            var tester        = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(serializer, true);
            var objectContext = (dbContext as IObjectContextAdapter).ObjectContext;
            var orderDetails  = dbContext.Order_Details.ToList();

            foreach (var detail in orderDetails)
            {
                objectContext.LoadProperty(detail, d => d.Order);
            }


            tester.SerializeAndDeserialize(orderDetails);
        }
Beispiel #3
0
        public void IDataContractSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = true;
            dbContext.Configuration.LazyLoadingEnabled   = true;
            List <Type> knownTypes = new List <Type>();

            knownTypes.Add(typeof(Category));
            knownTypes.Add(typeof(Customer));
            knownTypes.Add(typeof(CustomerDemographic));
            knownTypes.Add(typeof(Employee));
            knownTypes.Add(typeof(Northwind));
            knownTypes.Add(typeof(Order));
            knownTypes.Add(typeof(Order_Detail));
            knownTypes.Add(typeof(Product));
            knownTypes.Add(typeof(Region));
            knownTypes.Add(typeof(Shipper));
            knownTypes.Add(typeof(Supplier));
            knownTypes.Add(typeof(Territory));

            var typeSettings = new DataContractSerializerSettings()
            {
                DataContractResolver = new ProxyDataContractResolver(),
                KnownTypes           = knownTypes
            };

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order> >(new DataContractSerializer(typeof(IEnumerable <Order>), typeSettings), true);
            var orders = dbContext.Orders.ToList();

            tester.SerializeAndDeserialize(orders);
        }
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var streamingContext  = new StreamingContext(StreamingContextStates.All, dbContext);
            var surrogateSelector = new SurrogateSelector();

            surrogateSelector.AddSurrogate(
                typeof(Order_Detail),
                streamingContext,
                new OrderDetailSerializerSurrogate());
            surrogateSelector.AddSurrogate(
                typeof(Product),
                streamingContext,
                new ProductSerializerSurrogate());

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(new NetDataContractSerializer(
                                                                                               streamingContext,
                                                                                               int.MaxValue,
                                                                                               true,
                                                                                               FormatterAssemblyStyle.Simple,
                                                                                               surrogateSelector
                                                                                               ), true);

            var orderDetails = dbContext.Order_Details.ToList();

            tester.SerializeAndDeserialize(orderDetails);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var dbContext = new Northwind();

            dbContext.Configuration.ProxyCreationEnabled = true;
            dbContext.Configuration.LazyLoadingEnabled   = true;

            StreamingContext sc = new StreamingContext(
                StreamingContextStates.CrossProcess, (dbContext as IObjectContextAdapter).ObjectContext);

            SurrogateSelector ss = new SurrogateSelector();

            ss.AddSurrogate(typeof(Order_Detail),
                            sc,
                            new Order_DetailSerializationSurrogate());

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order> >(new DataContractSerializer(typeof(IEnumerable <Order>), new DataContractSerializerSettings {
                DataContractSurrogate = new OrderDataContractSurrogate(), PreserveObjectReferences = false
            }), true);
            var orders = dbContext.Orders.ToList();

            tester.SerializeAndDeserialize(orders);

            Console.ReadKey();
        }
Beispiel #6
0
        public void IDataContractSurrogate()
        {
            #region ARRANGE

            _dbContext.Configuration.ProxyCreationEnabled = true;
            _dbContext.Configuration.LazyLoadingEnabled   = true;

            #endregion

            #region ACT

            var settings = new DataContractSerializerSettings
            {
                DataContractSurrogate = new OrderDataContractSurrogate()
            };
            var tester = new XmlDataContractSerializerTester <IEnumerable <Order> >(
                new DataContractSerializer(
                    typeof(IEnumerable <Order>),
                    settings),
                true);
            var orders = _dbContext.Orders.ToList();

            #endregion

            #region ASSERT

            tester.SerializeAndDeserialize(orders);

            #endregion
        }
Beispiel #7
0
        public void ISerializationSurrogate()
        {
            #region ARRANGE

            _dbContext.Configuration.ProxyCreationEnabled = false;

            #endregion

            #region ACT

            var selector = new SurrogateSelector();
            selector.AddSurrogate(typeof(Order_Detail),
                                  new StreamingContext(StreamingContextStates.All, _dbContext),
                                  new OrderDetailSerializationSurrogate());

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(
                new NetDataContractSerializer
            {
                SurrogateSelector = selector,
                Context           = new StreamingContext(StreamingContextStates.All, _dbContext)
            },
                true);
            var orderDetails = _dbContext.Order_Details.ToList();

            #endregion

            #region ASSERT

            tester.SerializeAndDeserialize(orderDetails);

            #endregion
        }
        public void SerializationCallbacks()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;
            var categories = dbContext.Categories.ToList();
            var tester     = new XmlDataContractSerializerTester <IEnumerable <Category> >(new NetDataContractSerializer(new StreamingContext(StreamingContextStates.All, dbContext.Products.ToList())), true);

            tester.SerializeAndDeserialize(categories);
        }
        public void ISerializable2()
        {
            dbContext.Configuration.LazyLoadingEnabled   = false;
            dbContext.Configuration.ProxyCreationEnabled = false;
            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var products = dbContext.Products.Include("Category").AsNoTracking().ToList();

            tester.SerializeAndDeserialize(products);
        }
        public void SerializationCallbacks()
        {
            _dbContext.Configuration.ProxyCreationEnabled = false;

            var tester     = new XmlDataContractSerializerTester <IEnumerable <Category> >(new NetDataContractSerializer(), true);
            var categories = _dbContext.Categories.Include("Products").ToList();

            var categoriesDeserialize = tester.SerializeAndDeserialize(categories);
        }
        public void ISerializable()
        {
            _dbContext.Configuration.ProxyCreationEnabled = false;

            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var products = _dbContext.Products.Include("Order_Details").Include("Category").Include("Supplier").ToList();

            var productsDeserialize = tester.SerializeAndDeserialize(products);
        }
Beispiel #12
0
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var tester       = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(new NetDataContractSerializer(), true);
            var orderDetails = dbContext.Order_Details.ToList();

            tester.SerializeAndDeserialize(orderDetails);
        }
Beispiel #13
0
        public void ISerializable()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var products = dbContext.Products.ToList();

            tester.SerializeAndDeserialize(products);
        }
Beispiel #14
0
        public void IDataContractSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = true;
            dbContext.Configuration.LazyLoadingEnabled   = true;

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order> >(new DataContractSerializer(typeof(IEnumerable <Order>)), true);
            var orders = dbContext.Orders.ToList();

            tester.SerializeAndDeserialize(orders);
        }
Beispiel #15
0
        public void ISerializable()
        {
            _dbContext.Configuration.ProxyCreationEnabled = false;

            var streamingContext = new StreamingContext(StreamingContextStates.All, _dbContext);
            var tester           = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(streamingContext), true);
            var products         = _dbContext.Products.ToList();

            tester.SerializeAndDeserialize(products);
        }
        public void SurrogateSample()
        {
            var tester = new XmlDataContractSerializerTester <Person>(
                new DataContractSerializer(
                    typeof(Person),
                    new DataContractSerializerSettings {
                DataContractSurrogate = new PersonSurrogate()
            }), true);
            var person2 = tester.SerializeAndDeserialize(person);

            Console.WriteLine("{0} : {1}", person2.Credentials.Login, person2.Credentials.Password);
        }
        public void XmlDataContractSerializer()
        {
            var tester = new XmlDataContractSerializerTester <D>(
                new DataContractSerializer(typeof(D)), true);
            var d1 = new D()
            {
                PropertyA = "AAAAA"
            };
            var d2 = tester.SerializeAndDeserialize(d1);

            Console.WriteLine(d1.PropertyA);
            Console.WriteLine(d2.PropertyA);
        }
        public void XmlDataContractSerializer()
        {
            var tester = new XmlDataContractSerializerTester <E>(
                new DataContractSerializer(typeof(E)), true);
            var e1 = new E()
            {
                PropertyA = "EEEEE"
            };
            var e2 = tester.SerializeAndDeserialize(e1);

            Console.WriteLine(e1.PropertyA);
            Console.WriteLine(e2.PropertyA);
        }
Beispiel #19
0
        public void XmlDataContractSerializer()
        {
            var tester = new XmlDataContractSerializerTester <C>(
                new DataContractSerializer(typeof(C)), true);
            var c1 = new C()
            {
                PropertyA = "11111111"
            };
            var c2 = tester.SerializeAndDeserialize(c1);

            Console.WriteLine(c1.PropertyA);
            Console.WriteLine(c2.PropertyA);
        }
 public void IDataContractSurrogate()
 {
     _dbContext.Configuration.ProxyCreationEnabled = true;
     _dbContext.Configuration.LazyLoadingEnabled   = true;
     var settings = new DataContractSerializerSettings
     {
         DataContractSurrogate = new OrdersContractSurrogate()
     };
     var serializer = new DataContractSerializer(typeof(IEnumerable <Order>), settings);
     var tester     = new XmlDataContractSerializerTester <IEnumerable <Order> >(serializer, true);
     var orders     = _dbContext.Orders.ToList();
     var result     = tester.SerializeAndDeserialize(orders);
 }
        public void SerializationCallbacks()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var tester = new XmlDataContractSerializerTester <IEnumerable <Category> >(new NetDataContractSerializer(), true);

            var objectContext = (dbContext as IObjectContextAdapter).ObjectContext;

            var categories = dbContext.Categories.Take(3).ToList();

            categories.ForEach(category => objectContext.LoadProperty(category, c => c.Products));

            tester.SerializeAndDeserialize(categories);
        }
        public void ISerializable3()
        {
            dbContext.Configuration.LazyLoadingEnabled   = false;
            dbContext.Configuration.ProxyCreationEnabled = false;
            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var products = dbContext.Products.ToList().Select(x => new Product()
            {
                ProductID = 1, Category = new Category()
                {
                    CategoryID = 1
                }
            }).ToList();

            tester.SerializeAndDeserialize(products);
        }
        public void ISerializable()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var products = dbContext.Products.Include("Category").ToList();

            var res = tester.SerializeAndDeserialize(products);

            Assert.IsTrue(res.Any());
            foreach (var product in res)
            {
                Assert.IsNotNull(product.Category);
            }
        }
        public void ISerializable()
        {
            dbContext.Configuration.LazyLoadingEnabled   = false;
            dbContext.Configuration.ProxyCreationEnabled = false;
            var tester   = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(), true);
            var t        = (dbContext as IObjectContextAdapter).ObjectContext;
            var products = dbContext.Products.ToList();

            foreach (var product in products)
            {
                t.LoadProperty(product, f => f.Category);
            }

            tester.SerializeAndDeserialize(products);
        }
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var tester = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(new NetDataContractSerializer(), true);

            var objectContext = (dbContext as IObjectContextAdapter).ObjectContext;

            var orderDetails = dbContext.Order_Details.Take(3).ToList();

            orderDetails.ForEach(product => objectContext.LoadProperty(product, c => c.Order));
            orderDetails.ForEach(product => objectContext.LoadProperty(product, c => c.Product));

            tester.SerializeAndDeserialize(orderDetails);
        }
        public void SerializationEvents()
        {
            var settings = new DataContractSerializerSettings
            {
                DataContractResolver = new ProxyDataContractResolver()
            };

            var tester = new XmlDataContractSerializerTester<IEnumerable<Category>>(
                _testOutputHelper,
                new DataContractSerializer(typeof (IEnumerable<Category>), settings),
                true);

            List<Category> categories = _dbContext.Categories.ToList();

            var deserializedCategories = tester.SerializeAndDeserialize(categories).ToList();
        }
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;
            var t = (dbContext as IObjectContextAdapter).ObjectContext;

            var tester       = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(new NetDataContractSerializer(new StreamingContext(StreamingContextStates.All), int.MaxValue, false, System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full, new OrderDetailSurrogateSelector()), true);
            var orderDetails = dbContext.Order_Details.ToList();

            foreach (var od in orderDetails)
            {
                t.LoadProperty(od, f => f.Order);
                t.LoadProperty(od, f => f.Product);
            }

            tester.SerializeAndDeserialize(orderDetails);
        }
        public void ISerializable()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;

            var serializationContext = new SerializationContext
            {
                ObjectContext   = (dbContext as IObjectContextAdapter).ObjectContext,
                TypeToSerialize = typeof(Product)
            };

            var tester = new XmlDataContractSerializerTester <IEnumerable <Product> >(new NetDataContractSerializer(
                                                                                          new StreamingContext(StreamingContextStates.All, serializationContext)), true);
            var products = dbContext.Products.ToList();

            tester.SerializeAndDeserialize(products);
        }
        public void IDataContractSurrogate()
        {
            var orders = dbContext.Orders.ToArray();
            var knownTypes = new List<Type>
            {
                typeof (Order)
            };

            IDataContractSurrogate surrogate = new OrderSurrogate();
            var tester = new XmlDataContractSerializerTester<IEnumerable<Order>>(
                new DataContractSerializer(typeof(IEnumerable<Order>), knownTypes, Int32.MaxValue, false, true,
                    surrogate),
                true);

            tester.SerializeAndDeserialize(orders);
        }
		public void ISerializationSurrogate()
		{
			dbContext.Configuration.ProxyCreationEnabled = false;

            var serializationContext = new SerializationContexts
            {
                ObjectContext = (dbContext as IObjectContextAdapter).ObjectContext,
                TypeToSerialize = typeof(Product)
            };

            var xmlSerializer = new NetDataContractSerializer(new StreamingContext(StreamingContextStates.All, serializationContext));
            var tester = new XmlDataContractSerializerTester<IEnumerable<Order_Detail>>(xmlSerializer, true);
			var orderDetails = dbContext.Order_Details.ToList();

            tester.SerializeAndDeserialize(orderDetails);
		}
		public void SerializationCallbacks()
		{
			dbContext.Configuration.ProxyCreationEnabled = false;

            var serializationContext = new SerializationContexts
            {
                ObjectContext = (dbContext as IObjectContextAdapter).ObjectContext,
                TypeToSerialize = typeof(Category)
            };
            var xmlSerializer = new NetDataContractSerializer(new StreamingContext(StreamingContextStates.All, serializationContext));
            
            var tester = new XmlDataContractSerializerTester<IEnumerable<Category>>(xmlSerializer, true);
			var categories = dbContext.Categories.ToList();

			tester.SerializeAndDeserialize(categories);
		}
        public void ISerializable()
        {
            var settings = new DataContractSerializerSettings
            {
                DataContractResolver = new ProxyDataContractResolver(),
                KnownTypes = new List<Type>() {typeof (Supplier)}
            };

            var tester = new XmlDataContractSerializerTester<IEnumerable<Product>>(
                _testOutputHelper,
                new DataContractSerializer(typeof (IEnumerable<Product>), settings),
                true);

            var products = _dbContext.Products.ToList();

            var deserializedOrders = tester.SerializeAndDeserialize(products);
        }
Beispiel #33
0
        public void ISerializationSurrogate()
        {
            dbContext.Configuration.ProxyCreationEnabled = false;
            var selector = new SurrogateSelector();

            selector.AddSurrogate(type: typeof(Order_Detail),
                                  context: new StreamingContext(StreamingContextStates.All, dbContext),
                                  surrogate: new Order_DetailsSerializationSurrogate()
                                  );
            var serializer = new NetDataContractSerializer();

            serializer.SurrogateSelector = selector;
            var tester       = new XmlDataContractSerializerTester <IEnumerable <Order_Detail> >(serializer, true);
            var orderDetails = dbContext.Order_Details.ToList();

            tester.SerializeAndDeserialize(orderDetails);
        }
        public void ISerializable()
        {
            var dataContractSerializerSettings = new DataContractSerializerSettings
            {
                DataContractResolver = this.resolver
            };

            var dataContractSerializer = new DataContractSerializer(
                typeof(IEnumerable<Product>),
                dataContractSerializerSettings);

            var products = this.context.Products.ToList();

            var tester = new XmlDataContractSerializerTester<IEnumerable<Product>>(dataContractSerializer, true);

            var productsBack = tester.SerializeAndDeserialize(products);
        }
        public void ISerializable()
        {
            var products =
                dbContext.Products.Include(x => x.Category)
                    .Include(x => x.Supplier)
                    .Include(x => x.Order_Details)
                    .ToList();

            var knownTypes = new List<Type>
            {
                typeof (HashSet<Order_Detail>),
                typeof (Supplier),
                typeof (Category)
            };

            var tester =
                new XmlDataContractSerializerTester<IEnumerable<Product>>(
                    new DataContractSerializer(typeof(IEnumerable<Product>)
                        , knownTypes, int.MaxValue, false, true, null), true);

            tester.SerializeAndDeserialize(products);
        }
        public void SerializationEvents()
        {
            var categories = dbContext.Categories.Include(x => x.Products).ToList();

            var knownTypes = new List<Type>
            {
                typeof (HashSet<Order_Detail>)
            };

            var tester =
                new XmlDataContractSerializerTester<IEnumerable<Category>>(
                    new DataContractSerializer(typeof(IEnumerable<Category>)
                        , knownTypes, int.MaxValue, false, true, null), true);

            tester.SerializeAndDeserialize(categories);
        }
        public void IDataContractSurrogate()
        {
            var settings = new DataContractSerializerSettings
            {
                DataContractResolver = new ProxyDataContractResolver(),
                DataContractSurrogate = new OrderDataContractSurrogate(),
            };

            var tester = new XmlDataContractSerializerTester<IEnumerable<Order>>(
                _testOutputHelper,
                new DataContractSerializer(typeof(IEnumerable<Order>), settings),
                true);

            var orders = _dbContext.Orders.Take(10).ToList();

            var deserializedOrders = tester.SerializeAndDeserialize(orders);
        }
        public void SerializationCallbacks()
        {
            var dataContractSerializerSettings = new DataContractSerializerSettings
            {
                DataContractResolver = this.resolver
            };
            var dataContractSerializer = new DataContractSerializer(typeof(Category), dataContractSerializerSettings);

            var tester = new XmlDataContractSerializerTester<Category>(dataContractSerializer, true);

            var category = this.context.Categories.First();

            var categoryBack = tester.SerializeAndDeserialize(category);
        }