-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPaymentRequestAppService_Tests.cs
More file actions
158 lines (144 loc) · 6.04 KB
/
PaymentRequestAppService_Tests.cs
File metadata and controls
158 lines (144 loc) · 6.04 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Payments.Domain.PaymentRequests;
using Unity.Payments.Domain.Suppliers;
using Unity.Payments.Domain.Suppliers.ValueObjects;
using Unity.Payments.Enums;
using Volo.Abp.Uow;
using Volo.Abp.Users;
using Xunit;
namespace Unity.Payments.PaymentRequests;
public class PaymentRequestAppService_Tests : PaymentsApplicationTestBase
{
private readonly ICurrentUser _currentUser;
private readonly IExternalUserLookupServiceProvider _externalUserLookupServiceProvider;
private readonly IPaymentRequestAppService _paymentRequestAppService;
private readonly IPaymentRequestRepository _paymentRequestRepository;
private readonly ISupplierRepository _supplierRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public PaymentRequestAppService_Tests()
{
_currentUser = ServiceProvider.GetRequiredService<ICurrentUser>();
_externalUserLookupServiceProvider = GetRequiredService<IExternalUserLookupServiceProvider>();
_paymentRequestAppService = GetRequiredService<IPaymentRequestAppService>();
_paymentRequestRepository = GetRequiredService<IPaymentRequestRepository>();
_supplierRepository = GetRequiredService<ISupplierRepository>();
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
}
[Fact]
[Trait("Category", "Integration")]
public async Task CreateAsync_CreatesPaymentRequest()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var siteId = Guid.NewGuid();
var newSupplier = new Supplier(Guid.NewGuid(),
"Supplier",
"123",
Guid.NewGuid(),
"Test",
new MailingAddress(
"Address1",
"City",
"Province",
"ABC123"));
newSupplier.AddSite(new Site(siteId,
"123",
PaymentGroup.EFT,
new Address(
"123",
"456",
"789",
"Country",
"City",
"Province",
"ABC123")));
_ = await _supplierRepository.InsertAsync(newSupplier, true);
List<CreatePaymentRequestDto> paymentRequests = new List<CreatePaymentRequestDto> { new CreatePaymentRequestDto() {
Amount = 50,
InvoiceNumber ="Test",
ContractNumber ="",
CorrelationId = Guid.NewGuid(),
Description = "",
PayeeName= "",
SiteId= siteId,
SupplierNumber = "",
} };
// Act
var insertedPaymentRequest = await _paymentRequestAppService
.CreateAsync(paymentRequests);
// Assert
var paymentRequest = await _paymentRequestRepository.GetAsync(insertedPaymentRequest[0].Id, true);
paymentRequest.ShouldNotBeNull();
}
[Fact]
[Trait("Category", "Integration")]
public async Task GetListAsync_ReturnsPaymentsList()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var supplier = new Supplier(Guid.NewGuid(), "supp", "123", Guid.NewGuid(), "A");
supplier.AddSite(new Site(Guid.NewGuid(), "123", PaymentGroup.EFT));
var addedSupplier = await _supplierRepository.InsertAsync(supplier);
CreatePaymentRequestDto paymentRequestDto = new CreatePaymentRequestDto();
paymentRequestDto.InvoiceNumber = "";
paymentRequestDto.Amount = 100;
paymentRequestDto.PayeeName = "Test";
paymentRequestDto.ContractNumber = "0000000000";
paymentRequestDto.SupplierNumber = "";
paymentRequestDto.SiteId = addedSupplier.Sites[0].Id;
paymentRequestDto.CorrelationId = Guid.NewGuid();
paymentRequestDto.CorrelationProvider = "";
paymentRequestDto.ReferenceNumber = "UP-XXXX-000000";
paymentRequestDto.BatchName = "UNITY_BATCH_1";
paymentRequestDto.BatchNumber = 1;
_ = await _paymentRequestRepository.InsertAsync(new PaymentRequest(Guid.NewGuid(), paymentRequestDto), true);
// Act
var paymentRequests = await _paymentRequestAppService.GetListAsync(new Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto()
{
MaxResultCount = 100
});
// Assert
paymentRequests.TotalCount.ShouldBeGreaterThan(0);
}
[Fact]
[Trait("Category", "Integration")]
public async Task GetListAsync_ReturnsPagedPaymentsList()
{
// Arrange
using var uow = _unitOfWorkManager.Begin();
var supplier = new Supplier(Guid.NewGuid(), "supp", "123", Guid.NewGuid(), "A");
supplier.AddSite(new Site(Guid.NewGuid(), "123", PaymentGroup.EFT));
var addedSupplier = await _supplierRepository.InsertAsync(supplier);
CreatePaymentRequestDto paymentRequestDto = new CreatePaymentRequestDto
{
InvoiceNumber = "INV-001",
Amount = 100,
PayeeName = "Test Payee",
ContractNumber = "0000000000",
SupplierNumber = "SUP-001",
SiteId = addedSupplier.Sites[0].Id,
CorrelationId = Guid.NewGuid(),
CorrelationProvider = "TestProvider",
ReferenceNumber = "UP-XXXX-000001",
BatchName = "UNITY_BATCH_1",
BatchNumber = 1
};
_ = await _paymentRequestRepository.InsertAsync(new PaymentRequest(Guid.NewGuid(), paymentRequestDto), true);
// Act
var paymentRequests = await _paymentRequestAppService.GetListAsync(new Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto
{
MaxResultCount = 10,
SkipCount = 0,
Sorting = "CreationTime desc"
});
// Assert
paymentRequests.TotalCount.ShouldBeGreaterThan(0);
paymentRequests.Items.ShouldNotBeEmpty();
paymentRequests.Items[0].InvoiceNumber.ShouldBe("INV-001");
paymentRequests.Items[0].CreatorId.ShouldBe(PaymentsTestData.UserDataMocks.User1.Id);
}
}