Beispiel #1
0
        public NameScopeTests()
        {
            var topDownValueContext = new TopDownValueContext();

            sut    = new ObjectAssembler(RuntimeTypeSource, new ValueContext(RuntimeTypeSource, topDownValueContext));
            source = new InstructionResources(this);
        }
        public void GivenChildWithPreviousName_LatestNameIsRegisteredInParent()
        {
            var runtimeTypeSource = CreateRuntimeTypeSource();
            var x = CreateBuilder(runtimeTypeSource);

            var topDownValueContext = new TopDownValueContext();
            var valueConnectionContext = new ValueContext(runtimeTypeSource, topDownValueContext);
            var sut = new ObjectAssembler(runtimeTypeSource, valueConnectionContext);

            var batch = new Collection<Instruction>
            {
                x.StartObject<DummyClass>(),
                x.StartMember<DummyClass>(d => d.Child),
                x.StartObject<ChildClass>(),
                x.StartMember<ChildClass>(c => c.Name),
                x.Value("OuterName"),
                x.EndMember(),
                x.EndObject(),
                x.EndMember(),
                x.EndObject(),
            };

            sut.Process(batch);

            var result = (DummyClass)sut.Result;

            var childClass = result.Find("OuterName");
            Assert.NotNull(childClass);
        }
Beispiel #3
0
        public void MultinameRegistrationGivesSameObjectTwoSubsequentNames()
        {
            var runtimeTypeSource = CreateRuntimeTypeSource();
            var x = CreateBuilder(runtimeTypeSource);

            var topDownValueContext = new TopDownValueContext();

            var valueConnectionContext = new ValueContext(runtimeTypeSource, topDownValueContext, new Dictionary <string, object>());
            var sut = new ObjectAssembler(runtimeTypeSource, valueConnectionContext);

            var batch = new Collection <Instruction>
            {
                x.StartObject <DummyClass>(),
                x.StartMember <DummyClass>(d => d.Child),
                x.StartObject <ChildClass>(),
                x.StartMember <ChildClass>(c => c.Name),
                x.Value("OuterName"),
                x.EndMember(),
                x.EndObject(),
                x.EndMember(),
                x.EndObject(),
            };

            sut.Process(batch);

            var result = (DummyClass)sut.Result;
            var child  = (DummyObject)result.Child;

            Assert.Equal("InnerName", child.NamesHistory[0]);
            Assert.Equal("OuterName", child.NamesHistory[1]);
        }
Beispiel #4
0
        public void GivenChildWithPreviousName_LatestNameIsRegisteredInParent()
        {
            var runtimeTypeSource = CreateRuntimeTypeSource();
            var x = CreateBuilder(runtimeTypeSource);

            var topDownValueContext    = new TopDownValueContext();
            var valueConnectionContext = new ValueContext(runtimeTypeSource, topDownValueContext, new Dictionary <string, object>());
            var sut = new ObjectAssembler(runtimeTypeSource, valueConnectionContext);

            var batch = new Collection <Instruction>
            {
                x.StartObject <DummyClass>(),
                x.StartMember <DummyClass>(d => d.Child),
                x.StartObject <ChildClass>(),
                x.StartMember <ChildClass>(c => c.Name),
                x.Value("OuterName"),
                x.EndMember(),
                x.EndObject(),
                x.EndMember(),
                x.EndObject(),
            };

            sut.Process(batch);

            var result = (DummyClass)sut.Result;

            var childClass = result.Find("OuterName");

            Assert.NotNull(childClass);
        }
        public void MultinameRegistrationGivesSameObjectTwoSubsequentNames()
        {
            var runtimeTypeSource = CreateRuntimeTypeSource();
            var x = CreateBuilder(runtimeTypeSource);

            var topDownValueContext = new TopDownValueContext();

            var valueConnectionContext = new ValueContext(runtimeTypeSource, topDownValueContext);
            var sut = new ObjectAssembler(runtimeTypeSource, valueConnectionContext);

            var batch = new Collection<Instruction>
            {
                x.StartObject<DummyClass>(),
                x.StartMember<DummyClass>(d => d.Child),
                x.StartObject<ChildClass>(),
                x.StartMember<ChildClass>(c => c.Name),
                x.Value("OuterName"),
                x.EndMember(),
                x.EndObject(),
                x.EndMember(),
                x.EndObject(),
            };

            sut.Process(batch);

            var result = (DummyClass)sut.Result;
            var child = (DummyObject)result.Child;
            Assert.Equal("InnerName", child.NamesHistory[0]);
            Assert.Equal("OuterName", child.NamesHistory[1]);
        }
