コード例 #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>());
        }
コード例 #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);
        }
コード例 #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);
        }