-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPositionRepositoryAsyncSqliteTests.cs
More file actions
58 lines (50 loc) · 2.23 KB
/
Copy pathPositionRepositoryAsyncSqliteTests.cs
File metadata and controls
58 lines (50 loc) · 2.23 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
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace TalentManagementAPI.Infrastructure.Tests.Repositories
{
public class PositionRepositoryAsyncSqliteTests
{
[Fact]
public async Task GetPositionResponseAsync_ShouldFilterByTitleAndDepartment()
{
await using var connection = new SqliteConnection("DataSource=:memory:");
await connection.OpenAsync();
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseSqlite(connection)
.Options;
await using var context = new ApplicationDbContext(
options,
new DateTimeService(),
LoggerFactory.Create(_ => { }));
await context.Database.EnsureCreatedAsync();
var department = new Department { Id = Guid.NewGuid(), Name = new DepartmentName("Engineering") };
var salaryRange = new SalaryRange { Id = Guid.NewGuid(), MinSalary = 1, MaxSalary = 2 };
context.Departments.Add(department);
context.SalaryRanges.Add(salaryRange);
context.Positions.Add(new Position
{
Id = Guid.NewGuid(),
PositionNumber = "ENG-01",
PositionTitle = new PositionTitle("QA Engineer"),
PositionDescription = "Tests",
DepartmentId = department.Id,
SalaryRangeId = salaryRange.Id
});
await context.SaveChangesAsync();
var repository = new PositionRepositoryAsync(context, new DataShapeHelper<Position>(), new Mock<IMockService>().Object);
var query = new GetPositionsQuery
{
PositionTitle = "QA",
Department = "Engineering",
Fields = "Id,PositionTitle",
PageNumber = 1,
PageSize = 10
};
var (data, count) = await repository.GetPositionReponseAsync(query);
data.Should().HaveCount(1);
data.First()["PositionTitle"].Should().BeOfType<PositionTitle>().Which.Value.Should().Be("QA Engineer");
count.RecordsFiltered.Should().Be(1);
count.RecordsTotal.Should().Be(1);
}
}
}