126 lines
4.6 KiB
C#
126 lines
4.6 KiB
C#
using YLErp.Helpers;
|
|
|
|
namespace YLErp.Commons
|
|
{
|
|
[TestClass]
|
|
public class FoundationTest
|
|
{
|
|
[TestMethod]
|
|
public void DataConvertToLetterTest()
|
|
{
|
|
var result = "";
|
|
|
|
result = DataHelper.ConvertToLetter(0);
|
|
Assert.IsTrue(result == "A");
|
|
result = DataHelper.ConvertToLetter(25);
|
|
Assert.IsTrue(result == "Z");
|
|
result = DataHelper.ConvertToLetter(26);
|
|
Assert.IsTrue(result == "AA");
|
|
result = DataHelper.ConvertToLetter(701);
|
|
Assert.IsTrue(result == "ZZ");
|
|
result = DataHelper.ConvertToLetter(702);
|
|
Assert.IsTrue(result == "AAA");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestExceptionHelper()
|
|
{
|
|
var aex = new AggregateException(new[] {
|
|
new Exception("hello1",new Exception("gogog")),
|
|
new Exception("hello2",new NotSupportedException("not support")),
|
|
new AggregateException(new []{
|
|
new NotSupportedException("hello--1",new Exception("gogog--2")),
|
|
new NotSupportedException("hello--1",new NotSupportedException("gogog--3",new Exception("bbb"))),
|
|
new Exception("hello--2",new NotSupportedException("not support--2")),
|
|
}),
|
|
new InvalidOperationException("invalid operation"),
|
|
});
|
|
|
|
var bas = ExceptionHelper.GetBaseExceptions(aex);
|
|
Assert.AreEqual(bas[0].Message, "hello1");
|
|
Assert.AreEqual(bas[1].Message, "hello2");
|
|
Assert.AreEqual(bas[2].Message, "gogog--2");
|
|
Assert.AreEqual(bas[3].Message, "hello--1");
|
|
Assert.AreEqual(bas[4].Message, "hello--2");
|
|
Assert.AreEqual(bas[5].Message, "invalid operation");
|
|
|
|
System.Diagnostics.Debug.WriteLine(aex.Messages());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestDataChangeHelper()
|
|
{
|
|
var sourceTrade = new trade
|
|
{
|
|
TradeType = "香草期权",
|
|
TradeSinglePrice = 1.25,
|
|
NumOfSmoothingDays = 5,
|
|
TradeAmount = 3.24,
|
|
TraderId = 15,
|
|
Notional = 26.434,
|
|
IsUsePremiumRate = true,//
|
|
IsTradePricePayType = true,
|
|
MarginType = DBModels.Enums.MarginTypeEnum.FLOAT,
|
|
DividendDate = DateTime.Now,
|
|
SettlementDate = DateTime.Now.AddDays(-1),
|
|
get_trade_swap_details = new System.Collections.Generic.List<trade_swap_detail>
|
|
{
|
|
new trade_swap_detail
|
|
{
|
|
ExerciseDate = DateTime.Now,
|
|
FinalPrice = 26.45
|
|
}
|
|
},
|
|
MetaDic = new System.Collections.Generic.Dictionary<string, string>
|
|
{
|
|
["asd"] = "asdf",
|
|
["3w4"] = "58"
|
|
},
|
|
trade_forward = new trade_forward
|
|
{
|
|
OpenCommission = 156.685,
|
|
AnnualMarginRate = 354.438
|
|
},
|
|
trade_asian_option = null
|
|
};
|
|
var newTrade = new trade
|
|
{
|
|
TradeType = "香草期权",
|
|
TradeSinglePrice = 1.25,
|
|
NumOfSmoothingDays = 5,
|
|
TradeAmount = 3.24,
|
|
TraderId = 15,
|
|
Notional = 26.434,
|
|
IsUsePremiumRate = true,
|
|
IsTradePricePayType = true,
|
|
MarginType = DBModels.Enums.MarginTypeEnum.FLOAT,
|
|
DividendDate = DateTime.Now,
|
|
SettlementDate = DateTime.Now.AddDays(-1),
|
|
get_trade_swap_details = new System.Collections.Generic.List<trade_swap_detail>
|
|
{
|
|
new trade_swap_detail
|
|
{
|
|
ExerciseDate = DateTime.Now,
|
|
FinalPrice = 26.44
|
|
}
|
|
},
|
|
MetaDic = new System.Collections.Generic.Dictionary<string, string>
|
|
{
|
|
["as1d"] = "asdf",
|
|
["3w4"] = "58"
|
|
},
|
|
trade_forward = new trade_forward
|
|
{
|
|
OpenCommission = 156.685,
|
|
AnnualMarginRate = 354.438
|
|
},
|
|
trade_asian_option = null
|
|
};
|
|
TradeHelper2.ReduceTradeExt(sourceTrade);
|
|
TradeHelper2.ReduceTradeExt(newTrade);
|
|
var list = DataChangeHelper.GetDataChanges(sourceTrade, newTrade);
|
|
Assert.IsNotNull(list);
|
|
}
|
|
}
|
|
}
|