示例#1
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);
        }
        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);
        }
示例#3
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);
        }
示例#4
0
 public ObjectAssembler(StackingLinkedList <Level> state,
                        IRuntimeTypeSource typeSource,
                        IInstanceLifeCycleListener listener,
                        IValueContext context)
 {
     StateCommuter     = new StateCommuter(state, typeSource, listener, context);
     LifecycleListener = listener;
 }
示例#5
0
 public ObjectAssembler(StackingLinkedList<Level> state,
     IRuntimeTypeSource typeSource,
     ITopDownValueContext topDownValueContext,
     IInstanceLifeCycleListener listener)
 {
     StateCommuter = new StateCommuter(state, typeSource, topDownValueContext, listener);
     LifecycleListener = listener;
 }
示例#6
0
        public StateCommuter(StackingLinkedList<Level> stack, WiringContext wiringContext, ITopDownMemberValueContext topDownMemberValueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(wiringContext, nameof(wiringContext));
            Guard.ThrowIfNull(topDownMemberValueContext, nameof(topDownMemberValueContext));

            this.stack = stack;
            this.topDownMemberValueContext = topDownMemberValueContext;
            ValuePipeline = new ValuePipeline(wiringContext);
        }
示例#7
0
        public StateCommuter(StackingLinkedList <Level> stack, IWiringContext wiringContext, ITopDownValueContext topDownValueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(wiringContext, nameof(wiringContext));
            Guard.ThrowIfNull(topDownValueContext, nameof(topDownValueContext));

            Stack = stack;
            this.topDownValueContext = topDownValueContext;
            ValuePipeline            = new ValuePipeline(wiringContext.TypeContext, topDownValueContext);
            instanceProperties       = new InstanceProperties();
        }
示例#8
0
        public StateCommuter(StackingLinkedList<Level> stack, IWiringContext wiringContext, ITopDownValueContext topDownValueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(wiringContext, nameof(wiringContext));
            Guard.ThrowIfNull(topDownValueContext, nameof(topDownValueContext));

            Stack = stack;
            this.topDownValueContext = topDownValueContext;
            ValuePipeline = new ValuePipeline(wiringContext.TypeContext, topDownValueContext);
            instanceProperties = new InstanceProperties();
        }
示例#9
0
        public StateCommuter(StackingLinkedList<Level> stack,
            IRuntimeTypeSource typeSource,
            IInstanceLifeCycleListener lifecycleListener,
            IValueContext valueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(typeSource, nameof(typeSource));

            Stack = stack;
            this.lifecycleListener = lifecycleListener;
            this.valueContext = valueContext;
        }
示例#10
0
        public StateCommuter(StackingLinkedList <Level> stack,
                             IRuntimeTypeSource typeSource,
                             IInstanceLifeCycleListener lifecycleListener,
                             IValueContext valueContext)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(typeSource, nameof(typeSource));

            Stack = stack;
            this.lifecycleListener = lifecycleListener;
            this.valueContext      = valueContext;
        }
示例#11
0
        public StateCommuter(StackingLinkedList<Level> stack,
            IRuntimeTypeSource typeSource,
            ITopDownValueContext topDownValueContext,
            IInstanceLifeCycleListener lifecycleListener)
        {
            Guard.ThrowIfNull(stack, nameof(stack));
            Guard.ThrowIfNull(typeSource, nameof(typeSource));
            Guard.ThrowIfNull(topDownValueContext, nameof(topDownValueContext));

            Stack = stack;
            this.topDownValueContext = topDownValueContext;
            this.lifecycleListener = lifecycleListener;
            ValuePipeline = new ValuePipeline(typeSource, topDownValueContext);
        }
示例#12
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);
        }
        public void GivenConfiguredInstance_StartMemberSetsTheMember()
        {
            var state = new StackingLinkedList<Level>();

            var dummyClass = new DummyClass();
            state.Push(
                new Level
                {
                    Instance = dummyClass,
                });

            var xamlMember = WiringContext.TypeContext.GetXamlType(dummyClass.GetType()).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 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);
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
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);
        }
