초기커밋
This commit is contained in:
92
BrokerApiTest/DocQuery/DynamoDbClientTests.cs
Normal file
92
BrokerApiTest/DocQuery/DynamoDbClientTests.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace PlatformTest.DbQuery;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Xunit;
|
||||
using Amazon.DynamoDBv2;
|
||||
using Amazon.DynamoDBv2.Model;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
|
||||
public class DynamoDbClientTests
|
||||
{
|
||||
private ServerConfig? m_config;
|
||||
private string m_config_path = "../Config/Config.json";
|
||||
private string m_nlog_config_path = "../Config/nlog.config";
|
||||
|
||||
public DynamoDbClientTests()
|
||||
{
|
||||
Log.NLogFileName = m_nlog_config_path;
|
||||
m_config = new ServerConfig();
|
||||
m_config_path = Path.GetFullPath(m_config_path);
|
||||
m_config.setConfigFilePath(m_config_path);
|
||||
m_config.tryLoadConfig().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task connectToDb_ShouldConnectSuccessfully()
|
||||
{
|
||||
NullReferenceCheckHelper.throwIfNull(m_config);
|
||||
var dynamo_db_client = new DynamoDbClient();
|
||||
|
||||
// Act
|
||||
(var error_code, var to_load_table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType(m_config.ServiceType);
|
||||
if (error_code.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to DynamoDbClient.getDynamoDbTableNameWithServiceType() !!!";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var result = dynamo_db_client.connectToDb( to_load_table_names
|
||||
, m_config.AWS.LocalDynamoDB, m_config.Dynamodb
|
||||
, m_config.AWS.AccessKey, m_config.AWS.SecretKey, m_config.AWS.Region);
|
||||
if (result.isFail())
|
||||
{
|
||||
Log.getLogger().error($"Failed to connectToDb !!! ");
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert
|
||||
await Task.CompletedTask;
|
||||
Assert.True(result.isSuccess());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateDBIfNotExists_ShouldCreateTable()
|
||||
{
|
||||
NullReferenceCheckHelper.throwIfNull(m_config);
|
||||
|
||||
var dynamo_db_client = new DynamoDbClient();
|
||||
|
||||
(var error_code, var to_load_table_names) = ServerConfigHelper.getDynamoDbTableNamesWithServiceType(m_config.ServiceType);
|
||||
if (error_code.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to DynamoDbClient.getDynamoDbTableNameWithServiceType() !!!";
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var result = dynamo_db_client.connectToDb(to_load_table_names
|
||||
, m_config.AWS.LocalDynamoDB, m_config.Dynamodb
|
||||
, m_config.AWS.AccessKey, m_config.AWS.SecretKey, m_config.AWS.Region);
|
||||
if (result.isFail())
|
||||
{
|
||||
Log.getLogger().error($"Failed to connectToDb !!! ");
|
||||
return;
|
||||
}
|
||||
|
||||
// Act
|
||||
var is_success = await dynamo_db_client.createDBIfNotExists(false);
|
||||
|
||||
// Assert
|
||||
Assert.True(is_success);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user