Repository navigation
Expand file tree
/
Copy pathGetLoan.cs
More file actions
64 lines (53 loc) · 2.02 KB
/
Copy pathGetLoan.cs
File metadata and controls
64 lines (53 loc) · 2.02 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
using NSubstitute;
using Library.ApplicationCore;
using Library.ApplicationCore.Entities;
using Library.Infrastructure.Data;
using Microsoft.Extensions.Configuration;
using Xunit;
namespace UnitTests.Infrastructure.JsonLoanRepositoryTests;
public class GetLoanTest
{
private readonly ILoanRepository _mockLoanRepository;
private readonly JsonLoanRepository _jsonLoanRepository;
private readonly IConfiguration _configuration;
private readonly JsonData _jsonData;
public GetLoanTest()
{
_mockLoanRepository = Substitute.For<ILoanRepository>();
_configuration = new ConfigurationBuilder().Build();
_jsonData = new JsonData(_configuration);
_jsonLoanRepository = new JsonLoanRepository(_jsonData);
}
[Fact(DisplayName = "JsonLoanRepository.GetLoan: Returns loan when loan ID is found")]
public async Task GetLoan_ReturnsLoanWhenLoanIdIsFound()
{
// Arrange
var loanId = 1; // Use a loan ID that exists in the Loans.json file
var expectedLoan = new Loan
{
Id = loanId,
BookItemId = 17,
PatronId = 22,
LoanDate = DateTime.Parse("2023-12-08T00:40:43.1808862"),
DueDate = DateTime.Parse("2023-12-22T00:40:43.1808862"),
ReturnDate = null
};
_mockLoanRepository.GetLoan(loanId).Returns(expectedLoan);
// Act
var actualLoan = await _jsonLoanRepository.GetLoan(loanId);
// Assert
Assert.NotNull(actualLoan);
Assert.Equal(expectedLoan.Id, actualLoan?.Id);
}
[Fact(DisplayName = "JsonLoanRepository.GetLoan: Returns null when loan ID is not found")]
public async Task GetLoan_ReturnsNullWhenLoanIdIsNotFound()
{
// Arrange
var loanId = 999; // Use a loan ID that does not exist in the Loans.json file
_mockLoanRepository.GetLoan(loanId).Returns((Loan?)null);
// Act
var actualLoan = await _jsonLoanRepository.GetLoan(loanId);
// Assert
Assert.Null(actualLoan);
}
}