Browse Source

Add tests for Payment Service

pull/64/head
enisn 5 years ago
parent
commit
e915e83a1b
  1. 29
      services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethodAppService_Test.cs
  2. 48
      services/payment/test/EShopOnAbp.PaymentService.Application.Tests/PaymentMethods/PaymentMethod_Tests.cs
  3. 8
      services/payment/test/EShopOnAbp.PaymentService.EntityFrameworkCore.Tests/PaymentRequests/PaymentRequestRepository_Tests.cs

29
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<IPaymentMethodAppService>();
}
[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);
}
}

48
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<IEnumerable<IPaymentMethod>>();
paymentMethods.Count().ShouldBe(existingPaymentMethodTypes.Length);
}
[Fact]
public void EnsurePaymentTypeIsUnique()
{
var paymentMethods = GetRequiredService<IEnumerable<IPaymentMethod>>().ToList();
var distinctedPaymentMethods = paymentMethods.DistinctBy(p => p.PaymentType).ToList();
paymentMethods.Count.ShouldBe(distinctedPaymentMethods.Count);
}
[Fact]
public void EnsureAllPaymentMethodsHavePaymentTypeImplementation()
{
foreach (var paymentMethod in GetRequiredService<IEnumerable<IPaymentMethod>>())
{
paymentMethod.PaymentType.ShouldNotBeNullOrEmpty();
}
}
private static Type[] GetExistingPaymentMethotTypes()
{
return typeof(IPaymentMethod)
.Assembly
.GetTypes()
.Where(t => typeof(IPaymentMethod).IsAssignableFrom(t) && !t.IsAbstract)
.ToArray();
}
}

8
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);
}
}

Loading…
Cancel
Save