Browse Source

Complete the basic unit test of the payments module.

pull/99/head
GameBelial 6 years ago
parent
commit
b9b5850554
  1. 43
      modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs
  2. 27
      modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Refunds/RefundAppServiceTests.cs
  3. 15
      modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.TestBase/PaymentsTestData.cs
  4. 28
      modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.TestBase/PaymentsTestDataBuilder.cs

43
modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Payments/PaymentAppServiceTests.cs

@ -1,5 +1,11 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.EShop.Orders.Orders;
using EasyAbp.EShop.Orders.Orders.Dtos;
using EasyAbp.EShop.Payments.Payments.Dtos;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Xunit;
namespace EasyAbp.EShop.Payments.Payments
@ -8,19 +14,46 @@ namespace EasyAbp.EShop.Payments.Payments
{
private readonly IPaymentAppService _paymentAppService;
protected override void AfterAddApplication(IServiceCollection services)
{
MockOrderService(services);
}
private void MockOrderService(IServiceCollection services)
{
var orderService = Substitute.For<IOrderAppService>();
orderService.GetAsync(PaymentsTestData.Order1).Returns(Task.FromResult(new OrderDto
{
Id = PaymentsTestData.Order1,
Currency = "$",
TotalDiscount = 10,
TotalPrice = 100,
StoreId = PaymentsTestData.Store1
}));
services.AddTransient(_ => orderService);
}
public PaymentAppServiceTests()
{
_paymentAppService = GetRequiredService<IPaymentAppService>();
}
[Fact]
public async Task Test1()
public async Task Should_Success_Create_Payment()
{
// Arrange
var request = new CreatePaymentDto
{
OrderIds = new List<Guid>
{
PaymentsTestData.Order1
},
PaymentMethod = "Alipay"
};
// Act
// Assert
// Act & Assert
await _paymentAppService.CreateAsync(request);
}
}
}

27
modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Refunds/RefundAppServiceTests.cs

@ -1,5 +1,6 @@
using Shouldly;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.EShop.Payments.Refunds.Dtos;
using Xunit;
namespace EasyAbp.EShop.Payments.Refunds
@ -13,14 +14,30 @@ namespace EasyAbp.EShop.Payments.Refunds
_refundAppService = GetRequiredService<IRefundAppService>();
}
// TODO: There may be BUG.
[Fact]
public async Task Test1()
public async Task Should_Refund_Success()
{
// Arrange
var request = new CreateEShopRefundInput
{
DisplayReason = "Reason",
CustomerRemark = "Customer Remark",
PaymentId = PaymentsTestData.Payment1,
StaffRemark = "StaffRemark",
RefundItems = new List<CreateEShopRefundItemInput>
{
new CreateEShopRefundItemInput
{
CustomerRemark = "CustomerRemark",
OrderId = PaymentsTestData.Order1,
StaffRemark = "StaffRemark"
}
}
};
// Act
// Assert
// Act & Assert
await _refundAppService.CreateAsync(request);
}
}
}

15
modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.TestBase/PaymentsTestData.cs

@ -0,0 +1,15 @@
using System;
namespace EasyAbp.EShop.Payments
{
public static class PaymentsTestData
{
public static Guid Order1 { get; } = Guid.NewGuid();
public static Guid Order2 { get; } = Guid.NewGuid();
public static Guid Store1 { get; } = Guid.NewGuid();
public static Guid Payment1 { get; } = Guid.NewGuid();
}
}

28
modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.TestBase/PaymentsTestDataBuilder.cs

@ -0,0 +1,28 @@
using System.Threading.Tasks;
using EasyAbp.EShop.Payments.Payments;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
namespace EasyAbp.EShop.Payments
{
public class PaymentsTestDataBuilder : ITransientDependency
{
private readonly IPaymentRepository _paymentRepository;
public PaymentsTestDataBuilder(IPaymentRepository paymentRepository)
{
_paymentRepository = paymentRepository;
}
public void Build()
{
AsyncHelper.RunSync(BuildAsync);
}
public async Task BuildAsync()
{
// TODO: How to create payment?
// await _paymentRepository.InsertAsync(new Payment());
}
}
}
Loading…
Cancel
Save