Beispiel #6
0
        public void EndMemberAssignsInstanceToParentProperty()
        {
            var state = new StackingLinkedList <Level>();

            var dummyClass = new DummyClass();
            var xamlType   = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());

            state.Push(
                new Level
            {
                Instance   = dummyClass,
                XamlMember = xamlType.GetMember("Child"),
            });

            var childClass = new ChildClass();

            state.Push(
                new Level
            {
                XamlType = xamlType,
                Instance = childClass,
            });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.EndObject());

            Assert.AreEqual(1, state.Count);
            var expectedInstance = state.CurrentValue.Instance;

            Assert.AreSame(expectedInstance, dummyClass);
            Assert.AreSame(((DummyClass)expectedInstance).Child, childClass);
        }
Beispiel #7
0
        public void GivenCtorArguments_WritingEndObjectMakesResultTheProvidedValueOfTheMarkupExtension()
        {
            var state = new StackingLinkedList <Level>();

            var xamlType = WiringContext.TypeContext.GetXamlType(typeof(DummyClass));

            state.Push(
                new Level
            {
                XamlType   = xamlType,
                Instance   = new DummyClass(),
                XamlMember = xamlType.GetMember("SampleProperty")
            });

            var constructionArguments = new Collection <ConstructionArgument> {
                new ConstructionArgument("Value", "Value")
            };

            state.Push(
                new Level
            {
                XamlType      = WiringContext.TypeContext.GetXamlType(typeof(DummyExtension)),
                CtorArguments = constructionArguments,
            });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.EndObject());

            Assert.AreEqual("Value", sut.Result);
        }
Beispiel #8
0
        protected IObjectAssembler CreateObjectAssembler()
        {
            var topDownValueContext = new TopDownValueContext();
            var objectAssembler     = new ObjectAssembler(RuntimeTypeSource, new ValueContext(RuntimeTypeSource, topDownValueContext, new Dictionary <string, object>()));

            return(objectAssembler);
        }
        public void EndMemberAssignsInstanceToParentProperty()
        {
            var state = new StackingLinkedList<Level>();

            var dummyClass = new DummyClass();
            var xamlType = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());
            state.Push(
                new Level
                {
                    Instance = dummyClass,
                    XamlMember = xamlType.GetMember("Child"),
                });

            var childClass = new ChildClass();
            state.Push(
                new Level
                {
                    XamlType = xamlType,
                    Instance = childClass,
                });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.EndObject());

            Assert.AreEqual(1, state.Count);
            var expectedInstance = state.CurrentValue.Instance;

            Assert.AreSame(expectedInstance, dummyClass);
            Assert.AreSame(((DummyClass)expectedInstance).Child, childClass);
        }
        public IObjectAssembler CreateAssembler(Settings settings)
        {
            var mapping = new DeferredLoaderMapping();
            mapping.Map<DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var objectAssembler = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), settings);
            return new TemplateHostingObjectAssembler(objectAssembler, mapping);
        }
Beispiel #11
0
        private ObjectAssembler CreateAssemblerToReadSpecificInstance(object instance)
        {
            var settings = new ObjectAssemblerSettings {
                RootInstance = instance
            };
            var assembler = new ObjectAssembler(WiringContext, topDownValueContext, settings);

            return(assembler);
        }
        public IRepository PopulatedXmlRepository()
        {
            ObjectAssembler assembler  = new ObjectAssembler(_create);
            IRepository     repository = new XmlRepository(assembler);

            _populateRepository(repository);

            return(repository);
        }
        private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance)
        {
            var objectAssembler = new ObjectAssembler(wiringContext, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = rootInstance });

            var mapping = new DeferredLoaderMapping();
            mapping.Map<DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping);
            return templateAwareObjectAssembler;
        }
