-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGetActiveAnnouncementsCommandHandlerTests.cs
More file actions
43 lines (37 loc) · 1.44 KB
/
GetActiveAnnouncementsCommandHandlerTests.cs
File metadata and controls
43 lines (37 loc) · 1.44 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
using ByteSync.Common.Business.Announcements;
using ByteSync.ServerCommon.Commands.Announcements;
using ByteSync.ServerCommon.Interfaces.Repositories;
using FakeItEasy;
using FluentAssertions;
namespace ByteSync.ServerCommon.Tests.Commands.Announcements;
[TestFixture]
public class GetActiveAnnouncementsCommandHandlerTests
{
private IAnnouncementRepository _repository = null!;
private GetActiveAnnouncementsCommandHandler _handler = null!;
[SetUp]
public void Setup()
{
_repository = A.Fake<IAnnouncementRepository>();
_handler = new GetActiveAnnouncementsCommandHandler(_repository);
}
[Test]
public async Task Handle_ReturnsOnlyActiveAnnouncements()
{
// Arrange
var now = DateTime.UtcNow;
var announcements = new List<Announcement>
{
new() { Id = "1", StartDate = now.AddHours(-1), EndDate = now.AddHours(1) },
new() { Id = "2", StartDate = now.AddHours(-2), EndDate = now.AddHours(-1) },
new() { Id = "3", StartDate = now.AddHours(1), EndDate = now.AddHours(2) }
};
A.CallTo(() => _repository.GetAll()).Returns(announcements);
// Act
var result = await _handler.Handle(new GetActiveAnnouncementsRequest(), CancellationToken.None);
// Assert
result.Should().HaveCount(1);
result[0].Id.Should().Be("1");
A.CallTo(() => _repository.GetAll()).MustHaveHappenedOnceExactly();
}
}