Exemplo n.º 1
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());
        }
Exemplo n.º 2
0
        public void should_always_use_the_same_instance_when_injected_from_pipeline()
        {
            var construktion = new Construktion().Apply(new FooBlueprint());

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

            foo.GetHashCode().ShouldBe(result.Foo.GetHashCode());

            result.Foo
            .GetHashCode()
            .ShouldBe(result2.Foo.GetHashCode());
        }
        public void should_throw_when_opted_in()
        {
            registry.ThrowOnRecursion(true);
            var construktion = new Construktion().Apply(registry);

            Exception <Exception> .ShouldBeThrownBy(() => construktion.Construct <Parent>());
        }
Exemplo n.º 4
0
        public void should_always_use_the_same_instance()
        {
            var foo          = new Foo();
            var construktion = new Construktion().Inject(foo);

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

            result.Foo
            .GetHashCode()
            .ShouldBe(foo.GetHashCode());

            result2.Foo
            .GetHashCode()
            .ShouldBe(foo.GetHashCode());
        }
        public void should_add_through_construktion()
        {
            var construktion = new Construktion().Apply(new FooExitBlueprint());

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

            foo.Id.ShouldBe(10);
        }
Exemplo n.º 6
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>());
        }
        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_still_throw()
        {
            registry.ThrowOnRecursion(true);
            var newRegistry  = new ConstruktionRegistry();
            var construktion = new Construktion().Apply(registry).Apply(newRegistry);

            Exception <Exception> .ShouldBeThrownBy(() => construktion.Construct <Parent>());
        }
Exemplo n.º 10
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");
        }
Exemplo n.º 11
0
        public void should_omit_ids()
        {
            _registry.OmitIds();
            var construktion = new Construktion().AddRegistry(_registry);

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

            foo.FooId.ShouldBe(0);
        }
        public void should_construct()
        {
            var context = new Construktion().Apply(new FooBlueprint());

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

            result.Name.ShouldBe("Name");
            result.Age.ShouldBe(10);
        }
Exemplo n.º 13
0
        public void should_construct_email()
        {
            var construktion = new Construktion().Apply(x => x.AddEmailBlueprint());

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

            result.Email.ShouldContain("@");
            result.Custom.ShouldNotContain("@");
        }
Exemplo n.º 14
0
        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("@");
        }
Exemplo n.º 15
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_not_pass_nulls_to_exit_blueprint()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.AddBlueprint <NullFooBlueprint>();
                x.AddExitBlueprint <IFooExitBlueprint>();
            });

            Should.NotThrow(() => construktion.Construct <Foo>().ShouldBeNull());
        }
        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();
        }
Exemplo n.º 18
0
        public void new_registries_without_a_setting_should_not_overwrite()
        {
            var registry     = new ConstruktionRegistry(x => x.MaxDepth(1));
            var registry2    = new ConstruktionRegistry();
            var construktion = new Construktion().Apply(registry).Apply(registry2);

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

            result.LevelTwo.ShouldNotBe(null);
            result.LevelTwo.Name.ShouldBe(null);
        }
Exemplo n.º 19
0
        public void new_registries_should_overwrite_previous()
        {
            var registry     = new ConstruktionRegistry(x => x.MaxDepth(2));
            var registry2    = new ConstruktionRegistry(x => x.MaxDepth(1));
            var construktion = new Construktion().Apply(registry).Apply(registry2);

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

            result.LevelTwo.ShouldNotBe(null);
            result.LevelTwo.Name.ShouldBe(null);
        }
        public void should_be_case_sensitive()
        {
            var registry = new BlueprintRegistry();

            registry.OmitIds();
            var construktion = new Construktion().AddRegistry(registry);

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

            foo.Fooid.ShouldNotBe(0);
        }
        public void should_be_able_to_define_a_custom_convention()
        {
            var registry = new BlueprintRegistry();

            registry.OmitProperties(x => x.EndsWith("_Id"), typeof(string));
            var construktion = new Construktion().AddRegistry(registry);

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

            foo.String_Id.ShouldBe(null);
        }
Exemplo n.º 22
0
        public void should_construct_using_supplied_function()
        {
            var registry =
                new ConstruktionRegistry().ConstructPropertyUsing(p => p.Name.Equals("Credits"),
                                                                  () => new Random().Next(1, 5));
            var construktion = new Construktion().Apply(registry);

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

            foo.Credits.ShouldBeInRange(1, 4);
        }
Exemplo n.º 23
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");
        }
Exemplo n.º 24
0
        public void should_have_configurable_recursion_depth()
        {
            var construction = new Construktion().Apply(x => x.RecursionLimit(1));

            var parent = construction.Construct <Parent>();

            var firstRecursiveParent   = parent.Child.RecursiveParent;
            var secondRecurssiveParent = firstRecursiveParent.Child.RecursiveParent;

            firstRecursiveParent.ShouldNotBe(null);
            secondRecurssiveParent.ShouldBe(null);
        }
        public void should_not_alter_constructed_values()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.OmitIds();
                x.AddExitBlueprint <FooExitBlueprint>();
            });

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

            foo.Name.ShouldNotBeNullOrWhiteSpace();
        }
        public void should_work_for_interfaces()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.OmitIds();
                x.AddExitBlueprint <IFooExitBlueprint>();
            });

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

            foo.Id.ShouldBe(10);
        }
        public void should_override_matches()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.ConstructPropertyUsing(prop => prop.Name == nameof(Foo.Name), () => "Ping");
                x.AddExitBlueprint <FooPingPongExitBlueprint>();
            });

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

            foo.Name.ShouldBe("PingPong");
        }
        public void should_apply_value_after_the_normal_blueprints()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.OmitIds();
                x.AddExitBlueprint <FooExitBlueprint>();
            });

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

            foo.Id.ShouldBe(10);
        }
Exemplo n.º 29
0
        public void should_construct_deeper()
        {
            var registry     = new ConstruktionRegistry(x => x.MaxDepth(2));
            var construktion = new Construktion().Apply(registry);

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

            result.LevelTwo.ShouldNotBe(null);
            result.LevelTwo.Name.ShouldNotBe(null);
            result.LevelTwo.LevelThree.ShouldNotBe(null);
            result.LevelTwo.LevelThree.Name.ShouldBe(null);
        }
        public void only_types_of_T_should_match()
        {
            var construktion = new Construktion().Apply(x =>
            {
                x.ConstructPropertyUsing(prop => prop.Name == nameof(Bar.Name), () => "Ping");
                x.AddExitBlueprint <FooPingPongExitBlueprint>();
            });

            var bar = construktion.Construct <Bar>();

            bar.Name.ShouldNotBe("PingPong");
            bar.Name.ShouldBe("Ping");
        }