示例#18
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);
        }
        public void GivenConfiguredInstance_StartMemberSetsTheMember()
        {
            var state = new StackingLinkedList<Level>();

            var dummyClass = new DummyClass();
            var xamlType = TypeRuntimeTypeSource.GetByType(dummyClass.GetType());

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

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

            var sut = new ObjectAssembler(state, TypeRuntimeTypeSource, new TopDownValueContext(), new NullLifecycleListener());

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

            Assert.AreEqual(1, state.Count);
            Assert.AreEqual(state.CurrentValue.Member, xamlMember);
        }
示例#20
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);
        }
        public void GivenStateAfterGetObject_NeedsTwoEndObjectsToConsumeAllTheLevels()
        {
            var state = new StackingLinkedList<Level>();
            var collection = new Collection<Item>();

            state.Push(
                new Level
                {
                    Collection = collection,
                    Member = TypeRuntimeTypeSource.GetByType(typeof(DummyClass)).GetMember("Items"),
                    IsGetObject = true,
                });

            state.Push(new Level { XamlType = TypeRuntimeTypeSource.GetByType(typeof(Item)) });

            var sut = new ObjectAssembler(state, TypeRuntimeTypeSource, new TopDownValueContext(), new NullLifecycleListener());

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

            Assert.AreEqual(0, state.Count);
        }
        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 StartObjectShouldSetTheXamlType()
        {
            var state = new StackingLinkedList<Level>();
            state.Push(new Level());

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

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

            var actualType = sut.StateCommuter.Current.XamlType;

            var expectedType = TypeRuntimeTypeSource.GetByType(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 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);
        }
        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);
        }
        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);
        }
示例#28
0
 public ObjectAssembler(StackingLinkedList <Level> state, IWiringContext wiringContext, ITopDownValueContext topDownValueContext)
 {
     WiringContext = wiringContext;
     StateCommuter = new StateCommuter(state, wiringContext, topDownValueContext);
 }
 public void Initialize()
 {
     sut = new StackingLinkedList<int>();
 }
示例#30
0
 public void Initialize()
 {
     sut = new StackingLinkedList <int>();
 }
示例#31
0
 public CurrentScopeProxy(StackingLinkedList<Scope> stackingLinkedList)
 {
     this.stackingLinkedList = stackingLinkedList;
 }
        public void GivenStateAfterGetObject_WritingObjectAssignsItToTheCollection()
        {
            var state = new StackingLinkedList<Level>();
            var collection = new Collection<Item>();

            state.Push(
                new Level
                {
                    Collection = collection,
                    IsGetObject = true,
                });

            state.Push(new Level());

            var sut = new SuperObjectAssembler(state, WiringContext, new TopDownMemberValueContext());

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

            Assert.AreEqual(1, collection.Count);
        }
示例#33
0
 public ObjectAssembler(StackingLinkedList<Level> state, IWiringContext wiringContext, ITopDownValueContext topDownValueContext)
 {
     WiringContext = wiringContext;
     StateCommuter = new StateCommuter(state, wiringContext, topDownValueContext);
 }
        public void GivenStateAfterGetObject_WritingObjectAssignsItToTheCollection()
        {
            var state = new StackingLinkedList<Level>();
            var collection = new Collection<Item>();

            state.Push(
                new Level
                {
                    Collection = collection,
                    IsGetObject = true,
                    Member = TypeRuntimeTypeSource.GetByType(typeof(DummyClass)).GetMember("Items"),
                });

            state.Push(new Level());

            var sut = new ObjectAssembler(state, TypeRuntimeTypeSource, new TopDownValueContext(), new NullLifecycleListener());

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

            Assert.AreEqual(1, collection.Count);
        }