public void should_throw_when_opted_in()
        {
            registry.ThrowOnRecursion(true);
            var construktion = new Construktion().Apply(registry);

            Exception <Exception> .ShouldBeThrownBy(() => construktion.Construct <Parent>());
        }
        public void should_still_throw()
        {
            registry.ThrowOnRecursion(true);
            var newRegistry  = new ConstruktionRegistry();
            var construktion = new Construktion().Apply(registry).Apply(newRegistry);

            Exception <Exception> .ShouldBeThrownBy(() => construktion.Construct <Parent>());
        }
        public void should_not_throw_when_opted_out()
        {
            registry.ThrowOnRecursion(true);
            var newRegistry  = new ConstruktionRegistry().ThrowOnRecursion(false);
            var construktion = new Construktion().Apply(registry).Apply(newRegistry);

            Should.NotThrow(() => construktion.Construct <Parent>());
        }
        public void should_add_through_construktion()
        {
            var construktion = new Construktion().Apply(new FooExitBlueprint());

            var foo = construktion.Construct <Foo>();

            foo.Id.ShouldBe(10);
        }
示例#5
0
        public void should_use_modest_ctor_when_opted_in()
        {
            _registry.UseModestCtor();

            var result = new Construktion().AddRegistry(_registry).Construct <MultiCtor>();

            result.UsedModestCtor.ShouldBe(true);
        }
示例#6
0
        public void should_register_attribute_blueprint()
        {
            _registry.AddAttributeBlueprint <Set>(x => x.Value);

            var foo = new Construktion().AddRegistry(_registry).Construct <Foo>();

            foo.Bar.ShouldBe("Set");
        }
示例#7
0
        public void should_register_property_attribute_blueprint()
        {
            var registry = new ConstruktionRegistry().AddPropertyAttribute <Set>(x => x.Value);

            var foo = new Construktion().Apply(registry).Construct <Foo>();

            foo.WithAttribute.ShouldBe("Set");
        }
示例#8
0
        public void should_work_with_a_custom_registry()
        {
            var construktion = new Construktion().AddRegistry(new StringARegistry());

            var foo = construktion.Construct <Foo>();

            foo.Bar.ShouldBe("StringA");
        }
示例#9
0
        public void should_register_via_generic_parameter()
        {
            _registry.AddBlueprint <StringA>();

            var result = new Construktion().AddRegistry(_registry).Construct <string>();

            result.ShouldBe("StringA");
        }
示例#10
0
        public void should_register_a_custom_blueprint()
        {
            _registry.AddBlueprint(new StringA());

            var result = new Construktion().AddRegistry(_registry).Construct <string>();

            result.ShouldBe("StringA");
        }
示例#11
0
        public void should_use_linq_created_registry()
        {
            var construktion = new Construktion().AddRegistry(x => x.UseModestCtor());

            var result = construktion.Construct <MultiCtor>();

            result.UsedModestCtor.ShouldBe(true);
        }
        public void abstract_blueprints_should_only_match_t()
        {
            var construktion = new Construktion();

            construktion.Apply(new FooBlueprint());

            ShouldlyExtensions.ShouldNotThrow <InvalidCastException>(() => construktion.Construct <string>());
        }
示例#13
0
        public void should_register_instance_with_contract()
        {
            _registry.Register <IFoo, Foo>();

            var result = new Construktion().AddRegistry(_registry).Construct <IFoo>();

            result.ShouldBeOfType <Foo>();
        }
示例#14
0
        public void should_ignore_on_recursion()
        {
            var one = new Construktion().Construct <One>();

            one.Name.ShouldNotBeNullOrWhiteSpace();

            one.Two.Name.ShouldNotBeNullOrWhiteSpace();
            one.Two.One.ShouldBe(null);
        }
        public void resolved_ctor_args_should_be_different_objects()
        {
            var result1 = new Construktion().Construct <NonEmptyCtor>();
            var result2 = new Construktion().Construct <NonEmptyCtor>();

            result1.Foo.ShouldNotBeNull();
            result2.Foo.ShouldNotBeNull();
            result1.Foo.GetHashCode().ShouldNotBe(result2.Foo.GetHashCode());
        }
示例#16
0
        public void blue_prints_registered_first_are_chosen_first()
        {
            _registry.AddBlueprint(new StringB());
            _registry.AddBlueprint(new StringA());

            var result = new Construktion().AddRegistry(_registry).Construct <string>();

            result.ShouldBe("StringB");
        }
示例#17
0
        public void should_omit_ids()
        {
            _registry.OmitIds();
            var construktion = new Construktion().AddRegistry(_registry);

            var foo = construktion.Construct <Foo>();

            foo.FooId.ShouldBe(0);
        }
