public void RegisterTypeRegistration_Default_WithEnumerationParameter()
        {
            var itemNames = new string[]
            {
                "first",
                "second",
                "third"
            };
            var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer(EntLibContainer.ResolvedEnumerable<ISampleService>(itemNames)));
            registration.IsDefault = true;
            registration.Lifetime = TypeRegistrationLifetime.Transient;

            var builder = new ContainerBuilder();
            builder.RegisterTypeRegistration(registration);
            var first = new SampleServiceImpl();
            builder.RegisterInstance(first).Named<ISampleService>("first");
            var second = new SampleServiceImpl();
            builder.RegisterInstance(second).Named<ISampleService>("second");
            var third = new SampleServiceImpl();
            builder.RegisterInstance(third).Named<ISampleService>("third");
            var container = builder.Build();

            var resolved = container.Resolve<RegisteredServiceConsumer>();
            Assert.IsInstanceOf<IEnumerable<ISampleService>>(resolved.CtorParameter, "The constructor parameter was not the right type.");
            var services = ((IEnumerable<ISampleService>)resolved.CtorParameter).ToArray();
            Assert.AreSame(first, services[0], "The first enumerable service was not resolved properly.");
            Assert.AreSame(second, services[1], "The second enumerable service was not resolved properly.");
            Assert.AreSame(third, services[2], "The third enumerable service was not resolved properly.");
        }
        public void RegisterTypeRegistration_Default_NoParameters()
        {
            var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer());
            registration.IsDefault = true;
            registration.Lifetime = TypeRegistrationLifetime.Singleton;

            var builder = new ContainerBuilder();
            builder.RegisterTypeRegistration(registration);
            var container = builder.Build();

            var instance = container.Resolve<RegisteredServiceConsumer>();
            Assert.AreEqual("DEFAULTCTOR", instance.CtorParameter, "The default constructor should have been invoked.");
            var instance2 = container.Resolve<RegisteredServiceConsumer>();
            Assert.AreSame(instance, instance2, "The lifetime was not set on the registration.");
        }
        public void RegisterTypeRegistration_Default_WithSimpleParameter()
        {
            var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer("abc"));
            registration.IsDefault = true;
            registration.Lifetime = TypeRegistrationLifetime.Transient;

            var builder = new ContainerBuilder();
            builder.RegisterTypeRegistration(registration);
            var container = builder.Build();

            var instance = container.Resolve<RegisteredServiceConsumer>();
            Assert.AreEqual("abc", instance.CtorParameter, "The string parameter constructor should have been invoked with the appropriate argument.");
            var instance2 = container.Resolve<RegisteredServiceConsumer>();
            Assert.AreNotSame(instance, instance2, "The lifetime was not set on the registration.");
        }
 public void RegisterTypeRegistration_NullTypeRegistration()
 {
     TypeRegistration registration = null;
     var builder = new ContainerBuilder();
     Assert.Throws<ArgumentNullException>(() => builder.RegisterTypeRegistration(registration));
 }
        public void RegisterTypeRegistration_Named_WithParameters()
        {
            var registration = new TypeRegistration<RegisteredServiceConsumer>(() => new RegisteredServiceConsumer(EntLibContainer.Resolved<ISampleService>()));
            registration.Name = "named-service";
            registration.Lifetime = TypeRegistrationLifetime.Transient;

            var dependency = new SampleServiceImpl();
            var builder = new ContainerBuilder();
            builder.RegisterTypeRegistration(registration);
            builder.RegisterInstance(dependency).As<ISampleService>();
            var container = builder.Build();

            var instance = container.ResolveNamed<RegisteredServiceConsumer>("named-service"); ;
            Assert.AreSame(dependency, instance.CtorParameter, "The service implementation parameter constructor should have been invoked with the appropriate argument.");
            var instance2 = container.ResolveNamed<RegisteredServiceConsumer>("named-service"); ;
            Assert.AreNotSame(instance, instance2, "The lifetime was not set on the registration.");
        }