152 lines
5.1 KiB
C#
152 lines
5.1 KiB
C#
using BrokerCore.Common;
|
|
using BrokerCore.Entity;
|
|
using BrokerCore.Entity.Actions;
|
|
|
|
using BrokerTest.Helper;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using ServerCore;
|
|
using ServerBase;
|
|
using ServerCommon;
|
|
|
|
using BrokerApiServer.Extensions;
|
|
|
|
namespace BrokerTest.Entity;
|
|
|
|
public class EntityMailTests : IAsyncLifetime
|
|
{
|
|
private readonly IServiceCollection m_services;
|
|
|
|
public EntityMailTests()
|
|
{
|
|
AppBuilderExtensions.initGlobalNlog();
|
|
var config = AppBuilderExtensions.initBrokerServerConfig();
|
|
m_services = new ServiceCollection();
|
|
m_services.AddSingleton(config);
|
|
m_services.addBrokerServerLogic(config);
|
|
m_services.AddScoped<PlanetUserEntity>();
|
|
}
|
|
|
|
public Task InitializeAsync()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
var server_logic = m_services.BuildServiceProvider().GetService<IServerLogic>();
|
|
server_logic?.getDynamoDbClient().getDbClient()?.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task testMethod1()
|
|
{
|
|
await using var scope = m_services.BuildServiceProvider();
|
|
var planet_user = scope.GetRequiredService<PlanetUserEntity>();
|
|
await planet_user.onInit();
|
|
planet_user.setPlanetId("new_earth");
|
|
|
|
var auth_action = planet_user.getEntityAction<UserAuthAction>();
|
|
Assert.NotNull(auth_action);
|
|
var result = await auth_action.findAndSetAllAttributeByAccountId("20462");
|
|
Assert.NotNull(result);
|
|
Assert.True(result.isSuccess());
|
|
Assert.Equal("20462", planet_user.getEntityAttributeNotNull<AccountAttribute>().AccountId);
|
|
|
|
var server_logic = scope.GetRequiredService<IServerLogic>();
|
|
|
|
// 이미 받은 편지 삭제
|
|
await delAllMails(planet_user, server_logic);
|
|
|
|
MetaTableTestHelper meta_table_test_helper = new();
|
|
meta_table_test_helper.load();
|
|
var meta_table_ref = meta_table_test_helper.getMetaTableRef();
|
|
var product_policy_mata =
|
|
meta_table_ref.MetaTable.PlanetItemExchangePolicyMetaTable.PlanetItemExchangePolicyDataList.FirstOrDefault(x =>
|
|
x.CaliverseItemType == CaliverseItemType.CaliverseProduct.ToString());
|
|
Assert.NotNull(product_policy_mata);
|
|
|
|
var mail_send_by_product_id = async (int productId) =>
|
|
{
|
|
var broker_mail = new BrokerMailEntity(planet_user, server_logic);
|
|
result = await broker_mail.onInit();
|
|
Assert.NotNull(result);
|
|
Assert.True(result.isSuccess());
|
|
|
|
meta_table_ref.MetaTable.ProductMetaTable.ProductMetaDataListbyId.TryGetValue(
|
|
productId, out var product_meta);
|
|
Assert.NotNull(product_meta);
|
|
|
|
meta_table_ref.MetaTable.SystemMailMetaTable.SystemMailMetaDataListbyKey.TryGetValue(
|
|
product_meta.SystemMail_First, out var mail_meta);
|
|
Assert.NotNull(mail_meta);
|
|
|
|
var mail_send_action = broker_mail.getEntityActionNotNull<BrokerMailSendAction>();
|
|
var mail_option = mail_send_action.createSystemSendMailOptionByMeta(product_meta, mail_meta, planet_user.UserGuid,
|
|
planet_user.Nickname, 100);
|
|
// var mail_option2 =
|
|
// Helpers.createMailOptionByProductMeta(product_meta, mail_meta, planet_user.UserGuid,
|
|
// planet_user.Nickname);
|
|
result = await mail_send_action.sendMail(mail_option, () => Task.CompletedTask, () => Task.CompletedTask);
|
|
Assert.NotNull(result);
|
|
Assert.True(result.isSuccess());
|
|
|
|
var mail = broker_mail.getEntityAttributeNotNull<MailAttribute>();
|
|
|
|
var mail_recv_action = broker_mail.getEntityActionNotNull<BrokerMailRecvAction>();
|
|
var (mail_recv_result, recv_mail_docs)
|
|
= await mail_recv_action.findReceivedMailDoc(planet_user.UserGuid);
|
|
Assert.NotNull(mail_recv_result);
|
|
Assert.True(mail_recv_result.isSuccess());
|
|
Assert.NotNull(recv_mail_docs);
|
|
Assert.True(recv_mail_docs.Count > 0);
|
|
var result_mail_attrib =
|
|
recv_mail_docs.FirstOrDefault(x => x.getAttrib<MailAttrib>()?.MailGuid == mail.MailGuid);
|
|
Assert.NotNull(result_mail_attrib);
|
|
};
|
|
|
|
IEnumerable<int> product_ids = [3001, 3002, 3003, 3004];
|
|
foreach (var product_id in product_ids)
|
|
{
|
|
await mail_send_by_product_id(product_id);
|
|
await Task.Delay(10);
|
|
}
|
|
|
|
// var product_ids = meta_table_ref.MetaTable.ProductMetaTable.ProductMetaDataList
|
|
// .Take(10).Select(x => x.Id);
|
|
// foreach (var product_id in product_ids)
|
|
// {
|
|
// await mail_send_by_product_id(product_id);
|
|
// await Task.Delay(10);
|
|
// }
|
|
//
|
|
// await delAllMails(planet_user, server_logic);
|
|
}
|
|
|
|
private async Task delAllMails(PlanetUserEntity planetUser, IServerLogic serverLogic)
|
|
{
|
|
//==========================================
|
|
// 이미 받은 편지 삭제
|
|
//==========================================
|
|
var broker_mail_receiver = new BrokerMailEntity(planetUser, serverLogic);
|
|
var result = await broker_mail_receiver.onInit();
|
|
Assert.NotNull(result);
|
|
Assert.True(result.isSuccess());
|
|
var mail_recv_action = broker_mail_receiver.getEntityActionNotNull<BrokerMailRecvAction>();
|
|
{
|
|
var (recv_result, recv_mails) = await mail_recv_action.findReceivedMailDoc(planetUser.UserGuid);
|
|
Assert.NotNull(recv_result);
|
|
Assert.True(recv_result.isSuccess());
|
|
foreach (var attrib in recv_mails.Select(recvMail => recvMail.getAttrib<MailAttrib>()))
|
|
{
|
|
Assert.NotNull(attrib);
|
|
var result_del = await mail_recv_action.deleteMail(attrib.MailGuid);
|
|
Assert.NotNull(result_del);
|
|
Assert.True(result_del.isSuccess());
|
|
}
|
|
}
|
|
}
|
|
}
|