Skip to content

Commit 98109a4

Browse files
committed
RE1-T115 PR#362 fixes
1 parent 677aed8 commit 98109a4

9 files changed

Lines changed: 1058 additions & 732 deletions

File tree

Core/Resgrid.Services/WeatherAlertService.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class WeatherAlertService : IWeatherAlertService
2121
private readonly IWeatherAlertProviderFactory _weatherAlertProviderFactory;
2222
private readonly IDepartmentSettingsRepository _departmentSettingsRepository;
2323
private readonly IDepartmentsService _departmentsService;
24-
private readonly IMessageService _messageService;
24+
private readonly ICommunicationService _communicationService;
2525
private readonly ICallNotesRepository _callNotesRepository;
2626
private readonly ICacheProvider _cacheProvider;
2727
private readonly IEventAggregator _eventAggregator;
@@ -33,7 +33,7 @@ public WeatherAlertService(
3333
IWeatherAlertProviderFactory weatherAlertProviderFactory,
3434
IDepartmentSettingsRepository departmentSettingsRepository,
3535
IDepartmentsService departmentsService,
36-
IMessageService messageService,
36+
ICommunicationService communicationService,
3737
ICallNotesRepository callNotesRepository,
3838
ICacheProvider cacheProvider,
3939
IEventAggregator eventAggregator)
@@ -44,7 +44,7 @@ public WeatherAlertService(
4444
_weatherAlertProviderFactory = weatherAlertProviderFactory;
4545
_departmentSettingsRepository = departmentSettingsRepository;
4646
_departmentsService = departmentsService;
47-
_messageService = messageService;
47+
_communicationService = communicationService;
4848
_callNotesRepository = callNotesRepository;
4949
_cacheProvider = cacheProvider;
5050
_eventAggregator = eventAggregator;
@@ -381,33 +381,31 @@ public async Task SendPendingNotificationsAsync(CancellationToken ct = default)
381381
var members = await _departmentsService.GetAllMembersForDepartmentAsync(departmentId);
382382
if (members != null && members.Any())
383383
{
384-
// Use department managing user as sender for system messages
384+
// Use department managing user as sender for notifications
385385
var senderId = department?.ManagingUserId ?? members.First().UserId;
386386

387387
var subject = FormatAlertSubject(alert);
388388
var body = FormatAlertMessageBody(alert, department);
389389

390-
var message = new Message
391-
{
392-
Subject = subject,
393-
Body = body,
394-
SendingUserId = senderId,
395-
SentOn = DateTime.UtcNow,
396-
SystemGenerated = true,
397-
IsBroadcast = true,
398-
Type = 0
399-
};
400-
401390
foreach (var member in members)
402391
{
403-
if (member.UserId != senderId && !member.IsDisabled.GetValueOrDefault() && !member.IsDeleted)
404-
message.AddRecipient(member.UserId);
392+
if (member.UserId == senderId || member.IsDisabled.GetValueOrDefault() || member.IsDeleted)
393+
continue;
394+
395+
var notifyMsg = new Message
396+
{
397+
Subject = subject,
398+
Body = body,
399+
SendingUserId = senderId,
400+
ReceivingUserId = member.UserId,
401+
SentOn = DateTime.UtcNow,
402+
SystemGenerated = true,
403+
IsBroadcast = true,
404+
Type = 0
405+
};
406+
407+
await _communicationService.SendMessageAsync(notifyMsg, "Weather Alert System", null, departmentId, null, department);
405408
}
406-
407-
var savedMessage = await _messageService.SaveMessageAsync(message, ct);
408-
await _messageService.SendMessageAsync(savedMessage, "Weather Alert System", departmentId, false, ct);
409-
410-
alert.SystemMessageId = savedMessage.MessageId;
411409
}
412410
}
413411
catch (Exception ex)

Tests/Resgrid.Tests/Models/TimeZoneTests.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using FluentAssertions;
34
using NUnit.Framework;
45
using Resgrid.Model;
@@ -11,6 +12,8 @@ public class TimeZoneTests
1112
[Test]
1213
public void TestAllTimeZones()
1314
{
15+
var unresolvedZones = new List<string>();
16+
1417
foreach (var timeZone in TimeZones.Zones)
1518
{
1619
try
@@ -20,11 +23,37 @@ public void TestAllTimeZones()
2023
}
2124
catch (TimeZoneNotFoundException)
2225
{
23-
// Windows timezone IDs are not available on non-Windows platforms (Linux/macOS use IANA IDs).
24-
// Skip entries that are not found on the current OS rather than failing the test.
25-
Assert.Ignore($"Timezone '{timeZone.Key}' is not available on this platform; skipping.");
26+
// On non-Windows platforms, Windows timezone IDs are not available.
27+
// Try converting to IANA ID first, then attempt lookup.
28+
if (TimeZoneInfo.TryConvertWindowsIdToIanaId(timeZone.Key, out string ianaId))
29+
{
30+
try
31+
{
32+
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(ianaId);
33+
timeZoneInfo.Should().NotBeNull();
34+
continue;
35+
}
36+
catch (TimeZoneNotFoundException)
37+
{
38+
// IANA ID also not found on this platform
39+
}
40+
}
41+
42+
unresolvedZones.Add(timeZone.Key);
2643
}
2744
}
45+
46+
// Report any unresolvable zones but don't fail the test;
47+
// some Windows-specific timezone IDs don't exist on all platforms.
48+
if (unresolvedZones.Count > 0)
49+
{
50+
TestContext.WriteLine(
51+
$"The following {unresolvedZones.Count} timezone(s) could not be resolved on this platform: " +
52+
string.Join(", ", unresolvedZones));
53+
}
54+
55+
// The test passes as long as it didn't crash; unresolvable zones
56+
// are expected on non-Windows platforms for Windows-only IDs.
2857
}
2958
}
3059
}

0 commit comments

Comments
 (0)