本文整理汇总了C#中Book.SetSetting方法的典型用法代码示例。如果您正苦于以下问题:C# Book.SetSetting方法的具体用法?C# Book.SetSetting怎么用?C# Book.SetSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book.SetSetting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetSetting_WhenValid_Succeeds
public void SetSetting_WhenValid_Succeeds(string key, string value)
{
// Create a new, empty book.
var book = new Book();
// Attempt to set the value of a setting.
book.SetSetting(key, value);
// The test passes, because the call to SetSetting() has completed successfully.
Assert.True(true); // Assert.Pass() was not used, to maintain compatibility with ReSharper.
}
示例2: Load
//.........这里部分代码省略.........
var security = new Security(securityId, securityType, name, symbol, format, fractionTraded);
securities.Add(security.SecurityId, security);
book.AddSecurity(security);
}
foreach (var a in doc.Element("Book").Element("Accounts").Elements("Account"))
{
var accountId = (Guid)a.Attribute("id");
var accountType = (AccountType)Enum.Parse(typeof(AccountType), (string)a.Attribute("type"));
Security security = null;
var securityAttr = a.Attribute("securityId");
if (securityAttr != null)
{
security = securities[(Guid)securityAttr];
}
Account parentAccount = null;
var parentAttr = a.Attribute("parentAccountId");
if (parentAttr != null)
{
parentAccount = accounts[(Guid)parentAttr];
}
var name = (string)a.Attribute("name");
var smallestFraction = (int?)a.Attribute("smallestFraction");
var account = new Account(accountId, accountType, security, parentAccount, name, smallestFraction);
accounts.Add(account.AccountId, account);
book.AddAccount(account);
}
foreach (var t in doc.Element("Book").Element("Transactions").Elements("Transaction"))
{
var transactionId = (Guid)t.Attribute("id");
var securityId = (Guid)t.Attribute("securityId");
var security = securities[securityId];
var date = (DateTime)t.Attribute("date");
var transaction = new Transaction(transactionId, security);
using (var tlock = transaction.Lock())
{
transaction.SetDate(date, tlock);
foreach (var s in t.Elements("Split"))
{
var split = transaction.AddSplit(tlock);
var accountId = (Guid)s.Attribute("accountId");
var account = accounts[accountId];
split.SetAccount(account, tlock);
var splitSecurityId = (Guid)s.Attribute("securityId");
var splitSecurity = securities[splitSecurityId];
split.SetSecurity(splitSecurity, tlock);
var amount = (long)s.Attribute("amount");
split.SetAmount(amount, tlock);
var transactionAmount = (long)s.Attribute("transactionAmount");
split.SetTransactionAmount(transactionAmount, tlock);
var dateCleared = (DateTime?)s.Attribute("dateCleared");
split.SetDateCleared(dateCleared, tlock);
var reconciled = (bool)s.Attribute("reconciled");
split.SetIsReconciled(reconciled, tlock);
}
}
book.AddTransaction(transaction);
}
foreach (var p in doc.Element("Book").Element("PriceQuotes").Elements("PriceQuote"))
{
var priceQuoteId = (Guid)p.Attribute("id");
var dateTime = (DateTime)p.Attribute("date");
var securityId = (Guid)p.Attribute("securityId");
var security = securities[securityId];
var quantity = (long)p.Attribute("quantity");
var currencyId = (Guid)p.Attribute("currencyId");
var currency = securities[currencyId];
var price = (long)p.Attribute("price");
var source = (string)p.Attribute("source");
var priceQuote = new PriceQuote(priceQuoteId, dateTime, security, quantity, currency, price, source);
book.AddPriceQuote(priceQuote);
}
foreach (var s in doc.Element("Book").Element("Settings").Elements("Setting"))
{
var key = (string)s.Attribute("key");
var value = (string)s.Attribute("value");
book.SetSetting(key, value);
}
return book;
}
示例3: SetSetting_WhenKeyIsEmpty_ThrowsException
public void SetSetting_WhenKeyIsEmpty_ThrowsException(string key)
{
// Create a new, empty book.
var book = new Book();
// Assert that attempting to remove a setting with a null or empty key throws an ArgumentNullException exception.
Assert.That(() => book.SetSetting(key, "OK_VALUE"), Throws.InstanceOf<ArgumentNullException>());
}