public void CircularReferenceDetectionAcrossTypes()
 {
     ExportContext context = new ExportContext();
     ComponentExporter exporter = new ComponentExporter(typeof(Parent));
     context.Register(exporter);
     context.Register(new ComponentExporter(typeof(ParentChild)));
     Parent parent = new Parent();
     parent.Child = new ParentChild();
     parent.Child.Parent = parent;
     exporter.Export(context, parent, new EmptyJsonWriter());
 }
        public void CircularReferenceDetectionAcrossTypes()
        {
            ExportContext     context  = new ExportContext();
            ComponentExporter exporter = new ComponentExporter(typeof(Parent));

            context.Register(exporter);
            context.Register(new ComponentExporter(typeof(ParentChild)));
            Parent parent = new Parent();

            parent.Child        = new ParentChild();
            parent.Child.Parent = parent;
            exporter.Export(context, parent, new EmptyJsonWriter());
        }
Beispiel #3
0
            public Builder Register(ExportContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException(nameof(context));
                }

                context.Register(new ComponentExporter(_type, ToCustomType()));
                return(this);
            }
        public void TableExportedViaDataView()
        {
            DataTable table = new DataTable();

            ExportContext context = new ExportContext();
            TestDataViewExporter exporter = new TestDataViewExporter();
            context.Register(exporter);
            context.Export(table, new JsonRecorder());

            Assert.AreSame(table.DefaultView, exporter.LastExported);
        }
Beispiel #5
0
        public void ImmediateCircularReferenceDetection()
        {
            var context  = new ExportContext();
            var exporter = new ComponentExporter(typeof(Thing));

            context.Register(exporter);
            var thing = new Thing();

            thing.Other = thing;
            exporter.Export(context, thing, new EmptyJsonWriter());
        }
 public void DeepCircularReferenceDetection()
 {
     ExportContext context = new ExportContext();
     ComponentExporter exporter = new ComponentExporter(typeof(Thing));
     context.Register(exporter);
     Thing thing = new Thing();
     thing.Other = new Thing();
     thing.Other.Other = new Thing();
     thing.Other.Other.Other = thing;
     exporter.Export(context, thing, new EmptyJsonWriter());
 }
        public void TableExportedViaDataView()
        {
            var table = new DataTable();

            var context  = new ExportContext();
            var exporter = new TestDataViewExporter();

            context.Register(exporter);
            context.Export(table, new JsonRecorder());

            Assert.AreSame(table.DefaultView, exporter.LastExported);
        }
        public void TableExportedViaItsExporter()
        {
            DataSet ds = new DataSet();
            ds.Tables.Add(new DataTable("Table1"));

            ExportContext context = new ExportContext();
            TestDataTableExporter exporter = new TestDataTableExporter();
            context.Register(exporter);
            context.Export(ds, new JsonRecorder());

            Assert.AreSame(ds.Tables[0], exporter.LastExported);
        }
        public void DeepCircularReferenceDetection()
        {
            ExportContext     context  = new ExportContext();
            ComponentExporter exporter = new ComponentExporter(typeof(Thing));

            context.Register(exporter);
            Thing thing = new Thing();

            thing.Other             = new Thing();
            thing.Other.Other       = new Thing();
            thing.Other.Other.Other = thing;
            exporter.Export(context, thing, new EmptyJsonWriter());
        }
        public void TableExportedViaItsExporter()
        {
            var ds = new DataSet();

            ds.Tables.Add(new DataTable("Table1"));

            var context  = new ExportContext();
            var exporter = new TestDataTableExporter();

            context.Register(exporter);
            context.Export(ds, new JsonRecorder());

            Assert.AreSame(ds.Tables[0], exporter.LastExported);
        }
Beispiel #11
0
        public void MemberExportCustomization()
        {
            var calls = new ArrayList();

            var logicalType = new TestTypeDescriptor();
            var properties  = logicalType.GetProperties();

            var memexp1  = new TestObjectMemberExporter(calls);
            var services = new Hashtable
            {
                [typeof(IObjectMemberExporter)] = memexp1
            };

            properties.Add(new TestPropertyDescriptor("prop1", services));

            var memexp2 = new TestObjectMemberExporter(calls);

            services = new Hashtable
            {
                [typeof(IObjectMemberExporter)] = memexp2
            };
            properties.Add(new TestPropertyDescriptor("prop2", services));

            var exporter = new ComponentExporter(typeof(Thing), logicalType);
            var context  = new ExportContext();

            context.Register(exporter);

            var writer = new JsonRecorder();
            var thing  = new Thing();

            context.Export(thing, writer);

            Assert.AreEqual(2, calls.Count);

            object[] args = { context, writer, thing };

            Assert.AreSame(memexp1, calls[0]);
            Assert.AreEqual(args, ((TestObjectMemberExporter)calls[0]).ExportArgs);

            Assert.AreSame(memexp2, calls[1]);
            Assert.AreEqual(args, ((TestObjectMemberExporter)calls[1]).ExportArgs);
        }
        public void MemberExportCustomization()
        {
            ArrayList calls = new ArrayList();

            TestTypeDescriptor logicalType = new TestTypeDescriptor();
            PropertyDescriptorCollection properties = logicalType.GetProperties();

            Hashtable services;

            TestObjectMemberExporter memexp1 = new TestObjectMemberExporter(calls);
            services = new Hashtable();
            services.Add(typeof(IObjectMemberExporter), memexp1);
            properties.Add(new TestPropertyDescriptor("prop1", services));

            TestObjectMemberExporter memexp2 = new TestObjectMemberExporter(calls);
            services = new Hashtable();
            services.Add(typeof(IObjectMemberExporter), memexp2);
            properties.Add(new TestPropertyDescriptor("prop2", services));

            ComponentExporter exporter = new ComponentExporter(typeof(Thing), logicalType);
            ExportContext context = new ExportContext();
            context.Register(exporter);

            JsonRecorder writer = new JsonRecorder();
            Thing thing = new Thing();
            context.Export(thing, writer);

            Assert.AreEqual(2, calls.Count);

            object[] args = { context, writer, thing };

            Assert.AreSame(memexp1, calls[0]);
            Assert.AreEqual(args, ((TestObjectMemberExporter) calls[0]).ExportArgs);

            Assert.AreSame(memexp2, calls[1]);
            Assert.AreEqual(args, ((TestObjectMemberExporter) calls[1]).ExportArgs);
        }
        public void MemberExportCustomization()
        {
            TestObjectMemberExporter memberExporter = new TestObjectMemberExporter();
            Hashtable services = new Hashtable();
            services.Add(typeof(IObjectMemberExporter), memberExporter);

            TestTypeDescriptor logicalType = new TestTypeDescriptor();
            PropertyDescriptorCollection properties = logicalType.GetProperties();
            properties.Add(new TestPropertyDescriptor("prop", services));
            
            ComponentExporter exporter = new ComponentExporter(typeof(Thing), logicalType);
            ExportContext context = new ExportContext();
            context.Register(exporter);
            
            JsonRecorder writer = new JsonRecorder();
            Thing thing = new Thing();
            context.Export(thing, writer);
            
            Assert.AreSame(context, memberExporter.ExportContext);
            Assert.AreSame(writer, memberExporter.ExportWriter);
            Assert.AreSame(thing, memberExporter.ExportSource);
        }