322 lines
12 KiB
C#
322 lines
12 KiB
C#
namespace YLErp
|
|
{
|
|
public class YLUnitTestBase : YLBaseService
|
|
{
|
|
readonly StringBuilder _clearSQL;
|
|
|
|
public YLUnitTestBase() : base(OptUserInfo.UnitTestUser)
|
|
{
|
|
_clearSQL = new StringBuilder();
|
|
}
|
|
|
|
public YLUnitTestBase(YLBaseService baseService) : base(baseService)
|
|
{
|
|
_clearSQL = new StringBuilder();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成标的代码为CESHI99X的标的或者RB00(长期固定代码)
|
|
/// </summary>
|
|
protected underlying_manager GetUnderlyingManager(bool isRB00 = false)
|
|
{
|
|
var underlyingCode = isRB00 ? "RB00" : "RBTST";
|
|
|
|
var un = DbContext.underlying_manager.AsNoTracking().FirstOrDefault(n => n.UnderlyingCode == underlyingCode);
|
|
|
|
if (un == null)
|
|
{
|
|
var va = GetVariety(true);
|
|
un = new underlying_manager
|
|
{
|
|
CommodityCode = "RB",
|
|
ContractSize = 10,
|
|
CountRatio = 1,
|
|
UnderlyingDesc = underlyingCode,
|
|
DividendRate = 0,
|
|
LaunchState = "1",
|
|
MarginRate = 0.06,
|
|
MarketCode = "SHFE",
|
|
MarketName = "上海期货交易所",
|
|
MaturityDate = new DateTime(2030, 1, 1),
|
|
OpenDate = new DateTime(2020, 1, 1),
|
|
OptDate = DateTime.Now,
|
|
OptId = UserId,
|
|
OptName = UserName,
|
|
VolatilityRate = "1%",
|
|
Block1 = 0,
|
|
Block2 = 0,
|
|
Block3 = 0,
|
|
Block4 = 0,
|
|
Block5 = 0,
|
|
IsMainContract = false,
|
|
LastUpdateTime = DateTime.Now,
|
|
PrevClosePrice = 3555,
|
|
Price = 3600,
|
|
PriceTick = 0.1,
|
|
TradeUnit = "10吨/手",
|
|
QuoteUnit = "元(人民币)/吨",
|
|
TradeCode = underlyingCode,
|
|
UnderlyingCode = underlyingCode,
|
|
UnderlyingName = isRB00 ? "RB连续合约" : underlyingCode,
|
|
UnderlyingInstrumentType = ConsGlobal.InstrumentType.CommodityFutures,
|
|
UnderlyingState = "Live",
|
|
UnderlyingStatus = "正常运行",
|
|
UnderlyingTypeId = va.id,
|
|
UnderlyingType = "螺纹钢",
|
|
UpDownLimit = "10%"
|
|
};
|
|
DbContext.underlying_manager.Add(un);
|
|
DbContext.SaveChanges();
|
|
if (!isRB00)
|
|
{
|
|
AddClearSQL<underlying_manager>("UnderlyingCode='{0}'", underlyingCode);
|
|
}
|
|
}
|
|
|
|
return un;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成标的代码为CESHI99X的标的
|
|
/// </summary>
|
|
protected Variety GetVariety(bool isRB = false)
|
|
{
|
|
var varietyCode = isRB ? "RB" : "TSTVA";
|
|
|
|
var va = DbContext.variety.AsNoTracking().FirstOrDefault(n => n.VarietyCode == varietyCode);
|
|
|
|
if (va == null)
|
|
{
|
|
var market = DbContext.market.AsNoTracking().FirstOrDefault(n => n.ExchangeNo == "SHFE");
|
|
va = new Variety
|
|
{
|
|
AssetType = "黑色系",
|
|
CloseTodayCommission = null,
|
|
CloseTodayCommissionType = "固定",
|
|
CloseTodayContractRule = "",
|
|
Commission = null,
|
|
CommissionType = "固定",
|
|
ContractMonth = "1-12月",
|
|
DeliveryGrade = "",
|
|
DeliveryPlace = "交易所指定交割仓库",
|
|
DeliveryType = "实物交割",
|
|
Description = "",
|
|
DownLimit = "6%",
|
|
HasFieldOptions = false,
|
|
HasNightMarket = false,
|
|
IsVarietyOpenLimitPercent = false,
|
|
Margin = 0.07,
|
|
MiniDeliveryUnit = null,
|
|
OptDate = OptDate,
|
|
OptId = UserId,
|
|
OptName = UserName,
|
|
MinPriceChange = "1元/吨",
|
|
QuoteUnit = "元(人民币)/吨",
|
|
TradeUnit = "10吨/手",
|
|
VarietyCode = varietyCode,
|
|
VarietyName = "螺纹钢",
|
|
ShortName = varietyCode,
|
|
TradedOptionCommissionType = null,
|
|
TradeTimeSlot = null,
|
|
UpLimit = "6%",
|
|
VolatilityRate = "6%",
|
|
VarietyOpenLimit = null,
|
|
TradingMarketId = market.id,
|
|
TradingMarket = "上海期货交易所"
|
|
};
|
|
|
|
DbContext.variety.Add(va);
|
|
DbContext.SaveChanges();
|
|
|
|
if (!isRB)
|
|
{
|
|
AddClearSQL<Variety>("id=" + va.id);
|
|
}
|
|
}
|
|
|
|
return va;
|
|
}
|
|
|
|
AssetUnit _assetunit;
|
|
|
|
/// <summary>
|
|
/// 获取test1簿记
|
|
/// </summary>
|
|
protected AssetUnit GetAssetUnit()
|
|
{
|
|
if (_assetunit != null)
|
|
{
|
|
return _assetunit;
|
|
}
|
|
_assetunit = DbContext.assetunit.AsNoTracking().FirstOrDefault(n => n.Name == "test1");
|
|
if (_assetunit == null)
|
|
{
|
|
_assetunit = new AssetUnit
|
|
{
|
|
Name = "test1",
|
|
BaseCurrency = "人民币CNY",
|
|
InitialMoney = null,
|
|
OptDate = OptDate,
|
|
OptId = UserId,
|
|
OptName = UserName,
|
|
Remark = "单元测试生成",
|
|
TraderIds = "1,2,3,4,5,6,7,8,9,10",
|
|
TraderNames = "",
|
|
UserGroup = null
|
|
};
|
|
DbContext.assetunit.Add(_assetunit);
|
|
DbContext.SaveChanges();
|
|
}
|
|
return _assetunit;
|
|
}
|
|
|
|
Client _client;
|
|
|
|
/// <summary>
|
|
/// 获取test1客户
|
|
/// </summary>
|
|
protected Client GetClient()
|
|
{
|
|
if (_client != null)
|
|
{
|
|
return _client;
|
|
}
|
|
var db = DbContextFactory.GetClientDbContext(OptUser);
|
|
_client = db.client.AsNoTracking().FirstOrDefault(n => n.Name == "test1");
|
|
if (_client == null)
|
|
{
|
|
_client = new Client
|
|
{
|
|
Name = "test1",
|
|
OptDate = OptDate,
|
|
OptId = UserId,
|
|
OptName = UserName,
|
|
Remark = "单元测试生成",
|
|
Abbreviation = "单元测试",
|
|
AcceptableLoss = "很多",
|
|
ActualBeneficiary = "单元测试",
|
|
ActualController = "单元测试",
|
|
Address = "单元测试",
|
|
AdminFullName = "单元测试",
|
|
AdminRegisteredNum = "单元测试",
|
|
AppropriatenessAssessor = 0,
|
|
AppropriatenessDegree = 5,
|
|
BadFaithRecord = 0,
|
|
BookTime = null,
|
|
BusinessScope = 0,
|
|
BusinessType = "单元测试",
|
|
Capitalbalance = 0,
|
|
ChangeReasonAndEvaluationResults = "",
|
|
ClientType = "",
|
|
Code = "",
|
|
CreditDeadline = null,
|
|
CreditDirection = "",
|
|
CreditName = "",
|
|
CreditTemp = 0,
|
|
CreditTempDeadline = null,
|
|
CreditYear = null,
|
|
CurrentContractNo = 0,
|
|
CustomerManager = "",
|
|
CustomerManagerId = "",
|
|
CustomerNature = 0,
|
|
CustomerNature1 = "",
|
|
CustomerNature2 = "",
|
|
DefaultLoginName = "",
|
|
DerivativesInvestmentVarieties = "",
|
|
DisbeliefRecord = "",
|
|
Email = "",
|
|
EndureLevel = "",
|
|
EvaluateDate = null,
|
|
EvaluateOfValidity = "",
|
|
ExpectedReturn2 = "",
|
|
FinancialSituation = "",
|
|
FundsSource = 0,
|
|
Guid = Guid.NewGuid().ToString("N"),
|
|
MarginOptionType = 0,
|
|
IdentificationNumber = "unit-test-001",
|
|
InstitutionalAttributes = "",
|
|
InvestmentExperience = "",
|
|
InvestmentTerm = 0,
|
|
InvestorType = 0,
|
|
IsAcceptHighRiskService = 0,
|
|
IsAssessmentResultChange = 0,
|
|
IsAutoReback = 0,
|
|
IsCreditOn = 0,
|
|
IsEvaluate = 0,
|
|
IsIndustryConnectVariety = 0,
|
|
IsRealControl = 0,
|
|
IsRequireConversionTypes = 0,
|
|
IsTradeCredit = 0,
|
|
Level = "",
|
|
LevelId = 0,
|
|
LicenseCode = "",
|
|
LicenseCodeDate = null,
|
|
LicenseType = "",
|
|
Number = "unit-test-001",
|
|
PendingMarginCallPayment = 0,
|
|
Phone = "",
|
|
PostalAddress = "",
|
|
PostalCode = "",
|
|
PrivateFundProductInformation = "",
|
|
ProcessOptDate = null,
|
|
ProcessOrderId = 0,
|
|
ProcessStatus = "",
|
|
ProductNumber = "",
|
|
ProperClientClass = "",
|
|
ProtocolSignDate = null,
|
|
ProtocolSignVersion = "",
|
|
Pwd = "",
|
|
Region = "",
|
|
QuestionnaireScore = 0,
|
|
RegisteredAddress = "",
|
|
RegisteredCapital = "",
|
|
RejectOrderId = 0,
|
|
RightProtocolSignDate = null,
|
|
RiskPreference = "",
|
|
RiskServiceDegree = 5,
|
|
SalesDepartment = "",
|
|
SalesDepartmentId = 0,
|
|
SamePeer = 0,
|
|
Seller = "",
|
|
TradingInstType = DBModels.Enums.TradingInstTypeEnum.All,
|
|
TransactionTarget = "",
|
|
Type = ""
|
|
};
|
|
db.client.Add(_client);
|
|
DbContext.SaveChanges();
|
|
}
|
|
return _client;
|
|
}
|
|
|
|
protected void AddClearSQL<TEntity>(string whereFormat, params object[] args) where TEntity : class
|
|
{
|
|
var tableName = DbContext.GetTableName<TEntity>();
|
|
|
|
_clearSQL.Append("delete from ").Append(tableName)
|
|
.Append(" where ").AppendFormat(whereFormat, args).AppendLine(";");
|
|
}
|
|
|
|
[ClassCleanup]
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (!disposing)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (_clearSQL.Length > 0)
|
|
{
|
|
DbContext.Database.ExecuteSqlRaw(_clearSQL.ToString());
|
|
_clearSQL.Clear();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
DbContext.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|