从山证v2.3.0拷贝

This commit is contained in:
吴方海
2024-05-09 14:06:26 +08:00
parent 566ff33259
commit f9d8a256a6
4471 changed files with 1203456 additions and 9 deletions
@@ -0,0 +1,54 @@
namespace YLErp.Modules.DataProviderModule
{
[TestClass]
public class EodCurrencyProviderTest
{
[TestMethod]
public void TestGetCurrency()
{
using (var db = DbContextFactory.GetYLDbContext())
{
db.Database.ExecuteSqlRaw("delete from eod_currency_rate where ValueDate<='1971-01-01'");
var rate = new eod_currency_rate
{
ValueDate = new DateTime(1970, 12, 31),
BuyRate = 6.45,
ForeignCurrency = "USD",
LocalCurrency = "CNH",
OptDate = DateTime.Now,
OptId = 0,
OptName = "系统",
Rate = 6.45,
SellRate = 6.45
};
var rates = new eod_currency_rate[5];
rates[0] = rate;
for (var i = 1; i < 5; i++)
{
var rate2 = rates[i - 1].Clone();
rate2.ValueDate = rate2.ValueDate.AddDays(-i * 2);
rate2.BuyRate = rate2.SellRate = rate2.Rate -= 0.1;
rates[i] = rate2;
}
db.eod_currency_rate.AddRange(rates);
db.SaveChanges();
}
var provider = new EodCurrencyProvider(new DateTime(1970, 12, 31), false);
var bl = provider.TryGetCurrencyRate("usd", "cnh", out var rr);
Assert.IsTrue(bl);
Assert.AreEqual(rr.Rate, 6.45);
bl = provider.TryGetCurrencyRate("usd", "cny", out _);
Assert.IsFalse(bl);
provider = new EodCurrencyProvider(new DateTime(1970, 12, 24), true);
bl = provider.TryGetCurrencyRate("usd", "cnh", out rr);
Assert.IsTrue(bl);
Assert.AreEqual(rr.Rate, 6.15);
}
}
}
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YLErp.Modules.DataProviderModule
{
[TestClass]
public class EodExchangeOptionPriceProviderTest
{
[TestMethod]
public void Test()
{
var optionCode = "DB00-C-7000";
var provider = new EodExchangeOptionPriceProvider(new DateTime(2023,1,9), true);
var price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
var bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out var data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
price = provider.GetPrice(null);
Assert.AreEqual(price, 0);
bl = provider.TryGetPrice(null, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(null, out data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
optionCode = "RB00-C-5000";
provider.Initialize(new[] { optionCode });
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 520);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsTrue(bl);
Assert.AreEqual(price, 520);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsTrue(bl);
Assert.AreEqual(data.ClosePrice, 520);
provider = new EodExchangeOptionPriceProvider(new DateTime(2023, 1, 9), true).InitializeAll();
optionCode = "RB00-C-5000";
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 520);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsTrue(bl);
Assert.AreEqual(price, 520);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsTrue(bl);
Assert.AreEqual(data.ClosePrice, 520);
optionCode = "DB00-C-7000";
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
}
}
}
@@ -0,0 +1,20 @@
namespace YLErp.Modules.DataProviderModule
{
[TestClass]
public class EodPriceProviderTest : YLUnitTestBase
{
[TestMethod]
public void TestInitialize()
{
var provider1 = new EodPriceProvider(new DateTime(2021, 5, 27)).Initialize();
var provider2 = new EodPriceProvider(new DateTime(2021, 5, 27)).Initialize(new[] { "" });
Assert.AreEqual(provider1.Count, provider2.GetEodPriceList().Count());
var provider3 = new EodPriceProvider(new DateTime(2021, 5, 27)).Initialize(new[] { "RB00", "000300.SH" });
Assert.AreEqual(provider3.Count, 2);
}
}
}
@@ -0,0 +1,73 @@
namespace YLErp.Modules.DataProviderModule
{
[TestClass]
public class ExchangeOptionPriceProviderTest
{
[TestMethod]
public void Test()
{
var optionCode = "DB00-C-7000";
var provider = new ExchangeOptionPriceProvider(true);
var price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
var bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out var data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
optionCode = null;
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
optionCode = "DB00-C-7000";
provider = new ExchangeOptionPriceProvider(false);
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
optionCode = null;
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 0);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsFalse(bl);
Assert.AreEqual(price, 0);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsFalse(bl);
Assert.AreEqual(data, null);
optionCode = "RB00-C-5000";
provider = new ExchangeOptionPriceProvider(true);
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 510);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsTrue(bl);
Assert.AreEqual(price, 510);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsTrue(bl);
Assert.AreEqual(data.Price, 510);
provider = new ExchangeOptionPriceProvider(false);
price = provider.GetPrice(optionCode);
Assert.AreEqual(price, 510);
bl = provider.TryGetPrice(optionCode, out price);
Assert.IsTrue(bl);
Assert.AreEqual(price, 510);
bl = provider.TryGetPriceModel(optionCode, out data);
Assert.IsTrue(bl);
Assert.AreEqual(data.Price, 510);
}
}
}