using System; namespace HanvonF710XAttendanceService { internal static class HrmsEmployeeMappingTests { public static int RunAll() { int failed = 0; failed += Run("photo URL uses employees.id not device serial", TestPhotoUrlUsesEmployeeId); failed += Run("display name prefers concatenated_name", TestDisplayNamePrefersConcatenatedName); failed += Run("display name falls back to device serial", TestDisplayNameFallback); return failed; } private static int Run(string name, Func 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 TestPhotoUrlUsesEmployeeId() { // Device serial=15057 maps to employees.id=84321 for photo URL only. string url = HrmsEmployeePhotoClient.BuildPhotoUrl( "https://portal.utopiaindustries.pk/uind/employee-photo/", "84321"); return string.Equals( url, "https://portal.utopiaindustries.pk/uind/employee-photo/84321.jpeg", StringComparison.OrdinalIgnoreCase); } private static bool TestDisplayNamePrefersConcatenatedName() { var info = new HrmsEmployeeInfo("84321", "15057", "John Smith"); return info.EmployeeId == "84321" && info.SerialNumberInt == "15057" && info.ConcatenatedName == "John Smith" && info.EmployeeId != info.SerialNumberInt; } private static bool TestDisplayNameFallback() { var info = new HrmsEmployeeInfo("84321", "15057", ""); string name = !string.IsNullOrWhiteSpace(info.ConcatenatedName) ? info.ConcatenatedName : "15057"; return name == "15057"; } } }