-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeactivateNotificationTests.cs
More file actions
97 lines (78 loc) · 2.81 KB
/
Copy pathDeactivateNotificationTests.cs
File metadata and controls
97 lines (78 loc) · 2.81 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;
using Notifications.Database;
using Notifications.Models;
namespace Notifications.API.Tests;
[TestFixture]
public class DeactivateNotificationTests
{
private AppDbContext _dbContext;
[SetUp]
public async Task Setup()
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(databaseName: "RepositoryTest")
.UseAsyncSeeding((context, _, _) => TestData.SeedDataAsync(context))
.Options;
_dbContext = new AppDbContext(options);
await _dbContext.Database.EnsureCreatedAsync();
}
[TearDown]
public async Task TearDown()
{
await _dbContext.Database.EnsureDeletedAsync();
await _dbContext.DisposeAsync();
}
[Test]
public async Task HappyPath_ReturnsSuccess()
{
// Arrange
var create = new CreateNotificationDto
{
Message = "Test message",
DisplayStart = DateTime.Now.AddDays(-1),
DisplayEnd = DateTime.Now.AddDays(1),
};
var newNotification = (await Repository.AddNotification(create, _dbContext) as Ok<Notification>)!.Value;
var request = new DeactivateNotificationDto { Id = newNotification!.Id };
// Act
var result = await Repository.DeactivateNotification(request, _dbContext);
// Assert
using var scope = new AssertionScope();
result.Should().BeOfType<Ok<Notification>>();
var notification = ((Ok<Notification>)result).Value;
notification.Should().BeOfType<Notification>();
notification.Should().NotBeNull();
notification.Should().Be(newNotification with { Active = false });
}
[Test]
public async Task MissingId_ReturnsNotFound()
{
// Arrange
var request = new DeactivateNotificationDto { Id = Guid.NewGuid() };
// Act
var result = await Repository.DeactivateNotification(request, _dbContext);
// Assert
result.Should().BeOfType<NotFound<string>>();
}
[Test]
public async Task InactiveNotification_ReturnsBadRequest()
{
// Arrange
var request = new DeactivateNotificationDto { Id = TestData.InactiveNotificationId };
// Act
var result = await Repository.DeactivateNotification(request, _dbContext);
// Assert
result.Should().BeOfType<BadRequest<List<string>>>();
}
[Test]
public async Task ExpiredNotification_ReturnsBadRequest()
{
// Arrange
var request = new DeactivateNotificationDto { Id = TestData.ExpiredNotificationId };
// Act
var result = await Repository.DeactivateNotification(request, _dbContext);
// Assert
result.Should().BeOfType<BadRequest<List<string>>>();
}
}