public override int GetHashCode() { int hash = 1; if (JWToken.Length != 0) { hash ^= JWToken.GetHashCode(); } if (reservation_ != null) { hash ^= Reservation.GetHashCode(); } if (priceQuote_ != null) { hash ^= PriceQuote.GetHashCode(); } if (reservationSummary_ != null) { hash ^= ReservationSummary.GetHashCode(); } if (HasLastMinuteWaiver != false) { hash ^= HasLastMinuteWaiver.GetHashCode(); } return(hash); }
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>()); }
public ActionResult DeleteConfirmed(int id) { PriceQuote priceQuote = db.PriceQuotes.Find(id); db.PriceQuotes.Remove(priceQuote); db.SaveChanges(); return(RedirectToAction("Index")); }
public static void DisplayQuote(PriceQuote quote) { Debug.Write(quote.Security.FormatValue(quote.Quantity)); Debug.Write(" = "); Debug.Write(quote.Currency.FormatValue(quote.Price)); Debug.Write(" @ "); Debug.WriteLine(quote.DateTime.ToString("O")); }
public ActionResult TemporaryDelete(int?id) { PriceQuote priceQuote = db.PriceQuotes.Find(id); priceQuote.IsDeleted = true; db.SaveChanges(); return(RedirectToAction("Index")); }
public PriceQuoteAddedEventArgs(PriceQuote priceQuote) { if (priceQuote == null) { throw new ArgumentNullException("priceQuote"); } this.priceQuote = priceQuote; }
public ActionResult Edit([Bind(Include = "Id,UserName,Email,PhoneNumber,Stock,Color,Quantity,Height,Width,Depth,Comments,File,SubmittedTime,Seen,IsDeleted,SeenTime")] PriceQuote priceQuote) { if (ModelState.IsValid) { db.Entry(priceQuote).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(priceQuote)); }
// GET: PriceQuotes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PriceQuote priceQuote = db.PriceQuotes.Find(id); if (priceQuote == null) { return(HttpNotFound()); } return(View(priceQuote)); }
public void Constructor_WithNonUTCDate_ThrowsException(DateTimeKind kind) { Assert.That(() => { var ignore = new PriceQuote( Guid.NewGuid(), // OK DateTime.SpecifyKind(DateTime.MinValue, kind), // OK TestUtils.TestStock, // OK 1, // OK TestUtils.TestCurrency, // OK 1, // OK "OK_SOURCE"); }, Throws.InstanceOf <ArgumentOutOfRangeException>()); }
public void OnNewQuote_SymbolDoesNotMatch_ApplicationException() { // Arrange var stock = new Stock { Symbol = "ABC" }; var quote = new PriceQuote() { LastPrice = 9.99M, LastTime = DateTimeOffset.Now.AddMinutes(-123), Symbol = "XYZ" }; // Act Assert.Throws <ApplicationException>(() => stock.OnNewQuote(quote)); }
// GET: PriceQuotes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PriceQuote priceQuote = db.PriceQuotes.Find(id); if (priceQuote == null) { return(HttpNotFound()); } priceQuote.Seen = true; priceQuote.SeenTime = DateTime.Now; db.SaveChanges(); return(View(priceQuote)); }
private void PriceQuoteRequestFulfilled(PriceQuote priceQuoteFulfilled) { var previousFulfillment = FulfilledPriceQuotes.Where(x => x.Id == priceQuoteFulfilled.Id).First(); var currentPriceQuotes = previousFulfillment.PriceQuotes.ToList(); currentPriceQuotes.Add(priceQuoteFulfilled); var currentFulfillment = previousFulfillment.Create(currentPriceQuotes); if (currentPriceQuotes.Count >= currentFulfillment.QuotesRequested) { QuoteBestPrice(currentFulfillment); } else { FulfilledPriceQuotes.Remove(previousFulfillment); FulfilledPriceQuotes.Add(currentFulfillment); } }
public void MergeFrom(ReservationBookedNotification other) { if (other == null) { return; } if (other.JWToken.Length != 0) { JWToken = other.JWToken; } if (other.reservation_ != null) { if (reservation_ == null) { reservation_ = new global::HOLMS.Types.Booking.Indicators.ReservationIndicator(); } Reservation.MergeFrom(other.Reservation); } if (other.priceQuote_ != null) { if (priceQuote_ == null) { priceQuote_ = new global::HOLMS.Types.Booking.Pricing.PretaxReservationQuote(); } PriceQuote.MergeFrom(other.PriceQuote); } if (other.reservationSummary_ != null) { if (reservationSummary_ == null) { reservationSummary_ = new global::HOLMS.Types.Booking.Reservations.ReservationSummary(); } ReservationSummary.MergeFrom(other.ReservationSummary); } if (other.HasLastMinuteWaiver != false) { HasLastMinuteWaiver = other.HasLastMinuteWaiver; } }
public void OnNewQuote_SymbolMatches_StockUpdatedWithQuote() { // Arrange var stock = new Stock { Symbol = "ABC", LastPrice = 9.56M }; var quote = new PriceQuote { LastPrice = 9.99M, LastTime = DateTimeOffset.Now.AddMinutes(-123), Symbol = "ABC" }; // Act stock.OnNewQuote(quote); // Assert stock.LastPrice.Should().Be(quote.LastPrice); stock.PreviousLastPrice.Should().Be(9.56M); stock.LastTime.Should().Be(quote.LastTime); stock.Symbol.Should().Be(quote.Symbol); }
public PriceQuoteAddedEventArgs(PriceQuote priceQuote) { this.PriceQuote = priceQuote ?? throw new ArgumentNullException(nameof(priceQuote)); }
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>()); }
public void Constructor_WithNonUTCDate_ThrowsException(DateTimeKind kind) { Assert.That(() => { var ignore = new PriceQuote( Guid.NewGuid(), // OK DateTime.SpecifyKind(DateTime.MinValue, kind), // OK TestUtils.TestStock, // OK 1, // OK TestUtils.TestCurrency, // OK 1, // OK "OK_SOURCE"); }, Throws.InstanceOf<ArgumentOutOfRangeException>()); }
public QuotationFulfillment(PriceQuote price, IActorRef requester) { Price = price; Requester = requester; }
/// <inheritdoc/> protected override Book Load(Uri uri) { var book = new Book(); var doc = XDocument.Load(uri.ToString()); var securities = new Dictionary <Guid, Security>(); var accounts = new Dictionary <Guid, Account>(); foreach (var s in doc.Element("Book").Element("Securities").Elements("Security")) { var f = s.Element("Format"); var decimalDigits = (int)f.Attribute("decimalDigits"); var decimalSeparator = (string)f.Attribute("decimalSeparator"); var groupSeparator = (string)f.Attribute("groupSeparator"); var groupSizes = ((string)f.Attribute("groupSizes")).Split(',').Select(g => int.Parse(g.Trim())); var positiveFormat = (PositiveFormat)Enum.Parse(typeof(PositiveFormat), (string)f.Attribute("positiveFormat")); var negativeFormat = (NegativeFormat)Enum.Parse(typeof(NegativeFormat), (string)f.Attribute("negativeFormat")); var currencySymbol = (string)f.Attribute("symbol"); var format = new CurrencyFormat(decimalDigits, decimalSeparator, groupSeparator, groupSizes, currencySymbol, positiveFormat, negativeFormat); var securityId = (Guid)s.Attribute("id"); var securityType = (SecurityType)Enum.Parse(typeof(SecurityType), (string)s.Attribute("type")); var name = (string)s.Attribute("name"); var symbol = (string)s.Attribute("symbol"); var fractionTraded = (int)s.Attribute("fractionTraded"); 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) { Date = date, }; foreach (var s in t.Elements("Split")) { var split = transaction.AddSplit(); var accountId = (Guid)s.Attribute("accountId"); var account = accounts[accountId]; split.Account = account; var splitSecurityId = (Guid?)s.Attribute("securityId"); var splitSecurity = securities[splitSecurityId ?? securityId]; split.Security = splitSecurity; var amount = (long)s.Attribute("amount"); split.Amount = amount; var transactionAmount = (long?)s.Attribute("transactionAmount"); split.TransactionAmount = splitSecurity != security ? transactionAmount.Value : transactionAmount ?? amount; var dateCleared = (DateTime?)s.Attribute("dateCleared"); split.DateCleared = dateCleared; var reconciled = (bool)s.Attribute("reconciled"); split.IsReconciled = reconciled; } 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); }
public Calculate(QuoteViewModel quoteData, PriceQuote prices) { _quoteData = quoteData; _prices = prices; }
public PriceQuoteFulfilled(PriceQuote priceQuote) { PriceQuote = priceQuote; }
protected override Book Load(Uri uri) { var book = new Book(); var doc = XDocument.Load(uri.ToString()); var securities = new Dictionary<Guid, Security>(); var accounts = new Dictionary<Guid, Account>(); foreach (var s in doc.Element("Book").Element("Securities").Elements("Security")) { var f = s.Element("Format"); var decimalDigits = (int)f.Attribute("decimalDigits"); var decimalSeparator = (string)f.Attribute("decimalSeparator"); var groupSeparator = (string)f.Attribute("groupSeparator"); var groupSizes = ((string)f.Attribute("groupSizes")).Split(',').Select(g => int.Parse(g.Trim())); var positiveFormat = (PositiveFormat)Enum.Parse(typeof(PositiveFormat), (string)f.Attribute("positiveFormat")); var negativeFormat = (NegativeFormat)Enum.Parse(typeof(NegativeFormat), (string)f.Attribute("negativeFormat")); var currencySymbol = (string)f.Attribute("symbol"); var format = new CurrencyFormat(decimalDigits, decimalSeparator, groupSeparator, groupSizes, currencySymbol, positiveFormat, negativeFormat); var securityId = (Guid)s.Attribute("id"); var securityType = (SecurityType)Enum.Parse(typeof(SecurityType), (string)s.Attribute("type")); var name = (string)s.Attribute("name"); var symbol = (string)s.Attribute("symbol"); var fractionTraded = (int)s.Attribute("fractionTraded"); 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; }