Beispiel #14
0
        public IObjectAssembler CreateAssembler(ObjectAssemblerSettings settings)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var objectAssembler = new ObjectAssembler(wiringContext, new TopDownValueContext(), settings);

            return(new TemplateHostingObjectAssembler(objectAssembler, mapping));
        }
Beispiel #15
0
        public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <XamlDataTemplate>(template => template.Content, new TemplateLoader());

            var assembler = new ObjectAssembler(wiringContext, new TopDownMemberValueContext(), objectAssemblerSettings);

            _objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
        }
Beispiel #16
0
        public IObjectAssembler CreateAssembler(Settings settings)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var topDownValueContext    = new TopDownValueContext();
            var valueConnectionContext = new ValueContext(runtimeTypeSource, topDownValueContext, settings.ParsingContext);
            var objectAssembler        = new ObjectAssembler(runtimeTypeSource, valueConnectionContext, settings);

            return(new TemplateHostingObjectAssembler(objectAssembler, mapping));
        }
        private IObjectAssembler CreateObjectAssembler(Settings settings)
        {
            var topDownValueContext = new TopDownValueContext();

            var objectAssembler = new ObjectAssembler(runtimeTypeSource, new ValueContext(runtimeTypeSource, topDownValueContext, new Dictionary<string, object>()), settings);

            var mapping = new DeferredLoaderMapping();
            mapping.Map<DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping);
            return templateAwareObjectAssembler;
        }
        public PerspexObjectAssembler(IRuntimeTypeSource runtimeTypeSource, Settings objectAssemblerSettings = null)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <ControlTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <DataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <FocusAdornerTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <TreeDataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <ItemsPanelTemplate>(x => x.Content, new TemplateLoader());

            assembler       = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), objectAssemblerSettings);
            objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
        }
Beispiel #19
0
        public IObjectAssembler CreateSutForLoadingSpecificInstance(object instance)
        {
            var topDownValueContext    = new TopDownValueContext();
            var valueConnectionContext = new ValueContext(RuntimeTypeSource, topDownValueContext);

            var settings = new Settings {
                RootInstance = instance
            };

            var assembler = new ObjectAssembler(RuntimeTypeSource, valueConnectionContext, settings);

            return(assembler);
        }
Beispiel #20
0
        public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <ControlTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <DataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <FocusAdornerTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <TreeDataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <ItemsPanelTemplate>(x => x.Content, new TemplateLoader());

            var assembler = new ObjectAssembler(wiringContext, new TopDownValueContext(), objectAssemblerSettings);

            _objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
        }
        private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance)
        {
            var objectAssembler = new ObjectAssembler(wiringContext, new TopDownValueContext(), new ObjectAssemblerSettings {
                RootInstance = rootInstance
            });

            var mapping = new DeferredLoaderMapping();

            mapping.Map <DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping);

            return(templateAwareObjectAssembler);
        }
        private IObjectAssembler CreateObjectAssembler(Settings settings)
        {
            var topDownValueContext = new TopDownValueContext();

            var objectAssembler = new ObjectAssembler(runtimeTypeSource, new ValueContext(runtimeTypeSource, topDownValueContext, new Dictionary <string, object>()), settings);

            var mapping = new DeferredLoaderMapping();

            mapping.Map <DataTemplate>(template => template.Content, new DummyDeferredLoader());

            var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping);

            return(templateAwareObjectAssembler);
        }
        public XamlXmlLoader Build()
        {
            var wiringContextBuilder = new WiringContextBuilder();

            wiringContextBuilder
                .WithContentPropertiesFromAssemblies(lookupAssemblies)
                .WithNsPrefixes(prefixes)
                .WithConverters(Converters.FromAssemblies(lookupAssemblies));

            RegisterNamespaces(wiringContextBuilder);
            RegisterContentProperties(wiringContextBuilder);

            var wiringContext = wiringContextBuilder.Build();
            var assembler = new ObjectAssembler(wiringContext);
            return new XamlXmlLoader(assembler, wiringContext);
        }
