Skip to content

Commit

Permalink
FACILITY_WIN32
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Nov 14, 2023
1 parent f1e5c8c commit 0885fe7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Elmah.Io.HResults/Facility/Facilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class Facilities
{
private static readonly Dictionary<int, FacilityBase> facilities = new Dictionary<int, FacilityBase>
{
{ 19, new FacilityUrt() }
{ 19, new FacilityUrt() }, { 7, new FacilityWin32() }
};

internal static string? ErrorCodeToString(int facility, int errorCode)
Expand All @@ -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";
Expand Down
23 changes: 23 additions & 0 deletions src/Elmah.Io.HResults/Facility/FacilityWin32.cs
Original file line number Diff line number Diff line change
@@ -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}";
}
}
}
13 changes: 12 additions & 1 deletion test/Elmah.Io.HResults.Test/HResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
{
Expand Down

0 comments on commit 0885fe7

Please sign in to comment.