Exemple #1
0
        public void ResolverWithElementsReturnsEmptyArrayIfThereAreNoElements()
        {
            // Arrange
            object o1 = new object();
            object o2 = new object();

            Container.RegisterInstance("o1", o1)
            .RegisterInstance("o2", o2)

            .RegisterType <InjectedObject>(Invoke.Constructor(Inject.Array <object>()))

            .RegisterType <InjectedObject>(Legacy,
                                           new InjectionConstructor(new ResolvedArrayParameter(typeof(object))));

            // Act
            var result = (object[])Container.Resolve <InjectedObject>().InjectedValue;
            var legacy = (object[])Container.Resolve <InjectedObject>(Legacy).InjectedValue;

            // Validate
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Length);

            Assert.IsNotNull(legacy);
            Assert.AreEqual(0, legacy.Length);
        }
        public static IEnumerable <object[]> GetInjectArrayVariants()
        {
            yield return(new object[] { Inject.Array(typeof(string)) });

            yield return(new object[] { Inject.Array(typeof(string), string.Empty) });

            yield return(new object[] { Inject.Array <string>(string.Empty) });
        }
Exemple #3
0
        public void ResolverWithElementsReturnsResolvedElements()
        {
            // Arrange
            object o1 = new object();
            object o2 = new object();
            object o3 = new object();

            Container.RegisterInstance("o1", o1)
            .RegisterInstance("o2", o2)
            .RegisterInstance("o3", o3)

            .RegisterType <InjectedObject>(
                Invoke.Constructor(
                    Inject.Array(typeof(object),
                                 Resolve.Dependency <object>("o1"),
                                 Resolve.Dependency <object>("o2"))))

            .RegisterType <InjectedObject>(Legacy,
                                           new InjectionConstructor(
                                               new ResolvedArrayParameter(typeof(object),
                                                                          new ResolvedParameter <object>("o1"),
                                                                          new ResolvedParameter <object>("o2"))));
            // Act
            var result = (object[])Container.Resolve <InjectedObject>().InjectedValue;
            var legacy = (object[])Container.Resolve <InjectedObject>().InjectedValue;

            // Validate
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Length);
            Assert.AreSame(o1, result[0]);
            Assert.AreSame(o2, result[1]);

            Assert.IsNotNull(legacy);
            Assert.AreEqual(2, legacy.Length);
            Assert.AreSame(o1, legacy[0]);
            Assert.AreSame(o2, legacy[1]);
        }