Beispiel #24
0
        public void StartObjectShouldSetTheXamlType()
        {
            var state = new StackingLinkedList <Level>();

            state.Push(new Level());

            var type = typeof(DummyClass);
            var sut  = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartObject(type));

            var actualType = sut.StateCommuter.Current.XamlType;

            var expectedType = WiringContext.TypeContext.GetXamlType(type);

            Assert.AreEqual(expectedType, actualType);
        }
Beispiel #25
0
        public AvaloniaObjectAssembler(
            IRuntimeTypeSource typeSource,
            ITopDownValueContext topDownValueContext,
            Settings settings = null)
        {
            var mapping = new DeferredLoaderMapping();

            mapping.Map <ControlTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <DataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <FocusAdornerTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <TreeDataTemplate>(x => x.Content, new TemplateLoader());
            mapping.Map <ItemsPanelTemplate>(x => x.Content, new TemplateLoader());

            var parsingDictionary = GetDictionary(settings);
            var valueContext      = new ValueContext(typeSource, topDownValueContext, parsingDictionary);

            assembler       = new ObjectAssembler(typeSource, valueContext, settings);
            objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
        }
Beispiel #26
0
        public void SimpleTest()
        {
            var input = new Collection <Instruction>
            {
                X.StartObject <Item>(),
                X.StartMember <Item>(i => i.Template),
                X.StartObject <Template>(),
                X.StartMember <Template>(i => i.Content),
                X.StartObject <Grid>(),
                X.EndObject(),
                X.EndMember(),
                X.EndObject(),
                X.EndMember(),
                X.EndObject(),
            };

            var mapping   = new DeferredLoaderMapping();
            var assembler = new DummyDeferredLoader();

            mapping.Map <Template>(t => t.Content, assembler);

            var topDownValueContext = new TopDownValueContext();
            var objectAssembler     = new ObjectAssembler(RuntimeTypeSource, new ValueContext(RuntimeTypeSource, topDownValueContext));

            var sut = new TemplateHostingObjectAssembler(objectAssembler, mapping);

            foreach (var instruction in input)
            {
                sut.Process(instruction);
            }

            var actualNodes          = sut.NodeList;
            var expectedInstructions = new List <Instruction>
            {
                X.StartObject <Grid>(),
                X.EndObject(),
            }.AsReadOnly();

            Assert.Equal(expectedInstructions, actualNodes);
            Assert.NotNull(((Item)sut.Result).Template.Content);
        }
        public void SimpleTest()
        {
            var input = new Collection<Instruction>
            {
                X.StartObject<Item>(),
                X.StartMember<Item>(i => i.Template),
                X.StartObject<Template>(),
                X.StartMember<Template>(i => i.Content),
                X.StartObject<Grid>(),
                X.EndObject(),
                X.EndMember(),
                X.EndObject(),
                X.EndMember(),
                X.EndObject(),
            };

            var mapping = new DeferredLoaderMapping();
            var assembler = new DummyDeferredLoader();
            mapping.Map<Template>(t => t.Content, assembler);

            var topDownValueContext = new TopDownValueContext();
            var objectAssembler = new ObjectAssembler(RuntimeTypeSource, new ValueContext(RuntimeTypeSource, topDownValueContext));

            var sut = new TemplateHostingObjectAssembler(objectAssembler, mapping);

            foreach (var instruction in input)
            {
                sut.Process(instruction);
            }

            var actualNodes = sut.NodeList;
            var expectedInstructions = new List<Instruction>
            {
                X.StartObject<Grid>(),
                X.EndObject(),
            }.AsReadOnly();

            Assert.Equal(expectedInstructions, actualNodes);
            Assert.NotNull(((Item) sut.Result).Template.Content);
        }
