public void When_a_non_open_generic_type_is_registered_as_the_variantsOf_argument_then_it_throws()
        {
            var container = new PocketContainer();

            Action registerWrongType = () =>
                container.RegisterGeneric(typeof (string), typeof (List<>));

            registerWrongType.ShouldThrow<ArgumentException>().And.Message.Should().Contain("'variantsOf'");
        }
Пример #2
0
        public void When_a_non_open_generic_type_is_registered_as_the_to_argument_then_it_throws()
        {
            var container = new PocketContainer();

            Action registerWrongType = () =>
                                       container.RegisterGeneric(typeof(IEnumerable <>), typeof(string));

            registerWrongType.ShouldThrow <ArgumentException>().And.Message.Should().Contain("'to'");
        }
Пример #3
0
        public void An_open_generic_interface_can_be_registered_to_an_open_generic_type_and_resolved_correctly()
        {
            var container = new PocketContainer();

            container
            .RegisterGeneric(
                variantsOf: typeof(IAmAGenericInterface <>),
                to: typeof(IAmAGenericImplementation <>));

            container.Resolve <IAmAGenericInterface <string> >()
            .Should()
            .BeOfType <IAmAGenericImplementation <string> >();
        }
Пример #4
0
        public void Open_generic_registrations_can_be_singletons()
        {
            var container = new PocketContainer();

            container
            .RegisterGeneric(
                variantsOf: typeof(IAmAGenericInterface <>),
                to: typeof(IAmAGenericImplementation <>),
                singletons: true);

            var resolvedOnce  = container.Resolve <IAmAGenericInterface <int> >();
            var resolvedTwice = container.Resolve <IAmAGenericInterface <int> >();

            resolvedOnce
            .Should()
            .BeSameAs(resolvedTwice);
        }