public void RegisterOneChildInNameScope() { RuntimeTypeSource.ClearNamescopes(); RuntimeTypeSource.EnableNameScope <DummyClass>(); sut.Process(source.ChildInNameScope); var actual = sut.Result; var childInScope = ((DummyObject)actual).Find("MyObject"); Assert.IsType(typeof(ChildClass), childInScope); }
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); }
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); }
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); }
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]); }
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]); }
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 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 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 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 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); }
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 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 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); }
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); }
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_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); }
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 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 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); }