Beispiel #28
0
        public void GivenConfigurationOfCollection_GetObjectConfiguresTheLevel()
        {
            var state = new StackingLinkedList <Level>();

            var type       = typeof(DummyClass);
            var xamlMember = WiringContext.TypeContext.GetXamlType(type).GetMember("Items");

            state.Push(
                new Level
            {
                Instance   = new DummyClass(),
                XamlMember = xamlMember,
            });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.GetObject());

            Assert.AreEqual(2, state.Count);
            Assert.IsTrue(state.CurrentValue.Collection != null);
            Assert.IsTrue(state.CurrentValue.IsGetObject);
        }
        public void GivenConfigurationOfCollection_GetObjectConfiguresTheLevel()
        {
            var state = new StackingLinkedList<Level>();

            var type = typeof(DummyClass);
            var xamlMember = WiringContext.TypeContext.GetXamlType(type).GetMember("Items");

            state.Push(
                new Level
                {
                    Instance = new DummyClass(),
                    XamlMember = xamlMember,
                });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.GetObject());

            Assert.AreEqual(2, state.Count);
            Assert.IsTrue(state.CurrentValue.Collection != null);
            Assert.IsTrue(state.CurrentValue.IsGetObject);
        }
Beispiel #30
0
        public void GivenStateAfterGetObject_WritingObjectAssignsItToTheCollection()
        {
            var state      = new StackingLinkedList <Level>();
            var collection = new Collection <Item>();

            state.Push(
                new Level
            {
                Collection  = collection,
                IsGetObject = true,
                XamlMember  = WiringContext.TypeContext.GetXamlType(typeof(DummyClass)).GetMember("Items"),
            });

            state.Push(new Level());

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartObject <Item>());
            sut.Process(X.EndObject());

            Assert.AreEqual(1, collection.Count);
        }
Beispiel #31
0
        public void GivenConfiguredXamlType_StartMemberInstantiatesItSetsTheMember()
        {
            var state = new StackingLinkedList <Level>();

            var type = typeof(DummyClass);

            state.Push(
                new Level
            {
                XamlType = WiringContext.TypeContext.GetXamlType(type)
            });

            var xamlMember = WiringContext.TypeContext.GetXamlType(type).GetMember("Items");

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartMember <DummyClass>(d => d.Items));

            Assert.AreEqual(1, state.Count);
            Assert.IsInstanceOfType(state.CurrentValue.Instance, type);
            Assert.AreEqual(state.CurrentValue.XamlMember, xamlMember);
        }
Beispiel #32
0
        public void GivenConfiguredInstance_StartMemberSetsTheMember()
        {
            var state = new StackingLinkedList <Level>();

            var dummyClass = new DummyClass();
            var xamlType   = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());

            state.Push(
                new Level
            {
                Instance = dummyClass,
                XamlType = xamlType,
            });

            var xamlMember = xamlType.GetMember("Items");

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartMember <DummyClass>(d => d.Items));

            Assert.AreEqual(1, state.Count);
            Assert.AreEqual(state.CurrentValue.XamlMember, xamlMember);
        }
Beispiel #33
0
        public void GivenStateAfterGetObject_NeedsTwoEndObjectsToConsumeAllTheLevels()
        {
            var state      = new StackingLinkedList <Level>();
            var collection = new Collection <Item>();

            state.Push(
                new Level
            {
                Collection  = collection,
                XamlMember  = WiringContext.TypeContext.GetXamlType(typeof(DummyClass)).GetMember("Items"),
                IsGetObject = true,
            });

            state.Push(new Level {
                XamlType = WiringContext.TypeContext.GetXamlType(typeof(Item))
            });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.EndObject());
            sut.Process(X.EndObject());

            Assert.AreEqual(0, state.Count);
        }
Beispiel #34
0
 public EndMemberCommand(ObjectAssembler assembler, ITopDownValueContext topDownValueContext)
     : base(assembler)
 {
     this.topDownValueContext = topDownValueContext;
     typeContext = Assembler.WiringContext.TypeContext;
 }
