public void Message_ShouldIncludeElementGraph() { var expectations = new ExpectationCollection <CompositionError, string>(); CompositionError error = null; error = CreateCompositionErrorWithElementChain(1); expectations.Add(error, GetElementGraphString(error)); error = CreateCompositionErrorWithElementChain(2); expectations.Add(error, GetElementGraphString(error)); error = CreateCompositionErrorWithElementChain(3); expectations.Add(error, GetElementGraphString(error)); error = CreateCompositionErrorWithElementChain(10); expectations.Add(error, GetElementGraphString(error)); foreach (var e in expectations) { var exception = CreateCompositionException(new CompositionError[] { e.Input }); string result = exception.ToString(); string expected = FixMessage(e.Output); AssertExtensions.Contains(result, expected); } }
public static CompositionError ComposeTookTooManyIterations(int maximumNumberOfCompositionIterations) { return(CompositionError.Create( CompositionErrorId.ImportEngine_ComposeTookTooManyIterations, SR.ImportEngine_ComposeTookTooManyIterations, maximumNumberOfCompositionIterations)); }
public static CompositionError InvalidStateForRecompposition(ComposablePart part) { return(CompositionError.Create( CompositionErrorId.ImportEngine_InvalidStateForRecomposition, SR.ImportEngine_InvalidStateForRecomposition, part.ToElement().DisplayName)); }
public static CompositionError CreatePartCannotSetImport(ComposablePart part, ImportDefinition definition, Exception innerException) { if (part == null) { throw new ArgumentNullException(nameof(part)); } if (definition == null) { throw new ArgumentNullException(nameof(definition)); } if (innerException == null) { throw new ArgumentNullException(nameof(innerException)); } ICompositionElement element = definition.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCannotSetImport, element, innerException, SR.ImportEngine_PartCannotSetImport, element.DisplayName, part.ToElement().DisplayName)); }
public static CompositionError PreventedByExistingImport(ComposablePart part, ImportDefinition import) { return(CompositionError.Create( CompositionErrorId.ImportEngine_PreventedByExistingImport, SR.ImportEngine_PreventedByExistingImport, import.ToElement().DisplayName, part.ToElement().DisplayName)); }
public void Constructor2_ArrayWithNullAsErrorsArgument_ShouldThrowArgument() { var errors = new CompositionError[] { null }; ExceptionAssert.ThrowsArgument <ArgumentException>("errors", () => { new CompositionException(errors); }); }
public void Constructor5_ArrayWithNullAsErrorsArgument_ShouldThrowArgument() { var errors = new CompositionError[] { null }; Assert.Throws <ArgumentException>("errors", () => { new CompositionException("Message", new Exception(), errors); }); }
private static void WriteError(StringBuilder writer, CompositionError error) { writer.AppendLine(error.Description); if (error.Element != null) { WriteElementGraph(writer, error.Element); } }
public static CompositionError CreateImportCardinalityMismatch(ImportCardinalityMismatchException exception, ImportDefinition definition) { Assumes.NotNull(exception, definition); return(CompositionError.Create( CompositionErrorId.ImportEngine_ImportCardinalityMismatch, exception.Message, definition.ToElement(), (Exception)null)); }
public void Constructor4_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); Assert.All(expectations, e => { var exception = new CompositionError(e, ElementFactory.Create(), new Exception()); Assert.Equal(e, exception.Description); }); }
public void Constructor5_ValueAsElementArgument_ShouldSetElementProperty() { var expectations = Expectations.GetCompositionElements(); Assert.All(expectations, e => { var exception = new CompositionError(CompositionErrorId.Unknown, "Description", (ICompositionElement)e, new Exception()); Assert.Same(e, exception.Element); }); }
public void Constructor5_ValueAsIdArgument_ShouldSetICompositionErrorIdProperty() { var expectations = Expectations.GetEnumValues <CompositionErrorId>(); Assert.All(expectations, e => { var error = new CompositionError(e, "Description", ElementFactory.Create(), new Exception()); Assert.Equal(e, error.Id); }); }
public void Constructor4_ValueAsExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); Assert.All(expectations, e => { var error = new CompositionError("Description", ElementFactory.Create(), e); Assert.Same(e, error.InnerException); }); }
public void Constructor3_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); foreach (var e in expectations) { var exception = new CompositionError(e, new Exception()); Assert.AreEqual(e, exception.Description); } }
public void Constructor4_ValueAsElementArgument_ShouldSetElementProperty() { var expectations = Expectations.GetCompositionElements(); foreach (var e in expectations) { var exception = new CompositionError("Description", (ICompositionElement)e, new Exception()); Assert.AreSame(e, exception.Element); } }
public void Constructor3_ValueAsExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var error = new CompositionError("Description", e); Assert.AreSame(e, error.InnerException); } }
public void Constructor5_ValueAsIdArgument_ShouldSetICompositionErrorIdProperty() { var expectations = Expectations.GetEnumValues <CompositionErrorId>(); foreach (var e in expectations) { var error = new CompositionError(e, "Description", ElementFactory.Create(), new Exception()); Assert.AreEqual(e, ((ICompositionError)error).Id); } }
public void Constructor5_ValueAsExceptionArgument_ShouldSetExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var error = new CompositionError(CompositionErrorId.Unknown, "Description", ElementFactory.Create(), e); Assert.AreSame(e, error.Exception); } }
private static CompositionError[] CreateCompositionErrors(int count) { CompositionError[] errors = new CompositionError[count]; for (int i = 0; i < count; i++) { errors[i] = CreateCompositionError("Description" + (i + 1)); } return(errors); }
public void Constructor2_ValueAsMessageArgument_ShouldSetMessageProperty() { var expectations = Expectations.GetExceptionMessages(); foreach (var e in expectations) { var exception = new CompositionError(e, ElementFactory.Create()); Assert.AreEqual(e, exception.Description); } }
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 static CompositionError CreatePartCycle(ComposablePart part) { Assumes.NotNull(part); ICompositionElement element = part.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCycle, element, SR.ImportEngine_PartCycle, element.DisplayName)); }
public static CompositionError CreatePartCannotActivate(ComposablePart part, Exception innerException) { Assumes.NotNull(part, innerException); ICompositionElement element = part.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCannotActivate, element, innerException, SR.ImportEngine_PartCannotActivate, element.DisplayName)); }
private string GetElementGraphString(CompositionError error) { StringBuilder writer = new StringBuilder(); ICompositionElement element = error.Element; writer.AppendFormat(CultureInfo.CurrentCulture, SR.CompositionException_ElementPrefix, element.DisplayName); while ((element = element.Origin) != null) { writer.AppendFormat(CultureInfo.CurrentCulture, SR.CompositionException_OriginFormat, SR.CompositionException_OriginSeparator, element.DisplayName); } return(writer.ToString()); }
public static CompositionError CreateCannotGetExportedValue(ComposablePart part, ExportDefinition definition, Exception innerException) { Assumes.NotNull(part, definition, innerException); ICompositionElement element = definition.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCannotGetExportedValue, element, innerException, SR.ImportEngine_PartCannotGetExportedValue, element.DisplayName, part.ToElement().DisplayName)); }
public static CompositionError CreatePartCycle(ComposablePart part) { if (part == null) { throw new ArgumentNullException(nameof(part)); } ICompositionElement element = part.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCycle, element, SR.ImportEngine_PartCycle, element.DisplayName)); }
private object GetInstance() { var result = CompositionResult.SucceededResult; // We only need this guard if we are pulling on the lazy exports during this call // but if we do the pulling in SetImport it isn't needed. //if (currentlyExecuting) //{ // var issue = CompositionError.Create("CM:CreationCycleDetected", // "This failed because there is a creation cycle"); // return result.MergeIssue(issue).ToResult<object>(null); //} try { currentlyExecuting = true; List <object> constructorArgs = new List <object>(); foreach (ImportDefinition import in this.ImportDefinitions .Where(i => i.IsPrerequisite)) { object importValue; if (!this._imports.TryGetValue(import, out importValue)) { result = result.MergeError(CompositionError.Create(CompositionErrorId.ImportNotSetOnPart, "The import '{0}' is required for construction of '{1}'", import.ToString(), _type.FullName)); continue; } constructorArgs.Add(importValue); } if (!result.Succeeded) { throw new CompositionException(result.Errors); } object obj = this._constructor.Invoke(constructorArgs.ToArray()); return(obj); } finally { currentlyExecuting = false; } }
public static CompositionError CreatePartCannotSetImport(ComposablePart part, ImportDefinition definition, Exception innerException) { ArgumentNullException.ThrowIfNull(part); ArgumentNullException.ThrowIfNull(definition); ArgumentNullException.ThrowIfNull(innerException); ICompositionElement element = definition.ToElement(); return(CompositionError.Create( CompositionErrorId.ImportEngine_PartCannotSetImport, element, innerException, SR.ImportEngine_PartCannotSetImport, element.DisplayName, part.ToElement().DisplayName)); }
private static void VisitError(CompositionError error, VisitContext context) { context.Path.Push(error); if (error.Exception == null) { // This error is a root cause, so write // out the stack from this point context.LeafVisitor(context.Path); } else { VisitException(error.Exception, context); } context.Path.Pop(); }
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); }
public static CompositionError CreateImportCardinalityMismatch(ImportCardinalityMismatchException exception, ImportDefinition definition) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } if (definition == null) { throw new ArgumentNullException(nameof(definition)); } return(CompositionError.Create( CompositionErrorId.ImportEngine_ImportCardinalityMismatch, exception.Message, definition.ToElement(), (Exception?)null)); }
public void Constructor4_ValueAsExceptionArgument_ShouldSetInnerExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var error = new CompositionError("Description", ElementFactory.Create(), e); Assert.AreSame(e, ((ICompositionError)error).InnerException); } }
public CompositionErrorDebuggerProxy(CompositionError error) { Requires.NotNull(error, "error"); this._error = error; }
public void Constructor4_NullAsExceptionArgument_ShouldSetExceptionPropertyToNull() { var error = new CompositionError("Description", ElementFactory.Create(), (Exception)null); Assert.IsNull(error.Exception); }
public void Constructor5_NullAsMessageArgument_ShouldSetMessagePropertyToEmptyString() { var error = new CompositionError(CompositionErrorId.Unknown, (string)null, ElementFactory.Create(), new Exception()); Assert.AreEqual("", error.Description); }
private static CompositionException CreateCompositionException(CompositionError error) { return new CompositionException(error); }
public void Constructor5_ValueAsElementArgument_ShouldSetElementProperty() { var expectations = Expectations.GetCompositionElements(); foreach (var e in expectations) { var exception = new CompositionError(CompositionErrorId.Unknown, "Description", (ICompositionElement)e, new Exception()); Assert.AreSame(e, exception.Element); } }
public void Constructor3_NullAsMessageArgument_ShouldSetMessagePropertyToEmptyString() { var error = new CompositionError((string)null, new Exception()); Assert.AreEqual("", error.Description); }
public void Constructor5_NullAsElementArgument_ShouldSetElementPropertyToNull() { var exception = new CompositionError(CompositionErrorId.Unknown, "Description", (ICompositionElement)null, new Exception()); Assert.IsNull(exception.Element); }
public void Constructor3_ShouldSetElementPropertyToNull() { var exception = new CompositionError("Description", new Exception()); Assert.IsNull(exception.Element); }
public void Constructor2_NullAsElementArgument_ShouldSetElementPropertyToNull() { var exception = new CompositionError("Description", (ICompositionElement)null); Assert.IsNull(exception.Element); }
private static CompositionError[] CreateCompositionErrors(int count) { CompositionError[] errors = new CompositionError[count]; for (int i = 0; i < count; i++) { errors[i] = CreateCompositionError("Description" + (i + 1)); } return errors; }
public void Constructor3_NullAsExceptionArgument_ShouldSetInnerExceptionPropertyToNull() { var error = new CompositionError("Description", (Exception)null); Assert.IsNull(((ICompositionError)error).InnerException); }
public void Constructor5_NullAsExceptionArgument_ShouldSetInnerExceptionPropertyToNull() { var error = new CompositionError(CompositionErrorId.Unknown, "Description", ElementFactory.Create(), (Exception)null); Assert.IsNull(((ICompositionError)error).InnerException); }
public void Constructor5_ArrayWithNullAsErrorsArgument_ShouldThrowArgument() { var errors = new CompositionError[] { null }; ExceptionAssert.ThrowsArgument<ArgumentException>("errors", () => { new CompositionException("Message", new Exception(), errors); }); }
public void Constructor1_ShouldSetICompositionErrorIdPropertyToCompositionErrorIdUnknown() { var error = new CompositionError("Description"); Assert.AreEqual(CompositionErrorId.Unknown, ((ICompositionError)error).Id); }
private string GetElementGraphString(CompositionError error) { StringBuilder writer = new StringBuilder(); ICompositionElement element = error.Element; writer.AppendFormat(CultureInfo.CurrentCulture, Strings.CompositionException_ElementPrefix, element.DisplayName); while ((element = element.Origin) != null) { writer.AppendFormat(CultureInfo.CurrentCulture, Strings.CompositionException_OriginFormat, Strings.CompositionException_OriginSeparator, element.DisplayName); } return writer.ToString(); }
public void Constructor4_ShouldSetICompositionErrorIdPropertyToCompositionErrorIdUnknown() { var error = new CompositionError("Description", ElementFactory.Create(), new Exception()); Assert.AreEqual(CompositionErrorId.Unknown, ((ICompositionError)error).Id); }
public void Constructor3_ValueAsExceptionArgument_ShouldSetExceptionProperty() { var expectations = Expectations.GetInnerExceptions(); foreach (var e in expectations) { var error = new CompositionError("Description", e); Assert.AreSame(e, error.Exception); } }
public void Constructor5_ValueAsIdArgument_ShouldSetICompositionErrorIdProperty() { var expectations = Expectations.GetEnumValues<CompositionErrorId>(); foreach (var e in expectations) { var error = new CompositionError(e, "Description", ElementFactory.Create(), new Exception()); Assert.AreEqual(e, ((ICompositionError)error).Id); } }
public void Constructor1_ShouldSetInnerExceptionPropertyToNull() { var error = new CompositionError("Description"); Assert.IsNull(((ICompositionError)error).InnerException); }
internal CompositionException(CompositionError error) : this(new CompositionError[] { error }) { }
public void Constructor2_ShouldSetInnerExceptionPropertyToNull() { var error = new CompositionError("Description", ElementFactory.Create()); Assert.IsNull(((ICompositionError)error).InnerException); }