public static void Ctor_String() { string message = "This path is too long to hike in a single day."; var exception = new PathTooLongException(message); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_PATHTOOLONG, message: message); }
protected override void LogPathToLoog(string fullName, PathTooLongException ex) { this.xmlWriter.WriteStartElement("pathTooLong"); this.xmlWriter.WriteAttributeString("path", fullName); this.xmlWriter.WriteAttributeString("message", ex.Message); this.xmlWriter.WriteEndElement(); }
public static void PathTooLongException_ctor_string() { string message = "This path is too long to hike in a single day."; PathTooLongException plte = new PathTooLongException(message); Utility.ValidateExceptionProperties(plte, hResult: HResults.COR_E_PATHTOOLONG, message: message); }
public void Path_NormalizePathNormal() { PathTooLongException ptl = null; try { Assert.That(Path.GetFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.Not.Null); } catch (PathTooLongException e) { ptl = e; } if (IsCore()) { Assert.That(ptl, Is.Null, "Expected no error on Core"); } else if (Environment.Version.Major < 4) { Assert.That(ptl, Is.Not.Null, "Expected error in v2.0"); } else { // In .Net 4.x this is configurable on system and app level } }
public bool PosTest3() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest3: Create a new PathTooLongException instance,string is null."); try { string expectString = null; PathTooLongException myException = new PathTooLongException(expectString); if (myException == null) { TestLibrary.TestFramework.LogError("003.1", "the PathTooLongException ctor error occurred. "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("003.2", "Unexpected exception: " + e); retVal = false; } return retVal; }
public static void From_HR() { int hr = HResults.COR_E_PATHTOOLONG; PathTooLongException exception = Assert.IsAssignableFrom <PathTooLongException>(Marshal.GetExceptionForHR(hr, new IntPtr(-1))); ExceptionHelpers.ValidateExceptionProperties(exception, hResult: hr, validateMessage: false); }
public static void PathTooLongException_ctor_string_exception() { string message = "This path is too long to hike in a single day."; Exception innerException = new Exception("Inner exception"); PathTooLongException plte = new PathTooLongException(message, innerException); Utility.ValidateExceptionProperties(plte, hResult: HResults.COR_E_PATHTOOLONG, innerException: innerException, message: message); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Create a new PathTooLongException instance,string is empty."); try { string expectString = string.Empty; PathTooLongException myException = new PathTooLongException(expectString); if (myException.Message != expectString) { TestLibrary.TestFramework.LogError("002.1", "the PathTooLongException ctor error occurred. "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e); retVal = false; } return retVal; }
public static void Ctor_String_Exception() { string message = "This path is too long to hike in a single day."; var innerException = new Exception("Inner exception"); var exception = new PathTooLongException(message, innerException); ExceptionHelpers.ValidateExceptionProperties(exception, hResult: HResults.COR_E_PATHTOOLONG, innerException: innerException, message: message); }
public static void TestFrom_HR() { int hr = HResults.COR_E_PATHTOOLONG; PathTooLongException exception = Marshal.GetExceptionForHR(hr) as PathTooLongException; Assert.NotNull(exception); ExceptionUtility.ValidateExceptionProperties(exception, hResult: hr, validateMessage: false); }
internal static FailedHttpException Create(HttpResponseMessage response, string message) { if (response == null || response.IsSuccessStatusCode) { return(null); } Exception innerEx = null; var msg = $"Failed HTTP request with status code {(int)response.StatusCode} {response.ReasonPhrase}."; switch (response.StatusCode) { case HttpStatusCode.Unauthorized: case HttpStatusCode.ProxyAuthenticationRequired: case HttpStatusCode.Forbidden: innerEx = new UnauthorizedAccessException(msg); break; case HttpStatusCode.NotAcceptable: case HttpStatusCode.MethodNotAllowed: case HttpStatusCode.UnsupportedMediaType: case HttpStatusCode.SwitchingProtocols: case HttpStatusCode.UpgradeRequired: case HttpStatusCode.HttpVersionNotSupported: innerEx = new NotSupportedException(msg); break; case HttpStatusCode.RequestTimeout: innerEx = new TimeoutException("Request is timeout."); break; case HttpStatusCode.GatewayTimeout: innerEx = new TimeoutException("Gateway is timeout."); break; case HttpStatusCode.NotImplemented: innerEx = new NotImplementedException(msg); break; case HttpStatusCode.RequestUriTooLong: innerEx = new PathTooLongException("Request URI is too long."); break; case HttpStatusCode.BadRequest: innerEx = new InvalidOperationException(msg); break; } var reqEx = $"Response status code does not indicate success: {(int)response.StatusCode} ({response.ReasonPhrase})."; var ex = innerEx != null ? new HttpRequestException(reqEx, innerEx) : new HttpRequestException(reqEx); return(new FailedHttpException(response, message, ex)); }
public void ExceptionTests() { using (new InternalLoggerScope()) { InternalLogger.LogLevel = LogLevel.Trace; InternalLogger.LogToConsole = true; InternalLogger.IncludeTimestamp = false; var ex1 = new Exception("e1"); var ex2 = new Exception("e2", new Exception("inner")); var ex3 = new NLogConfigurationException("config error"); var ex4 = new NLogConfigurationException("config error", ex2); var ex5 = new PathTooLongException(); ex5.Data["key1"] = "value1"; Exception ex6 = null; const string prefix = " Exception: "; string expected = "Warn WWW" + prefix + ex1 + Environment.NewLine + "Error EEE" + prefix + ex2 + Environment.NewLine + "Fatal FFF" + prefix + ex3 + Environment.NewLine + "Trace TTT" + prefix + ex4 + Environment.NewLine + "Debug DDD" + prefix + ex5 + Environment.NewLine + "Info III" + Environment.NewLine; StringWriter consoleOutWriter = new StringWriter() { NewLine = Environment.NewLine }; // Redirect the console output to a StringWriter. Console.SetOut(consoleOutWriter); // Named (based on LogLevel) public methods. InternalLogger.Warn(ex1, "WWW"); InternalLogger.Error(ex2, "EEE"); InternalLogger.Fatal(ex3, "FFF"); InternalLogger.Trace(ex4, "TTT"); InternalLogger.Debug(ex5, "DDD"); InternalLogger.Info(ex6, "III"); consoleOutWriter.Flush(); var strings = consoleOutWriter.ToString(); Assert.Equal(expected, strings); } }
public bool PosTest1() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest1: Create a new PathTooLongException instance."); try { PathTooLongException myException = new PathTooLongException(); if (myException == null) { TestLibrary.TestFramework.LogError("001.1", "the PathTooLongException ctor error occurred. "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e); retVal = false; } return(retVal); }
internal static Exception GetWindowsErrorException(int errorCode, string parameterName) { string message = new Win32Exception(errorCode).Message; Exception retval; if (ERROR_FILE_NOT_FOUND == errorCode) { retval = new FileNotFoundException(message); } else if (ERROR_INVALID_DRIVE == errorCode) { retval = new DriveNotFoundException(message); } else if (ERROR_ACCESS_DENIED == errorCode) { retval = new UnauthorizedAccessException(message); } else if (ERROR_PATH_NOT_FOUND == errorCode) { retval = new DirectoryNotFoundException(message); } else if (ERROR_FILE_NAME_TOO_LONG == errorCode) { retval = new PathTooLongException(message); } else if (ERROR_INVALID_NAME == errorCode) { retval = new ArgumentException(message, parameterName); } else { retval = new IOException(message, ErrorCodeToHResult(errorCode)); } return(retval); }
public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: Create a new PathTooLongException instance,string is empty."); try { string expectString = string.Empty; PathTooLongException myException = new PathTooLongException(expectString); if (myException.Message != expectString) { TestLibrary.TestFramework.LogError("002.1", "the PathTooLongException ctor error occurred. "); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e); retVal = false; } return(retVal); }
public void Path_NormalizePathNormal() { PathTooLongException ptl = null; try { Assert.That(Path.GetFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.Not.Null); } catch (PathTooLongException e) { ptl = e; } if (Environment.Version.Major < 4) { Assert.That(ptl, Is.Not.Null, "Expected error in v2.0"); } }
public static void PathTooLongException_ctor() { PathTooLongException plte = new PathTooLongException(); Utility.ValidateExceptionProperties(plte, hResult: HResults.COR_E_PATHTOOLONG, validateMessage: false); }
public static void Handle(PathTooLongException exception) { ConsoleLogExceptionMessage(exception); }
public void TooLongPathNamesThrowException(string filePath, List <string> lines) { PathTooLongException ex = Assert.Throws <PathTooLongException>(() => _textDataAccess.SaveText(filePath, lines)); Assert.Equal("The path needs to be less than 261 characters long.", ex.Message); }
protected abstract void LogPathToLoog(string fullName, PathTooLongException ex);
protected override void LogPathToLoog(string fullName, PathTooLongException ex) { this.currentParent.Add(new XElement( "pathTooLong" , new XAttribute("message", ex.Message))); }
public void ExceptionTests() { using (new InternalLoggerScope()) { InternalLogger.LogLevel = LogLevel.Trace; InternalLogger.IncludeTimestamp = false; var ex1 = new Exception("e1"); var ex2 = new Exception("e2", new Exception("inner")); var ex3 = new NLogConfigurationException("config error"); var ex4 = new NLogConfigurationException("config error", ex2); var ex5 = new PathTooLongException(); ex5.Data["key1"] = "value1"; Exception ex6 = null; const string prefix = " Exception: "; { string expected = "Warn WWW1" + prefix + ex1 + Environment.NewLine + "Error EEE1" + prefix + ex2 + Environment.NewLine + "Fatal FFF1" + prefix + ex3 + Environment.NewLine + "Trace TTT1" + prefix + ex4 + Environment.NewLine + "Debug DDD1" + prefix + ex5 + Environment.NewLine + "Info III1" + Environment.NewLine; StringWriter consoleOutWriter = new StringWriter() { NewLine = Environment.NewLine }; // Redirect the console output to a StringWriter. InternalLogger.LogWriter = consoleOutWriter; // Named (based on LogLevel) public methods. InternalLogger.Warn(ex1, "WWW1"); InternalLogger.Error(ex2, "EEE1"); InternalLogger.Fatal(ex3, "FFF1"); InternalLogger.Trace(ex4, "TTT1"); InternalLogger.Debug(ex5, "DDD1"); InternalLogger.Info(ex6, "III1"); consoleOutWriter.Flush(); var strings = consoleOutWriter.ToString(); Assert.Equal(expected, strings); } { string expected = "Warn WWW2" + prefix + ex1 + Environment.NewLine + "Error EEE2" + prefix + ex2 + Environment.NewLine + "Fatal FFF2" + prefix + ex3 + Environment.NewLine + "Trace TTT2" + prefix + ex4 + Environment.NewLine + "Debug DDD2" + prefix + ex5 + Environment.NewLine + "Info III2" + Environment.NewLine; StringWriter consoleOutWriter = new StringWriter() { NewLine = Environment.NewLine }; // Redirect the console output to a StringWriter. InternalLogger.LogWriter = consoleOutWriter; // Named (based on LogLevel) public methods. InternalLogger.Warn(ex1, () => "WWW2"); InternalLogger.Error(ex2, () => "EEE2"); InternalLogger.Fatal(ex3, () => "FFF2"); InternalLogger.Trace(ex4, () => "TTT2"); InternalLogger.Debug(ex5, () => "DDD2"); InternalLogger.Info(ex6, () => "III2"); consoleOutWriter.Flush(); var strings = consoleOutWriter.ToString(); Assert.Equal(expected, strings); } { string expected = "Warn WWW3" + prefix + ex1 + Environment.NewLine + "Error EEE3" + prefix + ex2 + Environment.NewLine + "Fatal FFF3" + prefix + ex3 + Environment.NewLine + "Trace TTT3" + prefix + ex4 + Environment.NewLine + "Debug DDD3" + prefix + ex5 + Environment.NewLine + "Info III3" + Environment.NewLine; StringWriter consoleOutWriter = new StringWriter() { NewLine = Environment.NewLine }; // Redirect the console output to a StringWriter. InternalLogger.LogWriter = consoleOutWriter; // Named (based on LogLevel) public methods. InternalLogger.Log(ex1, LogLevel.Warn, "WWW3"); InternalLogger.Log(ex2, LogLevel.Error, "EEE3"); InternalLogger.Log(ex3, LogLevel.Fatal, "FFF3"); InternalLogger.Log(ex4, LogLevel.Trace, "TTT3"); InternalLogger.Log(ex5, LogLevel.Debug, "DDD3"); InternalLogger.Log(ex6, LogLevel.Info, "III3"); consoleOutWriter.Flush(); var strings = consoleOutWriter.ToString(); Assert.Equal(expected, strings); } { string expected = "Warn WWW4" + prefix + ex1 + Environment.NewLine + "Error EEE4" + prefix + ex2 + Environment.NewLine + "Fatal FFF4" + prefix + ex3 + Environment.NewLine + "Trace TTT4" + prefix + ex4 + Environment.NewLine + "Debug DDD4" + prefix + ex5 + Environment.NewLine + "Info III4" + Environment.NewLine; StringWriter consoleOutWriter = new StringWriter() { NewLine = Environment.NewLine }; // Redirect the console output to a StringWriter. InternalLogger.LogWriter = consoleOutWriter; // Named (based on LogLevel) public methods. InternalLogger.Log(ex1, LogLevel.Warn, () => "WWW4"); InternalLogger.Log(ex2, LogLevel.Error, () => "EEE4"); InternalLogger.Log(ex3, LogLevel.Fatal, () => "FFF4"); InternalLogger.Log(ex4, LogLevel.Trace, () => "TTT4"); InternalLogger.Log(ex5, LogLevel.Debug, () => "DDD4"); InternalLogger.Log(ex6, LogLevel.Info, () => "III4"); var strings = consoleOutWriter.ToString(); Assert.Equal(expected, strings); } } }
public static void Ctor_Empty() { var exception = new PathTooLongException(); ExceptionUtility.ValidateExceptionProperties(exception, hResult: HResults.COR_E_PATHTOOLONG, validateMessage: false); }