예제 #1
0
        public void Message_InnerExceptionMessageIncluded()
        {
            // Issue 343: The inner exception message should be included in the main exception message.
            var inner = new Exception("Can't find file.");
            var dre   = new DependencyResolutionException("Unable to resolve component.", inner);

            Assert.True(dre.Message.Contains("Can't find file."), "The exception message should include the inner exception message.");
        }
        public void Message_NullMessageWithInnerException()
        {
            // Issue 343: If there is no message but there is an inner exception specified, the main exception message should be modified.
            var inner = new Exception("Can't find file.");
            var dre   = new DependencyResolutionException(null, inner);

            Assert.True(dre.Message.Contains("Can't find file."), "The exception message should include the inner exception message.");
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstructorArgumentsMismatchException"/> class.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="typedFactoryType">
 /// The type of the factory interface.
 /// </param>
 /// <param name="nonMatchingParameters">
 /// The list of non-matching parameters.
 /// </param>
 /// <param name="innerException">
 /// The inner exception, documenting the resolution failure.
 /// </param>
 public ConstructorArgumentsMismatchException(string message,
                                              Type typedFactoryType,
                                              ParameterInfo[] nonMatchingParameters,
                                              DependencyResolutionException innerException)
     : base(message, innerException)
 {
     this.TypedFactoryType      = typedFactoryType;
     this.NonMatchingParameters = nonMatchingParameters;
 }
예제 #4
0
        public static void Test_Can_Resolve_GameTickables()
        {
            //arrange
            //TODO: This won't work if we have multiple configurable modules.
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            //Manually register SceneJect services
            builder.Register(context => new DefaultGameObjectFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultGameObjectComponentAttachmentFactory(context.Resolve <ILifetimeScope>(), new DefaultInjectionStrategy()))
            .As <IGameObjectComponentAttachmentFactory>()
            .SingleInstance();

            builder.Register(context => new DefaultManualInjectionStrategy(context.Resolve <IComponentContext>()))
            .As <IManualInjectionStrategy>()
            .SingleInstance();

            IContainer resolver = builder.Build();

            //act
            IReadOnlyCollection <IGameTickable> gameTickables = null;

            try
            {
                gameTickables = resolver.Resolve <IReadOnlyCollection <IGameTickable> >();
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }


            //assert
            Assert.NotNull(gameTickables);
            Console.WriteLine($"Found game tickable Count: {gameTickables.Count}");
            Assert.IsNotEmpty(gameTickables);
        }
예제 #5
0
        private static DependencyResolutionException PropagateActivationException(IInstanceActivator activator, Exception exception)
        {
            var activatorChain = activator.DisplayName();
            var innerException = exception;

            if (exception.Data.Contains(ActivatorChainExceptionData) &&
                exception.Data[ActivatorChainExceptionData] is string innerChain)
            {
                activatorChain = activatorChain + " -> " + innerChain;
                innerException = exception.InnerException;
            }

            var result = new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, ComponentActivationResources.ErrorDuringActivation, activatorChain), innerException);

            result.Data[ActivatorChainExceptionData] = activatorChain;
            return(result);
        }
예제 #6
0
        public static string GetMessage(this DependencyResolutionException ex)
        {
            if (ex.InnerException == null)
            {
                return(ex.Message);
            }

            if (ex.InnerException.InnerException == null)
            {
                return(ex.InnerException.Message);
            }

            var msg       = ex.InnerException.InnerException.Message;
            var resolving = msg.Between("DefaultConstructorFinder' on type '", "'");
            var argTyp    = msg.Between("Cannot resolve parameter '", " ");
            var argNme    = msg.Between(argTyp + " ", "'");

            return($"Check constructor of :{L.f}‹{resolving}›{L.F}"
                   + $"Can't resolve argument “{argNme}” of type :{L.f}‹{argTyp}›");
        }
예제 #7
0
        public void Test_Can_Create_IGameTickables()
        {
            //arrange
            IContainer container = BuildTestContainer();

            //assert
            try
            {
                container.Resolve <IEnumerable <IGameTickable> >();
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }
        }
        public void Message_NullInnerException()
        {
            var dre = new DependencyResolutionException("Unable to resolve component.", null);

            Assert.AreEqual("Unable to resolve component.", dre.Message, "The message should not be modified if there is no inner exception.");
        }
        public void Message_NoMessageOrInnerException()
        {
            var dre = new DependencyResolutionException(null);

            Assert.AreEqual("Exception of type 'Autofac.Core.DependencyResolutionException' was thrown.", dre.Message, "The message should not be modified if there is no inner exception.");
        }
예제 #10
0
        private static bool IsAutofacException(DependencyResolutionException e)
        {
            var inner = e.InnerException;

            return(inner == null || inner.GetType().FullName.StartsWith("Autofac"));
        }