public void CanWrapException() { ReplaceHandler handler = new ReplaceHandler(message, typeof(ApplicationException)); Exception ex = handler.HandleException(new InvalidOperationException(), Guid.NewGuid()); Assert.AreEqual(typeof(ApplicationException), ex.GetType()); Assert.AreEqual(typeof(ApplicationException), handler.ReplaceExceptionType); Assert.AreEqual(message, ex.Message); Assert.IsNull(ex.InnerException); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="ReplaceHandler"/> based on an instance of <see cref="ReplaceHandlerData"/>. /// </summary> /// <seealso cref="ExceptionHandlerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="ReplaceHandlerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="ReplaceHandler"/>.</returns> public IExceptionHandler Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { ReplaceHandlerData castedObjectConfiguration = (ReplaceHandlerData)objectConfiguration; ReplaceHandler createdObject = new ReplaceHandler(castedObjectConfiguration.ExceptionMessage, castedObjectConfiguration.ReplaceExceptionType); return(createdObject); }
public void CreatesReplaceExceptionHandlerWithMessageForThrowNewExceptionPostHandlingAction() { var excepionPolicies = new List <ExceptionPolicyDefinition>(); var excepionPolicyEntries = new List <ExceptionPolicyEntry>(); var exceptionHandler = new ReplaceHandler("string", typeof(InvalidCastException)); var exceptionPolicy = new ExceptionPolicyEntry(typeof(Exception), PostHandlingAction.ThrowNewException, new IExceptionHandler[] { exceptionHandler }); excepionPolicyEntries.Add(exceptionPolicy); excepionPolicies.Add(new ExceptionPolicyDefinition("EH", excepionPolicyEntries)); var exceptionManager = new ExceptionManager(excepionPolicies); ExceptionAssertHelper.Throws <InvalidCastException>(() => exceptionManager.HandleException(new Exception(), "EH")); Exception exception = null; bool rethrow = exceptionManager.HandleException(new Exception(), "EH", out exception); Assert.IsInstanceOfType(exception, typeof(InvalidCastException)); Assert.AreEqual("string", exception.Message); Assert.IsNull(exception.InnerException); Assert.IsTrue(rethrow); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="ReplaceHandler"/> based on an instance of <see cref="ReplaceHandlerData"/>. /// </summary> /// <seealso cref="ExceptionHandlerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="ReplaceHandlerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="ReplaceHandler"/>.</returns> public IExceptionHandler Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { ReplaceHandlerData castedObjectConfiguration = (ReplaceHandlerData)objectConfiguration; string exceptionMessage = castedObjectConfiguration.ExceptionMessage; if (!string.IsNullOrEmpty(castedObjectConfiguration.ExceptionMessageResourceName)) { Type exceptionMessageResourceType = Type.GetType(castedObjectConfiguration.ExceptionMessageResourceType, false); if (null != exceptionMessageResourceType) { exceptionMessage = ResourceStringLoader.LoadString(exceptionMessageResourceType.FullName, castedObjectConfiguration.ExceptionMessageResourceName, exceptionMessageResourceType.Assembly); } } ReplaceHandler createdObject = new ReplaceHandler(exceptionMessage, castedObjectConfiguration.ReplaceExceptionType); return(createdObject); }
public void ConstructingWithNullExceptionTypeThrows() { ReplaceHandler handler = new ReplaceHandler(message, null); }
public void HandlerThrowsWhenNotReplaceingAnException() { ReplaceHandler handler = new ReplaceHandler(message, typeof(object)); handler.HandleException(new ApplicationException(), Guid.NewGuid()); }