diff --git a/src/Elmah.Io.HResults/Facility/Facilities.cs b/src/Elmah.Io.HResults/Facility/Facilities.cs index d8dec8f..d7d4043 100644 --- a/src/Elmah.Io.HResults/Facility/Facilities.cs +++ b/src/Elmah.Io.HResults/Facility/Facilities.cs @@ -6,7 +6,7 @@ internal class Facilities { private static readonly Dictionary facilities = new Dictionary { - { 19, new FacilityUrt() } + { 19, new FacilityUrt() }, { 7, new FacilityWin32() } }; internal static string? ErrorCodeToString(int facility, int errorCode) @@ -27,7 +27,6 @@ internal class Facilities case 2: return "FACILITY_DISPATCH"; case 3: return "FACILITY_STORAGE"; case 4: return "FACILITY_ITF"; - case 7: return "FACILITY_WIN32"; case 8: return "FACILITY_WINDOWS"; case 9: return "FACILITY_SECURITY"; case 10: return "FACILITY_CONTROL"; diff --git a/src/Elmah.Io.HResults/Facility/FacilityWin32.cs b/src/Elmah.Io.HResults/Facility/FacilityWin32.cs new file mode 100644 index 0000000..47d5e55 --- /dev/null +++ b/src/Elmah.Io.HResults/Facility/FacilityWin32.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Elmah.Io.HResults.Facility +{ + internal class FacilityWin32 : FacilityBase + { + public FacilityWin32() : base("FACILITY_WIN32") + { + } + + internal override string? ErrorCodeToString(int errorCode) + { + switch (errorCode) + { + case 2: return "ERROR_FILE_NOT_FOUND"; + } + + return $"{errorCode}"; + } + } +} \ No newline at end of file diff --git a/test/Elmah.Io.HResults.Test/HResultTest.cs b/test/Elmah.Io.HResults.Test/HResultTest.cs index 22be46d..d68077c 100644 --- a/test/Elmah.Io.HResults.Test/HResultTest.cs +++ b/test/Elmah.Io.HResults.Test/HResultTest.cs @@ -6,7 +6,7 @@ namespace Elmah.Io.HResults.Test public class HResultTest { [Test] - public void CanParseKnown() + public void CanParseKnownUrt() { var ex = new ApplicationException(); var res = HResult.Parse(ex.HResult); @@ -17,6 +17,17 @@ public void CanParseKnown() Assert.That(res.ErrorCode, Is.EqualTo("COR_E_APPLICATION")); } + [Test] + public void CanParseKnownWin32() + { + var res = HResult.Parse(-2147024894); + Assert.IsNotNull(res); + Assert.That(res.Hex, Is.EqualTo("0x80070002")); + Assert.That(res.IsFailure, Is.True); + Assert.That(res.Facility, Is.EqualTo("FACILITY_WIN32")); + Assert.That(res.ErrorCode, Is.EqualTo("ERROR_FILE_NOT_FOUND")); + } + [Test] public void CanParseUnknown() {