Ejemplo n.º 1
0
        public void LazyCollectionBuilderHandlesTypesAndProducers()
        {
            IServiceCollection container = CreateRegister();
            var composition = new UmbracoBuilder(container, Mock.Of <IConfiguration>(), TestHelper.GetMockedTypeLoader());

            composition.WithCollectionBuilder <TestCollectionBuilder>()
            .Add <TransientObject3>()
            .Add <TransientObject2>()
            .Add <TransientObject3>()
            .Add(() => new[] { typeof(TransientObject1) });

            IServiceProvider factory = composition.CreateServiceProvider();

            TestCollection values = factory.GetRequiredService <TestCollection>();

            Assert.AreEqual(3, values.Count());
            Assert.IsTrue(values.Select(x => x.GetType())
                          .ContainsAll(new[] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) }));

            TestCollection other = factory.GetRequiredService <TestCollection>();

            Assert.AreNotSame(values, other); // transient
            ITestInterface o1 = other.FirstOrDefault(x => x is TransientObject1);

            Assert.IsFalse(values.Contains(o1)); // transient
        }