3 changed files with 81 additions and 4 deletions
@ -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); |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue