Merge branch 'glms/feature/0812_zmr_divPower' into glms/feature/1.4.2
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YLErp.Modules.EodModule
|
||||
{
|
||||
[TestClass]
|
||||
public class DividendBasketQueryTranslationTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void DividendBasketQueriesUseEfTranslatableCommodityCondition()
|
||||
{
|
||||
var source = ReadDividendServiceSource();
|
||||
var addDividendQuery = ExtractQuery(
|
||||
source,
|
||||
"var basketList =",
|
||||
"IEnumerable<eod_stock_price> priceList = null;");
|
||||
var executeStatusQuery = ExtractQuery(
|
||||
source,
|
||||
"var umList = DataCacheProvider.GetUnderlyingDataSource().AsQueryable(",
|
||||
").Select(O => O.UnderlyingCode).ToArray();");
|
||||
|
||||
AssertQueryUsesCommodityCondition(addDividendQuery, "AddDividendInfos");
|
||||
AssertQueryUsesCommodityCondition(executeStatusQuery, "checkDividendInfoExecuteStatus");
|
||||
}
|
||||
|
||||
private static void AssertQueryUsesCommodityCondition(string query, string methodName)
|
||||
{
|
||||
Assert.IsFalse(
|
||||
query.Contains("IsBasket()", StringComparison.Ordinal),
|
||||
$"{methodName} must not put IsBasket() in an IQueryable predicate.");
|
||||
Assert.IsTrue(
|
||||
query.Contains("O.CommodityCode == \"篮子标的\"", StringComparison.Ordinal),
|
||||
$"{methodName} must filter baskets with the EF-translatable CommodityCode condition.");
|
||||
}
|
||||
|
||||
private static string ExtractQuery(string source, string startMarker, string endMarker)
|
||||
{
|
||||
var start = source.IndexOf(startMarker, StringComparison.Ordinal);
|
||||
Assert.IsTrue(start >= 0, $"Could not find query marker: {startMarker}");
|
||||
var end = source.IndexOf(endMarker, start + startMarker.Length, StringComparison.Ordinal);
|
||||
Assert.IsTrue(end >= 0, $"Could not find query end marker: {endMarker}");
|
||||
return source.Substring(start, end + endMarker.Length - start);
|
||||
}
|
||||
|
||||
private static string ReadDividendServiceSource()
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (directory != null)
|
||||
{
|
||||
var path = Path.Combine(
|
||||
directory.FullName,
|
||||
"YLErpDAL",
|
||||
"Modules",
|
||||
"TradeModule",
|
||||
"DealModule",
|
||||
"DividendService.cs");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
Assert.Fail("Could not locate DividendService.cs from the test output directory.");
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ namespace YLErp.Modules.EodModule
|
||||
{
|
||||
UnderlyingCode = "002043.SZ",
|
||||
ExDividendDate = new DateTime(2020, 7, 6),
|
||||
GiveCashAmount = 2.5,
|
||||
GiveCashAmount = 2.5m,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
@@ -135,7 +135,7 @@ namespace YLErp.Modules.EodModule
|
||||
{
|
||||
UnderlyingCode = "600406.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.9,
|
||||
GiveCashAmount = 2.9m,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
@@ -147,7 +147,7 @@ namespace YLErp.Modules.EodModule
|
||||
{
|
||||
UnderlyingCode = "600406.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.9,
|
||||
GiveCashAmount = 2.9m,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
@@ -159,7 +159,7 @@ namespace YLErp.Modules.EodModule
|
||||
{
|
||||
UnderlyingCode = "601021.SH",
|
||||
ExDividendDate = new DateTime(2020, 7, 8),
|
||||
GiveCashAmount = 2.0006,
|
||||
GiveCashAmount = 2.0006m,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
@@ -171,7 +171,7 @@ namespace YLErp.Modules.EodModule
|
||||
{
|
||||
UnderlyingCode = "300001.SZ",
|
||||
ExDividendDate = new DateTime(2020, 7, 13),
|
||||
GiveCashAmount = 0.2,
|
||||
GiveCashAmount = 0.2m,
|
||||
GiveShareAmount = 0,
|
||||
RationedSharesAmount = 0,
|
||||
RationedSharesPrice = 0,
|
||||
|
||||
Reference in New Issue
Block a user