示例#1
0
        Tuple<string, bool> HandleCompositionError(CompositionException e, ReportExceptionEventArgs et) {
            Tuple<string, bool> handled = null;
            if (e.Errors == null)
                return handled;
            foreach (var error in e.Errors.Where(x => x.Exception != null)) {
                if (handled == null || handled.Item1 == null)
                    handled = InternalHandler(error.Exception, et, true);
            }

            return handled;
        }
        public void Constructor5_ValueAsErrorsArgument_ShouldSetErrorsProperty()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", new Exception(), e);

                EnumerableAssert.AreSequenceSame(e, exception.Errors);
            }
        }
        public void Constructor5_ArrayAsAsErrorsArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var error  = CreateCompositionError();
            var errors = new CompositionError[] { error };

            var exception = new CompositionException("Message", new Exception(), errors);

            errors[0] = null;

            EnumerableAssert.AreEqual(exception.Errors, error);
        }
        public void Constructor5_ValueAsMessageArgument_ShouldSetMessageProperty()
        {
            var expectations = Expectations.GetExceptionMessages();

            foreach (var e in expectations)
            {
                var exception = new CompositionException(e, new Exception(), Enumerable.Empty <CompositionError>());

                Assert.AreEqual(e, exception.Message);
            }
        }
        public void Constructor5_ValueAsInnerExceptionArgument_ShouldSetInnerExceptionProperty()
        {
            var expectations = Expectations.GetInnerExceptions();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", e, Enumerable.Empty <CompositionError>());

                Assert.AreSame(e, exception.InnerException);
            }
        }
        public void Constructor2_ValueAsMessageArgument_ShouldSetMessageProperty()
        {
            var expectations = Expectations.GetExceptionMessages();

            foreach (var e in expectations)
            {
                var exception = new CompositionException(e);

                Assert.AreEqual(e, exception.Message);
            }
        }
示例#7
0
        public void Constructor5_ValueAsErrorsArgument_ShouldSetErrorsProperty()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", new Exception(), e);

                EqualityExtensions.CheckEquals(e, exception.Errors);
            }
        }
示例#8
0
        public void Constructor4_ValueAsInnerExceptionArgument_ShouldSetInnerExceptionProperty()
        {
            var expectations = Expectations.GetInnerExceptions();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", e);

                Assert.Same(e, exception.InnerException);
            }
        }
示例#9
0
        private static void VisitCompositionException(CompositionException exception, VisitContext context)
        {
            foreach (CompositionError error in exception.Errors)
            {
                VisitError(error, context);
            }

            if (exception.InnerException != null)
            {
                VisitException(exception.InnerException, context);
            }
        }
示例#10
0
        private static void VisitException(Exception exception, VisitContext context)
        {
            CompositionException composition = exception as CompositionException;

            if (composition != null)
            {
                VisitCompositionException(composition, context);
            }
            else
            {
                VisitError(new CompositionError(exception.Message, exception.InnerException), context);
            }
        }
示例#11
0
        private void AssertMessage(CompositionException exception, string[] expected)
        {
            using (StringReader reader = new StringReader(exception.Message))
            {
                // Skip header
                reader.ReadLine();

                foreach (string expect in expected)
                {
                    // Skip blank line
                    reader.ReadLine();
                    Assert.Equal(FixMessage(expect), reader.ReadLine());
                }
            }
        }
示例#12
0
        private static CompositionError CreateCompositionError(params string[] messages)
        {
            CompositionError error = null;

            foreach (string message in messages.Reverse())
            {
                CompositionException exception = null;
                if (error != null)
                {
                    exception = CreateCompositionException(error);
                }

                error = ErrorFactory.Create(message, exception);
            }

            return(error);
        }
示例#13
0
        private static IEnumerable <IEnumerable <CompositionError> > CalculatePaths(CompositionException exception)
        {
            List <IEnumerable <CompositionError> > paths = new List <IEnumerable <CompositionError> >();

            VisitContext context = new VisitContext();

            context.Path        = new Stack <CompositionError>();
            context.LeafVisitor = path =>
            {
                // Take a snapshot of the path
                paths.Add(path.Copy());
            };

            VisitCompositionException(exception, context);

            return(paths);
        }
