public void FullNewSetsAllProperties() { Exception error = new Exception(); CommunicationsException exception = new CommunicationsException("Message", error); Assert.AreEqual("Message", exception.Message); Assert.AreEqual(error, exception.InnerException); }
/// <summary> /// Extension method that generates problem details for the exception. /// </summary> /// <param name="source">The exception to map to a <see cref="ProblemDetails"/></param> /// <param name="controller">The base controller the exception occured in. </param> /// <param name="type">Optional parameter that sets the URL for the human readable explanation for the status code. Default value is set to https://httpstatuses.com/403 </param> /// <param name="status">Optional parameter that sets the return status code for the problem. Default value is set to 403.</param> /// <param name="title">Optional parameter that sets the title for the problem. Default value is set to Forbidden.</param> /// <returns>Instance of the problem details.</returns> public static ProblemDetails GetProblemDetails(this CommunicationsException source, ControllerBase controller, string type = "https://httpstatuses.com/504", int?status = 504, string title = "Gateway Timeout") { return(new ProblemDetails { Type = type, Status = status, Title = title, Instance = controller?.HttpContext?.Request?.Path, Detail = source?.Message }); }
public void ConstructorSetsType() { var message = "Test Message"; var exception = new Exception(); var type = "Some type"; var error = new CommunicationsException(message, exception, type); Assert.AreEqual(message, error.Message); Assert.AreSame(exception, error.InnerException); Assert.AreEqual(type, error.ErrorType); }
public void ExceptionCanBeSerialised() { var message = "Test Message"; var exception = new Exception("Inner message"); var type = "Some type"; var original = new CommunicationsException(message, exception, type); var formatter = new BinaryFormatter(); var stream = new MemoryStream(); formatter.Serialize(stream, original); stream.Position = 0; var error = formatter.Deserialize(stream); Assert.IsInstanceOf <CommunicationsException>(error); var deserialised = error as CommunicationsException; Assert.AreEqual(message, deserialised.Message); Assert.IsNotNull(deserialised.InnerException); Assert.AreEqual(exception.Message, deserialised.InnerException.Message); Assert.AreEqual(type, deserialised.ErrorType); }
public void NewWithMessageSetsMessage() { CommunicationsException exception = new CommunicationsException("Message"); Assert.AreEqual("Message", exception.Message); }
public void NewWithNoParametersSetsDefaultMessage() { CommunicationsException exception = new CommunicationsException(); Assert.AreEqual("A communications error has occurred.", exception.Message); }