コード例 #1
0
        public void ExternalInstances()
        {
            var d1      = new BuilderTests.Dep1();
            var builder = new ContainerBuilder();

            builder.Register(d1);
            builder.Register(typeof(BuilderTests.Dep3));
            builder.Register <BuilderTests.DepB>();

            DependencyMissingException dme = null;

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

            Assert.Equal(1, dme.Created.Count);
            Assert.IsType <BuilderTests.Dep3>(dme.Created[0]);
        }
コード例 #2
0
        public void NiceMissingError()
        {
            var builder = new ContainerBuilder();

            builder.Register <C <A> >();

            DependencyMissingException dme = null;

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

            var expected = String.Join(Environment.NewLine, new[]
            {
                "Missing:",
                "  SingletonContainer.Tests.ExceptionTests.A",
                "Incomplete:",
                "  SingletonContainer.Tests.ExceptionTests.C<SingletonContainer.Tests.ExceptionTests.A>(SingletonContainer.Tests.ExceptionTests.A)",
            });

            Assert.Equal(expected, dme.Message);
        }
コード例 #3
0
        public void MissingDependency()
        {
            var builder = new ContainerBuilder();

            builder.Register <DepB>();
            builder.Register <Dep1>();

            DependencyMissingException mde = null;

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

            Assert.Equal(new[] { typeof(DepA) }, mde.Missing, EqualityComparer <Type> .Default);
        }