示例#18
0
        public void should_ignore_on_recursion()
        {
            var parent = new Construktion().Construct <Parent>();

            parent.Name.ShouldNotBeNullOrWhiteSpace();

            parent.Child.Name.ShouldNotBeNullOrWhiteSpace();
            parent.Child.RecursiveParent.ShouldBe(null);
        }
        public void should_construct_email()
        {
            var construktion = new Construktion().Apply(x => x.AddEmailBlueprint());

            var result = construktion.Construct <Foo>();

            result.Email.ShouldContain("@");
            result.Custom.ShouldNotContain("@");
        }
        public void should_allow_custom_convention()
        {
            var construktion = new Construktion().Apply(x => x.AddEmailBlueprint(p => p.Name.Equals("Custom")));

            var result = construktion.Construct <Foo>();

            result.Email.ShouldNotContain("@");
            result.Custom.ShouldContain("@");
        }
示例#21
0
        public void log_should_power_through_exceptions()
        {
            var context = new ConstruktionContext(typeof(WillThrowFoo));

            var result = new Construktion().DebuggingConstruct(context, out string log);

            log.ShouldContain("Cannot construct the interface");
            log.ShouldContain("End Construktion.Tests.DebuggingConstruktionTests+WillThrowFoo");
        }
示例#22
0
        public void last_registered_instance_should_be_chosen()
        {
            _registry.Register <IFoo, Foo>();
            _registry.Register <IFoo, Foo2>();

            var result = new Construktion().AddRegistry(_registry).Construct <IFoo>();

            result.ShouldBeOfType <Foo2>();
        }
        public void should_construct()
        {
            var context = new Construktion().Apply(new FooBlueprint());

            var result = context.Construct <Foo>();

            result.Name.ShouldBe("Name");
            result.Age.ShouldBe(10);
        }
        public void should_not_pass_nulls_to_exit_blueprint()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.AddBlueprint <NullFooBlueprint>();
                x.AddExitBlueprint <IFooExitBlueprint>();
            });

            Should.NotThrow(() => construktion.Construct <Foo>().ShouldBeNull());
        }
示例#25
0
        public void should_construct_top_level_properties()
        {
            var registry     = new ConstruktionRegistry(x => x.MaxDepth(1));
            var construktion = new Construktion().Apply(registry);

            var result = construktion.Construct <LevelOne>();

            result.LevelTwo.ShouldNotBe(null);
            result.LevelTwo.Name.ShouldBe(null);
        }
        public void should_set_value_from_attribute()
        {
            var construktion = new Construktion().AddBlueprint(new AttributeBlueprint <Set>(x => x.Value));

            var foo = construktion.Construct <Foo>();

            foo.Bar.ShouldBe("Set");
            foo.Baz.ShouldNotBe("Set");
            foo.Baz.ShouldNotBeNullOrWhiteSpace();
        }
示例#27
0
        public void should_inject_instance()
        {
            var foo          = new Foo();
            var construktion = new Construktion().Inject(foo);

            var result = construktion.Construct <FooHolder>();

            result.Foo
            .GetHashCode()
            .ShouldBe(foo.GetHashCode());
        }
示例#28
0
        public void should_inject_from_within_pipeline()
        {
            var construktion = new Construktion().Apply(new FooBlueprint());

            var foo    = construktion.Construct <Foo>();
            var result = construktion.Construct <FooHolder>();

            result.Foo
            .GetHashCode()
            .ShouldBe(foo.GetHashCode());
        }
示例#29
0
        public void registries_registered_first_should_have_their_blueprints_used_first()
        {
            var construktion = new Construktion();

            construktion.AddRegistry(new StringBRegistry());
            construktion.AddRegistry(new StringARegistry());

            var result = construktion.Construct <string>();

            result.ShouldBe("StringB");
        }
示例#30
0
        public void should_handle_an_enunmerable_with_recursive_property_correctly()
        {
            var deepReccursion = new Construktion().Construct <DeepRecurrsionWithEnumerable>();

            deepReccursion.Name.ShouldNotBeNullOrWhiteSpace();

            deepReccursion.MyClass.ShouldAllBe(x => !string.IsNullOrWhiteSpace(x.Name));
            deepReccursion.MyClass.ShouldAllBe(x => !string.IsNullOrWhiteSpace(x.One.Name));
            deepReccursion.MyClass.ShouldAllBe(x => !string.IsNullOrWhiteSpace(x.One.Two.Name));
            deepReccursion.MyClass.ShouldAllBe(x => x.One.Two.One == null);
        }