Exemplo n.º 1
0
        public void RegistrationErrorHandlingTest()
        {
            var container = new PandaContainer();

            Should.Throw <InvalidOperationException>(() => container.Resolve <IRegistrationTest>());

            container.RegisterType <NoPublicConstructorTest, NoPublicConstructorTest>();

            Should.Throw <InvalidOperationException>(() => container.Resolve <NoPublicConstructorTest>());
            Should.Throw <InvalidOperationException>(() => container.RegisterType <NoPublicConstructorTest, NoPublicConstructorTest>());
            Should.Throw <InvalidOperationException>(() => container.RegisterSingletonType <NoPublicConstructorTest, NoPublicConstructorTest>());

            container.RegisterType <ParameterizedConstructorTest, ParameterizedConstructorTest>();

            Should.Throw <InvalidOperationException>(() => container.Resolve <ParameterizedConstructorTest>());
        }
Exemplo n.º 2
0
        public void SingleInstanceRegistrationTest()
        {
            var container = new PandaContainer();

            container.RegisterSingletonType <IRegistrationTest, RegistrationTest>();

            var instance = container.Resolve <IRegistrationTest>();

            instance.Name.ShouldBeNull();
            instance.Value.ShouldBeNull();

            var anotherInstance = container.Resolve <IRegistrationTest>(
                new InjectProperty("Test", "Name"),
                new InjectProperty("Value", "Value"));

            anotherInstance.ShouldBeSameAs(instance);
        }
Exemplo n.º 3
0
        public void SingleInstanceCustomFactoryRegistrationTest()
        {
            var container = new PandaContainer();

            container.RegisterSingletonType <IRegistrationTest>(() => new RegistrationTest {
                Name = "CustomName", Value = "CustomValue"
            });

            var instance = container.Resolve <IRegistrationTest>();

            instance.Name.ShouldBe("CustomName");
            instance.Value.ShouldBe("CustomValue");

            var anotherInstance = container.Resolve <IRegistrationTest>();

            anotherInstance.ShouldBeSameAs(instance);
        }
Exemplo n.º 4
0
        public void MultipleInstanceTypeOfRegistrationTest()
        {
            var container = new PandaContainer();

            container.RegisterType <IRegistrationTest>(typeof(RegistrationTest));

            var instance = container
                           .Resolve(typeof(IRegistrationTest))
                           .ShouldBeOfType <RegistrationTest>();

            instance.Name.ShouldBeNull();
            instance.Value.ShouldBeNull();
        }
Exemplo n.º 5
0
        public void MultipleInstanceCustomFactoryRegistrationTest()
        {
            var container = new PandaContainer();

            container.RegisterType <IRegistrationTest>(() => new RegistrationTest {
                Name = "CustomName", Value = "CustomValue"
            });

            var instance = container.Resolve <IRegistrationTest>();

            instance.Name.ShouldBe("CustomName");
            instance.Value.ShouldBe("CustomValue");
        }
Exemplo n.º 6
0
        public void ParameterizedConstructorRegistrationTest()
        {
            var container = new PandaContainer();

            container.RegisterType <IRegistrationTest>(() => new RegistrationTest {
                Name = "42"
            });
            container.RegisterType <ParameterizedConstructorTest, ParameterizedConstructorTest>();

            var instance = container.Resolve <ParameterizedConstructorTest>();

            instance.Container.ShouldBeSameAs(container);
            instance.TestProperty.ShouldNotBeNull();
            instance.TestProperty.Name.ShouldBe("42");
        }