-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameAssertErrorReporter.cs
More file actions
53 lines (48 loc) · 1.84 KB
/
GameAssertErrorReporter.cs
File metadata and controls
53 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Text;
using AET.ModVerify.Verifiers;
using PG.StarWarsGame.Engine.ErrorReporting;
using PG.StarWarsGame.Engine.IO;
namespace AET.ModVerify.Reporting.Engine;
internal sealed class GameAssertErrorReporter(IGameRepository gameRepository, IServiceProvider serviceProvider)
: EngineErrorReporterBase<EngineAssert>(gameRepository, serviceProvider)
{
public override string FriendlyName => "Game Engine Asserts";
protected override ErrorData CreateError(EngineAssert assert)
{
var context = new List<string>();
context.AddRange(assert.Context);
context.Add($"location='{GetLocation(assert)}'");
return new ErrorData(
GetIdFromError(assert.Kind),
assert.Message,
context,
assert.Value,
VerificationSeverity.Warning);
}
private static string GetLocation(EngineAssert assert)
{
var sb = new StringBuilder("method='");
if (assert.TypeName is not null)
{
sb.Append(assert.TypeName);
sb.Append("::");
}
sb.Append(assert.Method);
sb.Append('\'');
return sb.ToString();
}
private static string GetIdFromError(EngineAssertKind assertKind)
{
return assertKind switch
{
EngineAssertKind.NullOrEmptyValue => VerifierErrorCodes.AssertValueNullOrEmpty,
EngineAssertKind.ValueOutOfRange => VerifierErrorCodes.AssertValueOutOfRange,
EngineAssertKind.InvalidValue => VerifierErrorCodes.AssertValueInvalid,
EngineAssertKind.FileNotFound => VerifierErrorCodes.FileNotFound,
EngineAssertKind.DuplicateEntry => VerifierErrorCodes.DuplicateFound,
_ => throw new ArgumentOutOfRangeException(nameof(assertKind), assertKind, null)
};
}
}