コード例 #1
0
        public void WhenEnumTypeIsProvidedForIntParameterConversionWillBeAttempted()
        {
            var ci  = typeof(CtorWithInt).GetTypeInfo().DeclaredConstructors.Single();
            var cpb = new ConstructorParameterBinding(
                ci, new[] { new PositionalParameter(0, Foo.B), }, new ContainerBuilder().Build());
            var instance = (CtorWithInt)cpb.Instantiate();

            Assert.Equal(1, instance.Value);
        }
コード例 #2
0
        public void WhenAnExceptionIsThrownFromAConstructor_TheInnerExceptionIsWrapped()
        {
            var ci  = typeof(ThrowsInCtor).GetTypeInfo().DeclaredConstructors.Single();
            var cpb = new ConstructorParameterBinding(
                ci, Enumerable.Empty <Parameter>(), new ContainerBuilder().Build());
            var dx = Assert.Throws <DependencyResolutionException>(() =>
                                                                   cpb.Instantiate());

            Assert.True(dx.Message.Contains(typeof(ThrowsInCtor).Name));
            Assert.Equal(ThrowsInCtor.Message, dx.InnerException.Message);
        }
コード例 #3
0
        public void WhenAnExceptionIsThrownFromAConstructor_TheInnerExceptionIsWrapped()
        {
            var ci  = typeof(ThrowsInCtor).GetConstructor(new Type[0]);
            var cpb = new ConstructorParameterBinding(
                ci, Enumerable.Empty <Parameter>(), Container.Empty);
            var dx = Assert.Throws <DependencyResolutionException>(() =>
                                                                   cpb.Instantiate());

            Assert.That(dx.Message.Contains(typeof(ThrowsInCtor).Name));
            Assert.AreEqual(ThrowsInCtor.Message, dx.InnerException.Message);
        }