public void NiceCycleError()
        {
            var builder = new ContainerBuilder();

            builder.Register <BuilderTests.DepCycle2>();
            builder.Register <BuilderTests.DepCycle1>();

            DependencyCycleException dce = null;

            Assert.Throws <DependencyCycleException>(() =>
            {
                try
                {
                    builder.Build();
                }
                catch (DependencyCycleException e)
                {
                    dce = e;
                    throw;
                }
            });

            var expected = String.Join(Environment.NewLine, new[]
            {
                "Incomplete:",
                "  SingletonContainer.Tests.BuilderTests.DepCycle1(SingletonContainer.Tests.BuilderTests.DepCycle2)",
                "  SingletonContainer.Tests.BuilderTests.DepCycle2(SingletonContainer.Tests.BuilderTests.DepCycle1)",
            });

            Assert.Equal(expected, dce.Message);
        }
예제 #2
0
        public void CycleExceptionDetails()
        {
            var builder = new ContainerBuilder();

            builder.Register <DepCycle4>();
            builder.Register <DepCycle3>();
            builder.Register <Dep1>();

            DependencyCycleException dce = null;

            Assert.Throws <DependencyCycleException>(() =>
            {
                try
                {
                    builder.Build();
                }
                catch (DependencyCycleException e)
                {
                    dce = e;
                    throw;
                }
            });

            Assert.Equal(
                new[] { typeof(DepCycle3), typeof(DepCycle4) },
                dce.Incomplete.OrderBy(t => t.Name));
        }