public async void InsertReceipt() { Receipt receipt = new Receipt(); receipt.Date = DateTime.Now; receipt.UserId = 1; ReceiptEntry entry = new ReceiptEntry(); entry.Amount = 30m; receipt.Entries = new List <ReceiptEntry>(); receipt.Entries.Add(entry); using (IBudgetDatabase database = new BudgetDatabase()) { ReceiptRepository repository = new ReceiptRepository(database); await repository.Save(receipt); } Assert.AreNotEqual(0, receipt.Id); Assert.AreNotEqual(0, entry.Id); Assert.AreEqual(receipt.Id, entry.ReceiptId); }
public async void PostReceipt() { ReceiptClient client = this.CreateClient(); Receipt receipt = new Receipt(); receipt.Date = DateTime.Now; receipt.UserId = 1; ReceiptEntry entry = new ReceiptEntry(); entry.Amount = 30m; receipt.Entries = new List <ReceiptEntry> { entry }; Receipt saved = await client.Save(receipt); }
public async Task <Receipt> CalculateAsync(ShoppingCart cart) { if (cart.Items.Count == 0) { throw new InvalidOperationException("Cannot create a receipt for an empty cart."); } var receiptEntries = new List <ReceiptEntry>(cart.Items.Count); foreach (var cartItem in cart.Items) { var item = await this.itemsRepository.GetByIdAsync(cartItem.ItemId); var totalCost = await this.taxCalculator.CalculateTaxAsync(item, cartItem.Count); var entry = new ReceiptEntry(item, cartItem.Count, item.Price * cartItem.Count, totalCost); receiptEntries.Add(entry); } var subtotal = receiptEntries.Sum(x => x.Subtotal); var total = receiptEntries.Sum(x => x.Total); return(new Receipt(receiptEntries.AsReadOnly(), subtotal, total)); }
/// <summary> /// Determines whether the specified object is equal to the current object. Implementation courtesy of Resharper /// </summary> /// <param name="other"></param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> private bool Equals(ReceiptEntry other) { return Quantity == other.Quantity && string.Equals(ItemDescription, other.ItemDescription) && UnitPrice == other.UnitPrice && TotalPrice == other.TotalPrice && Promotion == other.Promotion; }
/// <summary> /// Determines whether the specified object is equal to the current object. Implementation courtesy of Resharper /// </summary> /// <param name="other"></param> /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns> private bool Equals(ReceiptEntry other) { return(Quantity == other.Quantity && string.Equals(ItemDescription, other.ItemDescription) && UnitPrice == other.UnitPrice && TotalPrice == other.TotalPrice && Promotion == other.Promotion); }