示例#14
0
        private void AssertMessage(CompositionException exception, int rootCauseCount, CultureInfo culture)
        {
            using (StringReader reader = new StringReader(exception.Message))
            {
                string line = reader.ReadLine();

                if (rootCauseCount == 1)
                {
                    Assert.True(line.Contains(SR.CompositionException_SingleErrorWithSinglePath));
                }
                else
                {
                    Assert.True(
                        line.Contains(string.Format(CultureInfo.CurrentCulture, SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount)) ||
                        line.Contains(string.Format(CultureInfo.CurrentCulture, SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount))
                        );
                }
            }
        }
        private void AssertMessage(CompositionException exception, string[] expected)
        {
            if (PlatformDetection.IsNetNative)
            {
                return;
            }
            using (StringReader reader = new StringReader(exception.Message))
            {
                // Skip header
                reader.ReadLine();

                foreach (string expect in expected)
                {
                    // Skip blank line
                    reader.ReadLine();
                    Assert.Equal(FixMessage(expect), reader.ReadLine());
                }
            }
        }
示例#16
0
        public void Message_ShouldFormatCountOfRootCausesUsingTheCurrentCulture()
        {
            IEnumerable <CultureInfo> cultures = Expectations.GetCulturesForFormatting();

            foreach (CultureInfo culture in cultures)
            {
                // Save old culture and set a fixed culture for object instantiation
                using (new ThreadCultureChange(culture))
                {
                    CompositionError[]   errors    = CreateCompositionErrors(1000);
                    CompositionException exception = CreateCompositionException(errors);
                    AssertMessage(exception, 1000, culture);

                    errors    = CreateCompositionErrors(1);
                    exception = CreateCompositionException(errors);
                    AssertMessage(exception, 1, culture);
                }
            }
        }
示例#17
0
        private void AssertMessage(CompositionException exception, int rootCauseCount, CultureInfo culture)
        {
            using (StringReader reader = new StringReader(exception.Message))
            {
                string line = reader.ReadLine();

                if (rootCauseCount == 1)
                {
                    Assert.Contains(SR.CompositionException_SingleErrorWithSinglePath, line);
                }
                else
                {
                    string option1 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount);
                    string option2 = string.Format(CultureInfo.CurrentCulture, SR.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount);
                    if (!line.Contains(option1) && !line.Contains(option2))
                    {
                        throw new XunitException($"`{line}` contains neither `{option1}` nor `{option2}`");
                    }
                }
            }
        }
示例#18
0
        public void Constructor5_NullAsMessageArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException((string)null, new Exception(), Enumerable.Empty<CompositionError>());

            ExceptionAssert.HasDefaultMessage(exception);
        }
        public CompositionExceptionDebuggerProxy(CompositionException exception)
        {
            Requires.NotNull(exception, "exception");

            this._exception = exception;
        }
        public void Constructor2_NullAsErrorsArgument_ShouldSetErrorsPropertyToEmptyEnumerable()
        {
            var exception = new CompositionException((IEnumerable <CompositionError>)null);

            Assert.Empty(exception.Errors);
        }
示例#21
0
        public void Constructor2_NullAsMessageArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException((string)null);

            ExceptionAssert.HasDefaultMessage(exception);
        }
示例#22
0
        public void Constructor2_NullAsErrorsArgument_ShouldSetErrorsPropertyToEmptyEnumerable()
        {
            var exception = new CompositionException((IEnumerable<CompositionError>)null);

            EnumerableAssert.IsEmpty(exception.Errors);
        }
示例#23
0
        public void Constructor5_EmptyEnumerableAsErrorsArgument_ShouldSetErrorsPropertyToEmptyEnumerable()
        {
            var exception = new CompositionException("Message", new Exception(), Enumerable.Empty<CompositionError>());

            EnumerableAssert.IsEmpty(exception.Errors);
        }
        public void Constructor3_EmptyEnumerableAsErrorsArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException(Enumerable.Empty <CompositionError>());

            ExceptionAssert.HasDefaultMessage(exception);
        }
