Exemple #1
0
        public void NodeWithChildrenShouldGetThemAsChildren()
        {
            var converter = new FuncStringConverterExtended((s, t) => (true, Convert.ChangeType(s, t)));
            var creator   = new FuncInstanceCreator((hints, type) => new CreationResult(Activator.CreateInstance(type)));
            var sut       = new NodeAssembler(creator, converter, null);

            var constructionNode = new ConstructionNode <Collection>()
                                   .WithChildren(
                new ConstructionNode <int>
            {
                SourceValue = "1"
            },
                new ConstructionNode <int>
            {
                SourceValue = "2"
            },
                new ConstructionNode <int>
            {
                SourceValue = "3"
            }
                );

            sut.Assemble(constructionNode, null);

            Assert.Equal(new Collection()
            {
                1, 2, 3,
            }, (IEnumerable)constructionNode.Instance);
        }
Exemple #2
0
        public void NodeWithOnlyATypeShouldReturnTheProvidedInstanced()
        {
            var someInstance = new TextBlock();
            var creator      = new FuncInstanceCreator((hints, type) => new CreationResult(someInstance));
            var sut          = new NodeAssembler(creator, null, null);

            var constructionNode = new ConstructionNode <TextBlock>();

            sut.Assemble(constructionNode, null);

            Assert.Equal(someInstance, constructionNode.Instance);
        }
Exemple #3
0
        public void ConstructionWithAssignmentShouldExecuteAssigmentApplier()
        {
            var textBlock = new TextBlock();
            var converter = new FuncStringConverterExtended((s, t) => (true, Convert.ChangeType(s, t)));

            var creator = new FuncInstanceCreator((hints, type) => new CreationResult(textBlock));
            var sut     = new NodeAssembler(creator, converter, new FuncAssignmentApplier((assignment, objectBuilder, context) =>
            {
                assignment.Assignment.Member.SetValue(assignment.Instance, assignment.Assignment.Values.First().Instance);
            }));

            var constructionNode = new ConstructionNode <TextBlock>().WithAssignment(tb => tb.Text, "SomeText");

            sut.Assemble(constructionNode, null);

            Assert.Equal("SomeText", textBlock.Text);
        }