Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<List<Alert>> HandleAsync(CancellationToken cancellationToken)
{
var alerts = new List<Alert>();

foreach (var dbAlert in await _processorContext.Alerts.ToListAsync())
foreach (var dbAlert in await _processorContext.Alerts.ToListAsync(cancellationToken))
{
var alert = new Alert()
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/AgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task AgentRequestSucceeds()
{
using (var processorContext = _contextCreator.CreateContext())
{
if (processorContext.Database.EnsureCreated())
if (await processorContext.Database.EnsureCreatedAsync())
{
processorContext.Agents.Add(new OpenAlprWebhookProcessor.Data.Agent()
{
Expand Down
58 changes: 58 additions & 0 deletions Tests/Alerts/GetAlerts/GetAlerts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using OpenAlprWebhookProcessor.Alerts;
using OpenAlprWebhookProcessor.Data;
using System.Data.Common;

namespace Tests.Alerts.GetAlerts
{
public class GetAlertsTests
{
private ProcessorContext _context;
private DbContextOptions<ProcessorContext> _dbContextOptions;
private DbConnection _connection;

[SetUp]
public async Task SetupAsync()
{
_connection = new SqliteConnection("Filename=:memory:");
await _connection.OpenAsync();

_dbContextOptions = new DbContextOptionsBuilder<ProcessorContext>()
.UseSqlite(_connection)
.Options;

_context = new ProcessorContext(_dbContextOptions);
await _context.Database.EnsureCreatedAsync();

_context.Alerts.AddRange(
new OpenAlprWebhookProcessor.Data.Alert { Id = Guid.NewGuid(), PlateNumber = "ABC123", IsStrictMatch = true, Description = "Stolen vehicle" },
new OpenAlprWebhookProcessor.Data.Alert { Id = Guid.NewGuid(), PlateNumber = "XYZ789", IsStrictMatch = false, Description = "Suspicious activity" }
);
await _context.SaveChangesAsync();
}

[TearDown]
public void TearDown()
{
_context?.Dispose();
_connection?.Close();
_connection?.Dispose();
}

[Test]
public async Task HandleAsync_ReturnsAllAlerts()
{
// Arrange
var handler = new GetAlertsRequestHandler(_context);
var cancellationToken = CancellationToken.None;

// Act
var result = await handler.HandleAsync(cancellationToken);

// Assert
Assert.That(result, Is.Not.Null);
Assert.That(result, Has.Count.EqualTo(2));
}
}
}
Loading