当前位置: 首页>>代码示例>>C#>>正文


C# Book.AddPriceQuote方法代码示例

本文整理汇总了C#中Book.AddPriceQuote方法的典型用法代码示例。如果您正苦于以下问题:C# Book.AddPriceQuote方法的具体用法?C# Book.AddPriceQuote怎么用?C# Book.AddPriceQuote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book.AddPriceQuote方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Replay_WhenSavePointIsNull_ReplaysFromTheBeginning

        public void Replay_WhenSavePointIsNull_ReplaysFromTheBeginning()
        {
            // Create a new, valid book.
            var book = new Book();

            // Create a new, valid account.
            var account = TestUtils.CreateValidAccount();

            // Create a new, valid transaction.
            var transaction = TestUtils.CreateValidTransaction(account);

            // Get two valid securities.
            var security1 = TestUtils.TestCurrency;
            var security2 = TestUtils.TestStock;

            // Create a new, valid price quote based on the above securities.
            var priceQuote = TestUtils.CreateValidPriceQuote();

            // Add and immediately remove the security, account, and transaction from the book.
            book.AddSecurity(security1);
            book.AddSecurity(security2);
            book.AddAccount(account);
            book.AddPriceQuote(priceQuote);
            book.RemovePriceQuote(priceQuote);
            book.AddTransaction(transaction);
            book.RemoveTransaction(transaction);
            book.RemoveAccount(account);
            book.RemoveSecurity(security2);
            book.RemoveSecurity(security1);

            // Create a new mock data adapter and replay the book changes into the mock.
            var destination = new MockSaver();
            book.Replay(destination, null);

            // Assert that the mock received the proper additional and removals of each component.
            Assert.That(destination.SecurityAdditions.Count, Is.EqualTo(2));
            Assert.That(destination.SecurityRemovals.Count, Is.EqualTo(2));
            Assert.That(destination.PriceQuoteAdditions.Count, Is.EqualTo(1));
            Assert.That(destination.PriceQuoteRemovals.Count, Is.EqualTo(1));
            Assert.That(destination.AccountAdditions.Count, Is.EqualTo(1));
            Assert.That(destination.AccountRemovals.Count, Is.EqualTo(1));
            Assert.That(destination.TransactionAdditions.Count, Is.EqualTo(1));
            Assert.That(destination.TransactionRemovals.Count, Is.EqualTo(1));
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:44,代码来源:BookSavingTests.cs

示例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;
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:101,代码来源:XmlPersistenceStrategy.cs

示例3: RemoveSecurity_WhenSecurityIsUsedByPriceQuoteAsSecurity_ThrowsException

        public void RemoveSecurity_WhenSecurityIsUsedByPriceQuoteAsSecurity_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency and stock to the book.
            book.AddSecurity(TestUtils.TestCurrency);
            book.AddSecurity(TestUtils.TestStock);

            // Create a new, valid price quote based on the above securities.
            var priceQuote = TestUtils.CreateValidPriceQuote();

            // Add the price quote to the book.
            book.AddPriceQuote(priceQuote);

            // Assert that trying to remove the security while the price quote depends on it throws an InvalidOperationException.
            Assert.That(() => book.RemoveSecurity(TestUtils.TestStock), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:18,代码来源:BookTests.cs

示例4: RemovePriceQuote_WhenValid_NotifiesOfChange

        public void RemovePriceQuote_WhenValid_NotifiesOfChange()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test stock and currency to the book.
            book.AddSecurity(TestUtils.TestStock);
            book.AddSecurity(TestUtils.TestCurrency);

            // Create a new, valid price quote based on the above securities and add it to the book.
            var priceQuote = TestUtils.CreateValidPriceQuote();
            book.AddPriceQuote(priceQuote);

            // Wire-up the CollectionChanged event to flag the change.
            bool called = false;
            book.PriceQuoteRemoved += (sender, e) => { called = true; };

            // Remove the price quote from the book.
            book.RemovePriceQuote(priceQuote);

            // Assert that the collection notified us of the change.
            Assert.That(called, Is.True);
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:23,代码来源:BookTests.cs

示例5: RemovePriceQuote_WhenValid_Succeeds

        public void RemovePriceQuote_WhenValid_Succeeds()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test stock and currency to the book.
            book.AddSecurity(TestUtils.TestStock);
            book.AddSecurity(TestUtils.TestCurrency);

            // Create a new, valid price quote based on the above securities and add it to the book.
            var priceQuote = TestUtils.CreateValidPriceQuote();
            book.AddPriceQuote(priceQuote);

            // Remove the price quote from the book.
            book.RemovePriceQuote(priceQuote);

            // The test passes, because the call to RemovePriceQuote() has completed successfully.
            Assert.True(true);  // Assert.Pass() was not used, to maintain compatibility with ReSharper.
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:19,代码来源:BookTests.cs

示例6: AddPriceQuote_WhenSecurityHasNotBeenAdded_ThrowsException

        public void AddPriceQuote_WhenSecurityHasNotBeenAdded_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency (but not a test stock) to the book.
            book.AddSecurity(TestUtils.TestCurrency);

            // Create a new, valid price quote based on the above securities.
            var priceQuote = TestUtils.CreateValidPriceQuote();

            // Assert that attempting to add the price quote without adding the security to the book throws an InvalidOperationException.
            Assert.That(() => book.AddPriceQuote(priceQuote), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:14,代码来源:BookTests.cs

示例7: RemovePriceQuote_WhenPriceQuoteHasAlreadyBeenRemoved_ThrowsException

        public void RemovePriceQuote_WhenPriceQuoteHasAlreadyBeenRemoved_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test stock and currency to the book.
            book.AddSecurity(TestUtils.TestStock);
            book.AddSecurity(TestUtils.TestCurrency);

            // Create a new, valid price quote.
            var priceQuote = TestUtils.CreateValidPriceQuote();

            // Add and immediately remove the price quote from the book.
            book.AddPriceQuote(priceQuote);
            book.RemovePriceQuote(priceQuote);

            // Assert that attempting to remove a price quote that has already been removed throws an InvalidOperationException.
            Assert.That(() => book.RemovePriceQuote(priceQuote), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:19,代码来源:BookTests.cs

示例8: AddPriceQuote_WhenPriceQuoteIsValid_Succeeds

        public void AddPriceQuote_WhenPriceQuoteIsValid_Succeeds()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency and stock to the book.
            book.AddSecurity(TestUtils.TestCurrency);
            book.AddSecurity(TestUtils.TestStock);

            // Create a new, valid price quote based on the above securities.
            var priceQuote = TestUtils.CreateValidPriceQuote();

            // Attempt to add the price quote to the book.
            book.AddPriceQuote(priceQuote);

            // The test passes, because the call to AddAccount() has completed successfully.
            Assert.True(true);  // Assert.Pass() was not used, to maintain compatibility with ReSharper.
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:18,代码来源:BookTests.cs

示例9: AddPriceQuote_WhenPriceQuoteIsNull_ThrowsException

        public void AddPriceQuote_WhenPriceQuoteIsNull_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Assert that attempting to add a price quote of null throws an ArgumentNullException.
            Assert.That(() => book.AddPriceQuote(null), Throws.InstanceOf<ArgumentNullException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:8,代码来源:BookTests.cs

示例10: AddPriceQuote_WhenPriceQuoteHasAlreadyBeenAdded_ThrowsException

        public void AddPriceQuote_WhenPriceQuoteHasAlreadyBeenAdded_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency and stock to the book.
            book.AddSecurity(TestUtils.TestCurrency);
            book.AddSecurity(TestUtils.TestStock);

            // Create a new, valid price quote based on the above securities and add it to the book.
            var priceQuote = TestUtils.CreateValidPriceQuote();
            book.AddPriceQuote(priceQuote);

            // Assert that attempting to add the price quote again throws an InvalidOperationException.
            Assert.That(() => book.AddPriceQuote(priceQuote), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:16,代码来源:BookTests.cs

示例11: AddPriceQuote_WhenAnotherPriceQuoteWithSameSecurityCurrencySourceAndDateHasBeenAdded_ThrowsException

        public void AddPriceQuote_WhenAnotherPriceQuoteWithSameSecurityCurrencySourceAndDateHasBeenAdded_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency and stock to the book.
            book.AddSecurity(TestUtils.TestCurrency);
            book.AddSecurity(TestUtils.TestStock);

            // Create a new, valid price quote based on the above securities and add it to the book.
            var priceQuote1 = TestUtils.CreateValidPriceQuote();
            book.AddPriceQuote(priceQuote1);

            // Create a new, valid price quote that is identical to the above quote.
            var priceQuote2 = TestUtils.CreateValidPriceQuote();

            // Assert that attempting to add the second price quote when the first price quote duplicates it throws an InvalidOperationException.
            Assert.That(() => book.AddPriceQuote(priceQuote2), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:19,代码来源:BookTests.cs

示例12: AddPriceQuote_WhenAnotherPriceQuoteWithSamePriceQuoteIdHasBeenAdded_ThrowsException

        public void AddPriceQuote_WhenAnotherPriceQuoteWithSamePriceQuoteIdHasBeenAdded_ThrowsException()
        {
            // Create a new, valid book.
            var book = new Book();

            // Add a test currency and stock to the book.
            book.AddSecurity(TestUtils.TestCurrency);
            book.AddSecurity(TestUtils.TestStock);

            // Create a new, valid price quote based on the above securities and add it to the book.
            var priceQuote1 = TestUtils.CreateValidPriceQuote();
            book.AddPriceQuote(priceQuote1);

            // Create a new, valid price quote that has the same price quote id as the above quote.
            var priceQuote2 = new PriceQuote(
                priceQuote1.PriceQuoteId,
                DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc), // OK
                TestUtils.TestStock, // OK
                1, // OK
                TestUtils.TestCurrency, // OK
                1, // OK
                "OK_SOURCE");

            // Assert that attempting to add the second price quote when the first price quote duplicates it throws an InvalidOperationException.
            Assert.That(() => book.AddPriceQuote(priceQuote2), Throws.InstanceOf<InvalidOperationException>());
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:26,代码来源:BookTests.cs


注:本文中的Book.AddPriceQuote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。