diff --git a/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethodAppService_Test.cs b/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethodAppService_Test.cs new file mode 100644 index 00000000..45666bc7 --- /dev/null +++ b/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethodAppService_Test.cs @@ -0,0 +1,29 @@ +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace EShopOnAbp.PaymentService.PaymentMethods; +public class PaymentMethodAppService_Test : PaymentServiceApplicationTestBase +{ + IPaymentMethodAppService _paymentMethodAppService; + + public PaymentMethodAppService_Test() + { + _paymentMethodAppService = GetRequiredService(); + } + + [Fact] + public async Task ShouldReturnAllPaymentMethods() + { + var paymentMethods = await _paymentMethodAppService.GetListAsync(); + + paymentMethods.ShouldNotBeEmpty(); + + paymentMethods.ShouldContain(x => x.PaymentType == PaymentTypes.PayPal); + paymentMethods.ShouldContain(x => x.PaymentType == PaymentTypes.Demo); + } +} diff --git a/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethod_Tests.cs b/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethod_Tests.cs new file mode 100644 index 00000000..ec6e4a8a --- /dev/null +++ b/services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethod_Tests.cs @@ -0,0 +1,48 @@ +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace EShopOnAbp.PaymentService.PaymentMethods; + +public class PaymentMethod_Tests : PaymentServiceApplicationTestBase +{ + [Fact] + public void EnsureAllPaymentMethodsAreRegistered() + { + var existingPaymentMethodTypes = GetExistingPaymentMethotTypes(); + + var paymentMethods = GetRequiredService>(); + + paymentMethods.Count().ShouldBe(existingPaymentMethodTypes.Length); + } + + [Fact] + public void EnsurePaymentTypeIsUnique() + { + var paymentMethods = GetRequiredService>().ToList(); + + var distinctedPaymentMethods = paymentMethods.DistinctBy(p => p.PaymentType).ToList(); + + paymentMethods.Count.ShouldBe(distinctedPaymentMethods.Count); + } + + [Fact] + public void EnsureAllPaymentMethodsHavePaymentTypeImplementation() + { + foreach (var paymentMethod in GetRequiredService>()) + { + paymentMethod.PaymentType.ShouldNotBeNullOrEmpty(); + } + } + + private static Type[] GetExistingPaymentMethotTypes() + { + return typeof(IPaymentMethod) + .Assembly + .GetTypes() + .Where(t => typeof(IPaymentMethod).IsAssignableFrom(t) && !t.IsAbstract) + .ToArray(); + } +} diff --git a/services/payment/test/EShopOnAbp.PaymentService.EntityFrameworkCore.Tests/PaymentRequests/PaymentRequestRepository_Tests.cs b/services/payment/test/EShopOnAbp.PaymentService.EntityFrameworkCore.Tests/PaymentRequests/PaymentRequestRepository_Tests.cs index f21634a0..dabc4147 100644 --- a/services/payment/test/EShopOnAbp.PaymentService.EntityFrameworkCore.Tests/PaymentRequests/PaymentRequestRepository_Tests.cs +++ b/services/payment/test/EShopOnAbp.PaymentService.EntityFrameworkCore.Tests/PaymentRequests/PaymentRequestRepository_Tests.cs @@ -18,12 +18,12 @@ namespace EShopOnAbp.PaymentService.PaymentRequests public async Task Should_Insert_Payment_Request() { var id = Guid.NewGuid(); - var paymentRequest = new PaymentRequest(id, "123",456,"USD"); - + var paymentRequest = new PaymentRequest(id, Guid.NewGuid().ToString(), 456, "USD"); + await _paymentRequestRepository.InsertAsync(paymentRequest, autoSave: true); - + var inserted = await _paymentRequestRepository.GetAsync(id); - + inserted.Id.ShouldNotBe(Guid.Empty); } }