示例#25
0
        public void Constructor5_NullAsInnerExceptionArgument_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message", (Exception)null, Enumerable.Empty<CompositionError>());

            Assert.IsNull(exception.InnerException);
        }
        public void Constructor5_EmptyEnumerableAsErrorsArgument_ShouldSetErrorsPropertyToEmptyEnumerable()
        {
            var exception = new CompositionException("Message", new Exception(), Enumerable.Empty <CompositionError>());

            Assert.Empty(exception.Errors);
        }
        public void Constructor2_NullAsMessageArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException((string)null);

            ExceptionAssert.HasDefaultMessage(exception);
        }
        public void Constructor4_ShouldSetErrorsPropertyToEmptyEnumerable()
        {
            var exception = new CompositionException("Message", new Exception());

            Assert.Empty(exception.Errors);
        }
        public void Constructor3_ShouldSetErrorsPropertyToEmpty()
        {
            var exception = new CompositionException();

            Assert.Empty(exception.Errors);
        }
        public void Constructor1_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException();

            ExceptionAssert.HasDefaultMessage(exception);
        }
        public void Constructor4_NullAsInnerExceptionArgument_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message", (Exception)null);

            Assert.Null(exception.InnerException);
        }
        public void Constructor2_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message");

            Assert.Null(exception.InnerException);
        }
示例#33
0
        public void Constructor4_NullAsInnerExceptionArgument_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message", (Exception)null);

            Assert.IsNull(exception.InnerException);
        }
        private static void VisitCompositionException(CompositionException exception, VisitContext context)
        {
            foreach (CompositionError error in exception.Errors)
            {
                VisitError(error, context);
            }

            if (exception.InnerException != null)
            {
                VisitException(exception.InnerException, context);
            }
        }
示例#35
0
        public void Constructor5_ValueAsInnerExceptionArgument_ShouldSetInnerExceptionProperty()
        {
            var expectations = Expectations.GetInnerExceptions();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", e, Enumerable.Empty<CompositionError>());

                Assert.AreSame(e, exception.InnerException);
            }
        }
示例#36
0
        public void Constructor5_ArrayAsAsErrorsArgument_ShouldNotAllowModificationAfterConstruction()
        {
            var error = CreateCompositionError();
            var errors = new CompositionError[] { error };

            var exception = new CompositionException("Message", new Exception(), errors);

            errors[0] = null;

            EnumerableAssert.AreEqual(exception.Errors, error);
        }
示例#37
0
        public void Constructor3_ShouldSetErrorsPropertyToEmpty()
        {
            var exception = new CompositionException();

            EnumerableAssert.IsEmpty(exception.Errors);
        }
示例#38
0
        private void AssertMessage(CompositionException exception, string[] expected)
        {
            using (StringReader reader = new StringReader(exception.Message))
            {
                // Skip header
                reader.ReadLine();

                foreach (string expect in expected)
                {
                    // Skip blank line
                    reader.ReadLine();
                    Assert.AreEqual(FixMessage(expect), reader.ReadLine());
                }
            }
        }
示例#39
0
        public void Constructor5_ValueAsErrorsArgument_ShouldSetErrorsProperty()
        {
            var expectations = Expectations.GetCompositionErrors();

            foreach (var e in expectations)
            {
                var exception = new CompositionException("Message", new Exception(), e);

                EnumerableAssert.AreSequenceSame(e, exception.Errors);
            }
        }
        public void Constructor5_NullAsInnerExceptionArgument_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message", (Exception)null, Enumerable.Empty <CompositionError>());

            Assert.Null(exception.InnerException);
        }