Beispiel #35
0
 public ValueCommand(ObjectAssembler objectAssembler, ITopDownValueContext topDownValueContext, string value) : base(objectAssembler)
 {
     this.value    = value;
     ValuePipeLine = new ValuePipeline(objectAssembler.WiringContext.TypeContext, topDownValueContext);
 }
        public void StartObjectShouldSetTheXamlType()
        {
            var state = new StackingLinkedList<Level>();
            state.Push(new Level());

            var type = typeof(DummyClass);
            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartObject(type));

            var actualType = sut.StateCommuter.Current.XamlType;

            var expectedType = WiringContext.TypeContext.GetXamlType(type);
            Assert.AreEqual(expectedType, actualType);
        }
        public void GivenStateAfterGetObject_NeedsTwoEndObjectsToConsumeAllTheLevels()
        {
            var state = new StackingLinkedList<Level>();
            var collection = new Collection<Item>();

            state.Push(
                new Level
                {
                    Collection = collection,
                    XamlMember = WiringContext.TypeContext.GetXamlType(typeof(DummyClass)).GetMember("Items"),
                    IsGetObject = true,
                });

            state.Push(new Level { XamlType = WiringContext.TypeContext.GetXamlType(typeof(Item)) });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.EndObject());
            sut.Process(X.EndObject());

            Assert.AreEqual(0, state.Count);
        }
        public void GivenConfiguredXamlType_StartMemberInstantiatesItSetsTheMember()
        {
            var state = new StackingLinkedList<Level>();

            var type = typeof(DummyClass);
            state.Push(
                new Level
                {
                    XamlType = WiringContext.TypeContext.GetXamlType(type)
                });

            var xamlMember = WiringContext.TypeContext.GetXamlType(type).GetMember("Items");

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartMember<DummyClass>(d => d.Items));

            Assert.AreEqual(1, state.Count);
            Assert.IsInstanceOfType(state.CurrentValue.Instance, type);
            Assert.AreEqual(state.CurrentValue.XamlMember, xamlMember);
        }
Beispiel #39
0
 public EndObjectCommand(ObjectAssembler assembler)
     : base(assembler)
 {
 }
 public IObjectAssembler CreateSutForLoadingSpecificInstance(object instance)
 {
     var settings = new Settings { RootInstance = instance };
     var assembler = new ObjectAssembler(TypeRuntimeTypeSource, new TopDownValueContext(), settings);
     return assembler;
 }
 public StartMemberCommand(ObjectAssembler assembler, XamlMemberBase member) : base(assembler)
 {
     this.member = member;
 }
Beispiel #42
0
 public NameScopeTests()
 {
     sut = new ObjectAssembler(TypeRuntimeTypeSource, new TopDownValueContext());
     source = new InstructionResources(this);
 }
Beispiel #43
0
 public StartObjectCommand(ObjectAssembler assembler, XamlType xamlType, object rootInstance)
     : base(assembler)
 {
     this.xamlType = xamlType;
     this.rootInstance = rootInstance;
 }
Beispiel #44
0
 public EndObjectCommand(ObjectAssembler assembler) : base(assembler)
 {
 }
 public void MixedCollectionWithRootInstance()
 {
     var root = new ArrayList();
     var settings = new ObjectAssemblerSettings { RootInstance = root };
     var assembler = new ObjectAssembler(WiringContext, topDownValueContext, settings);
     assembler.PumpNodes(source.MixedCollection);
     var result = assembler.Result;
     Assert.IsInstanceOfType(result, typeof(ArrayList));
     var arrayList = (ArrayList)result;
     Assert.IsTrue(arrayList.Count > 0);
 }
Beispiel #46
0
 public NameScopeTests()
 {
     sut    = new ObjectAssembler(WiringContext, new TopDownValueContext());
     source = new XamlInstructionResources(this);
 }
