本文整理汇总了C#中Stock.AddHistoricPrice方法的典型用法代码示例。如果您正苦于以下问题:C# Stock.AddHistoricPrice方法的具体用法?C# Stock.AddHistoricPrice怎么用?C# Stock.AddHistoricPrice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock.AddHistoricPrice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddsHistoricPriceWhenPriceIsNew
public void AddsHistoricPriceWhenPriceIsNew()
{
//// SETUP
// Test Data
var price1 = new HistoricPrice { Date = DateTime.Parse("1/1/2000") };
var price2 = new HistoricPrice { Date = DateTime.Parse("1/2/2000") };
var price3 = new HistoricPrice { Date = DateTime.Parse("1/3/2000") };
// Setup target
var target = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
// EXECUTE (3 times)
var actual1 = target.AddHistoricPrice(price1);
var actual2 = target.AddHistoricPrice(price2);
var actual3 = target.AddHistoricPrice(price3);
//// VERIFY
Assert.AreEqual(3, target.PriceHistory.Count);
// Price 1
Assert.True(actual1);
Assert.True(target.PriceHistory.Contains(price1));
Assert.AreSame(target, price1.Stock);
// Price 2
Assert.True(actual2);
Assert.True(target.PriceHistory.Contains(price2));
Assert.AreSame(target, price2.Stock);
// Price 3
Assert.True(actual3);
Assert.True(target.PriceHistory.Contains(price3));
Assert.AreSame(target, price2.Stock);
}
示例2: DoesNotAddHistoricPriceWhenPriceIsPreexisting
public void DoesNotAddHistoricPriceWhenPriceIsPreexisting()
{
//// SETUP
// Test Data
var price = new HistoricPrice { Date = DateTime.Parse("1/1/2000") };
var duplicatePrice = new HistoricPrice { Date = DateTime.Parse("1/1/2000") };
// Setup target
var target = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
// EXECUTE (twice)
var initialActual = target.AddHistoricPrice(price);
var duplicateActual = target.AddHistoricPrice(duplicatePrice);
//// VERIFY
Assert.AreEqual(1, target.PriceHistory.Count);
// Initial (Should have succeeded)
Assert.True(initialActual);
Assert.True(target.PriceHistory.Contains(price));
Assert.AreSame(target, price.Stock);
// Duplicate (Should have failed)
Assert.False(duplicateActual);
Assert.Null(duplicatePrice.Stock);
}