示例#41
0
        private void AssertMessage(CompositionException exception, int rootCauseCount, CultureInfo culture)
        {
            using (StringReader reader = new StringReader(exception.Message))
            {
                string line = reader.ReadLine();

                if (rootCauseCount == 1)
                {
                    Assert.IsTrue(line.Contains(Strings.CompositionException_SingleErrorWithSinglePath));
                }
                else
                {
                    Assert.IsTrue(
                        line.Contains(string.Format(CultureInfo.CurrentCulture, Strings.CompositionException_SingleErrorWithMultiplePaths, rootCauseCount)) ||
                        line.Contains(string.Format(CultureInfo.CurrentCulture, Strings.CompositionException_MultipleErrorsWithMultiplePaths, rootCauseCount))
                        );
                }
            }
        }
        static Exception FindException(CompositionException exception) {
            foreach (var e in exception.Errors) {
                if (e.Exception is Win32Exception)
                    return e.Exception;

                var ce = e.Exception as CompositionException;
                if (ce != null) {
                    var found = FindException(ce);
                    if (found != null)
                        return found;
                }

                var ae = e.Exception as AggregateException;
                if (ae != null) {
                    var found = FindException(ae);
                    if (found != null)
                        return found;
                }

                if (!(e.Exception is XamlException))
                    continue;

                var inner = e.Exception.FindInnerException<Win32Exception>();
                if (inner != null)
                    return inner;
            }
            return null;
        }
示例#43
0
        public void Constructor1_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException();

            ExceptionAssert.HasDefaultMessage(exception);
        }
示例#44
0
        public void Constructor2_ValueAsMessageArgument_ShouldSetMessageProperty()
        {
            var expectations = Expectations.GetExceptionMessages();

            foreach (var e in expectations)
            {
                var exception = new CompositionException(e);

                Assert.AreEqual(e, exception.Message);
            }
        }
示例#45
0
        public void Constructor3_EmptyEnumerableAsErrorsArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException(Enumerable.Empty<CompositionError>());

            ExceptionAssert.HasDefaultMessage(exception);
        }
示例#46
0
        public void Constructor5_ValueAsMessageArgument_ShouldSetMessageProperty()
        {
            var expectations = Expectations.GetExceptionMessages();

            foreach (var e in expectations)
            {
                var exception = new CompositionException(e, new Exception(), Enumerable.Empty<CompositionError>());

                Assert.AreEqual(e, exception.Message);
            }
        }
示例#47
0
        /// <summary>
        /// Reports the composition error.
        /// </summary>
        private void ReportPluginCompositionError(CompositionException ex)
        {
            // save composition errors to string
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                var ci = new CompositionInfo(this.compositionContainer.Catalog, this.compositionContainer);
                CompositionInfoTextFormatter.Write(ci, sw);

                // create error and add it to our list
                this.errors.Add(new PluginLoadError
                {
                    Message = sw.GetStringBuilder().ToString(),
                    Exception = ex,
                    Plugin = null
                });
            }
        }
示例#48
0
        public void Constructor2_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException("Message");

            Assert.IsNull(exception.InnerException);
        }
示例#49
0
        public void Constructor3_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException(Enumerable.Empty<CompositionError>());

            Assert.IsNull(exception.InnerException);
        }
        public void Constructor3_ShouldSetInnerExceptionPropertyToNull()
        {
            var exception = new CompositionException(Enumerable.Empty <CompositionError>());

            Assert.Null(exception.InnerException);
        }
        private static IEnumerable<IEnumerable<CompositionError>> CalculatePaths(CompositionException exception)
        {
            List<IEnumerable<CompositionError>> paths = new List<IEnumerable<CompositionError>>();

            VisitContext context = new VisitContext();
            context.Path = new Stack<CompositionError>();
            context.LeafVisitor = path =>
            {
                // Take a snapshot of the path
                paths.Add(path.Copy());
            };

            VisitCompositionException(exception, context);

            return paths;
        }
        public void Constructor5_NullAsMessageArgument_ShouldSetMessagePropertyToDefault()
        {
            var exception = new CompositionException((string)null, new Exception(), Enumerable.Empty <CompositionError>());

            ExceptionAssert.HasDefaultMessage(exception);
        }
        public CompositionExceptionDebuggerProxy(CompositionException exception)
        {
            Requires.NotNull(exception, nameof(exception));

            _exception = exception;
        }
示例#54
0
            void ISafeSerializationData.CompleteDeserialization(object obj)
            {
                CompositionException exception = obj as CompositionException;

                exception._errors = new ReadOnlyCollection <CompositionError>(this._errors);
            }