Beispiel #47
0
 public ValueCommand(ObjectAssembler objectAssembler, ITopDownValueContext topDownValueContext, string value)
     : base(objectAssembler)
 {
     this.value = value;
     ValuePipeLine = new ValuePipeline(objectAssembler.WiringContext.TypeContext, topDownValueContext);
 }
Beispiel #48
0
 public GetObjectCommand(ObjectAssembler objectAssembler)
     : base(objectAssembler)
 {
 }
        public void GivenCtorArguments_WritingEndObjectMakesResultTheProvidedValueOfTheMarkupExtension()
        {
            var state = new StackingLinkedList<Level>();

            var xamlType = WiringContext.TypeContext.GetXamlType(typeof(DummyClass));
            state.Push(
                new Level
                {
                    XamlType = xamlType,
                    Instance = new DummyClass(),
                    XamlMember = xamlType.GetMember("SampleProperty")
                });

            var constructionArguments = new Collection<ConstructionArgument> { new ConstructionArgument("Value", "Value") };
            state.Push(
                new Level
                {
                    XamlType = WiringContext.TypeContext.GetXamlType(typeof(DummyExtension)),
                    CtorArguments = constructionArguments,
                });

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());
            sut.Process(X.EndObject());

            Assert.AreEqual("Value", sut.Result);
        }
Beispiel #50
0
 public GetObjectCommand(ObjectAssembler objectAssembler) : base(objectAssembler)
 {
 }
        public void GivenStateAfterGetObject_WritingObjectAssignsItToTheCollection()
        {
            var state = new StackingLinkedList<Level>();
            var collection = new Collection<Item>();

            state.Push(
                new Level
                {
                    Collection = collection,
                    IsGetObject = true,
                    XamlMember = WiringContext.TypeContext.GetXamlType(typeof(DummyClass)).GetMember("Items"),
                });

            state.Push(new Level());

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartObject<Item>());
            sut.Process(X.EndObject());

            Assert.AreEqual(1, collection.Count);
        }
 private ObjectAssembler CreateAssemblerToReadSpecificInstance(object instance)
 {
     var settings = new ObjectAssemblerSettings {RootInstance = instance};
     var assembler = new ObjectAssembler(WiringContext, topDownValueContext, settings);
     return assembler;
 }
Beispiel #53
0
 protected Command(ObjectAssembler assembler)
 {
     Assembler = assembler;
 }
 public GetObjectWriter(ObjectAssembler objectAssembler)
 {
     this.objectAssembler = objectAssembler;
     bag = objectAssembler.Bag;
 }
        public void GivenConfiguredInstance_StartMemberSetsTheMember()
        {
            var state = new StackingLinkedList<Level>();

            var dummyClass = new DummyClass();
            var xamlType = WiringContext.TypeContext.GetXamlType(dummyClass.GetType());

            state.Push(
                new Level
                {
                    Instance = dummyClass,
                    XamlType = xamlType,
                });

            var xamlMember = xamlType.GetMember("Items");

            var sut = new ObjectAssembler(state, WiringContext, new TopDownValueContext());

            sut.Process(X.StartMember<DummyClass>(d => d.Items));

            Assert.AreEqual(1, state.Count);
            Assert.AreEqual(state.CurrentValue.XamlMember, xamlMember);
        }
 public StartMemberWriter(ObjectAssembler objectAssembler)
 {
     this.objectAssembler = objectAssembler;
     bag = objectAssembler.Bag;
 }
        public IParser Create(Settings settings)
        {
            var objectAssemblerForUndefinedRoot = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), settings);

            return CreateParser(objectAssemblerForUndefinedRoot);
        }
 public StartObjectWriter(ObjectAssembler objectAssembler, object rootInstance = null)
 {
     this.objectAssembler = objectAssembler;
     this.rootInstance = rootInstance;
     bag = objectAssembler.Bag;
 }
Beispiel #59
0
 protected Command(ObjectAssembler assembler)
 {
     Assembler = assembler;
 }
Beispiel #60
0
 public NameScopeTests()
 {
     sut = new ObjectAssembler(WiringContext, new TopDownValueContext());
     source = new XamlInstructionResources(this);
 }