49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace HanvonF710XAttendanceService
|
|
{
|
|
internal static class DbToDeviceFaceErrorsTests
|
|
{
|
|
public static int RunAll()
|
|
{
|
|
int failed = 0;
|
|
failed += Run("parse duplicate face error", TestParseDuplicateFace);
|
|
failed += Run("ignore generic upload error", TestIgnoreGenericError);
|
|
return failed;
|
|
}
|
|
|
|
private static int Run(string name, Func<bool> test)
|
|
{
|
|
try
|
|
{
|
|
if (!test())
|
|
{
|
|
Console.WriteLine("FAIL: " + name);
|
|
return 1;
|
|
}
|
|
|
|
Console.WriteLine("PASS: " + name);
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("FAIL: " + name + " err=" + ex.Message);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private static bool TestParseDuplicateFace()
|
|
{
|
|
return DbToDeviceFaceErrors.TryParseDuplicateFace("face is double,id=6400", out string existingId)
|
|
&& existingId == "6400"
|
|
&& DbToDeviceFaceErrors.TryParseDuplicateFace("Face is double, id=6475", out string existingId2)
|
|
&& existingId2 == "6475";
|
|
}
|
|
|
|
private static bool TestIgnoreGenericError()
|
|
{
|
|
return !DbToDeviceFaceErrors.TryParseDuplicateFace("no face in picture", out _);
|
|
}
|
|
}
|
|
}
|