public void Adding_BillItem_To_BIll() { var date = new DateTime(2017, 6, 19); var billItems = ListOfBillItems.Create(); var projectId = Guid.NewGuid().ToString(); var storeHouseItemAId = Guid.NewGuid().ToString(); var storehuseItemAQuantity = 15; var billItemA = BillItem.Create(5, 2.5M, storeHouseItemAId, storehuseItemAQuantity); var storeHouseItemBId = Guid.NewGuid().ToString(); var storehuseItemBQuantity = 15; var billItemB = BillItem.Create(4, 2.5M, storeHouseItemBId, storehuseItemBQuantity); var bill = Bill.Create(date, billItems, projectId); Assert.True(bill.GetBillItems().Count() == 0); bill.AddBillItem(billItemA); Assert.True(bill.GetBillItems().Count() == 1); bill.AddBillItem(billItemB); Assert.True(bill.GetBillItems().Count() == 2); bill.AddBillItem(billItemA); Assert.True(bill.GetBillItems().Count() == 2); }
public ListOfBillItems AddBilledItems(Bill bill) { var billedItems = bill.GetBillItems(); billedItems.AddRange(bill.GetBillItems()); return(ListOfBillItems.Create(billedItems)); }
public ListOfBillItems GetBillItems() { if (string.IsNullOrEmpty(this.BillItems)) { return(ListOfBillItems.Create()); } return((ListOfBillItems)this.BillItems); }
public static Bill Create(DateTime date, ListOfBillItems billItems, string projectId) { return(new Bill() { Date = date, RevisionDate = date, BillItems = billItems, Amount = CalculateAmount(billItems), ProjectId = projectId, HasInvoice = false }); }
public void Create_Valid_Bill() { var date = new DateTime(2017, 6, 22); var projectId = Guid.NewGuid().ToString(); var billItems = ListOfBillItems.Create(); var bill = Bill.Create(date, billItems, projectId); Assert.NotNull(bill); Assert.NotNull(bill.BillItems); Assert.True(bill.Date.Equals(date)); Assert.True(bill.ProjectId.Equals(projectId)); Assert.False(bill.HasInvoice); }
public void Attache_Invoice_to_Bill() { var date = new DateTime(2017, 6, 19); var billItems = ListOfBillItems.Create(); var projectId = Guid.NewGuid().ToString(); var invoiceId = Guid.NewGuid().ToString(); var otherInviceId = Guid.NewGuid().ToString(); var bill = Bill.Create(date, billItems, projectId); bill.AttachInvoice(invoiceId); Assert.NotNull(bill.InvoiceId); Assert.True(bill.HasInvoice); Assert.Throws <InvalidOperationException>(() => bill.AttachInvoice(otherInviceId)); }
public void Revise(DateTime revisionDate, ListOfBillItems billItems) { if (this.HasInvoice) { throw new InvalidOperationException("Invoice has been issued and the bill can not be changed."); } if (this.Date > revisionDate) { throw new ArgumentOutOfRangeException("revisionDate", "Revision date can't be prior then the creation date."); } if (this.RevisionDate > revisionDate) { throw new ArgumentOutOfRangeException("revisionDate", "Revision date can't be prior then the last revision date."); } this.RevisionDate = revisionDate; this.BillItems = billItems; this.Amount = CalculateAmount(billItems); }
public void Revise_Bill() { var date = new DateTime(2017, 6, 19); var revisionDate = new DateTime(2017, 6, 22); var billItems = ListOfBillItems.Create(); var projectId = Guid.NewGuid().ToString(); var storeHouseItemId = Guid.NewGuid().ToString(); var storehuseItemQuantity = 6; var billItem = BillItem.Create(5, 2.5M, storeHouseItemId, storehuseItemQuantity); var revisedBillItem = BillItem.Create(4, 2.5M, storeHouseItemId, storehuseItemQuantity); var items = new List <BillItem> { billItem }; var revisedItems = new List <BillItem> { revisedBillItem }; var bill = Bill.Create(date, billItems, projectId); bill.Revise(revisionDate, ListOfBillItems.Create(revisedItems)); Assert.NotNull(bill); Assert.NotNull(bill.BillItems); Assert.True(bill.GetBillItems().Count() == 1); Assert.True(bill.GetBillItems().First().Quantity == revisedBillItem.Quantity); Assert.True(bill.RevisionDate.Equals(revisionDate)); var revisonDatePriorTheDate = date.AddDays(-5); Assert.Throws <ArgumentOutOfRangeException>(() => bill.Revise(revisonDatePriorTheDate, ListOfBillItems.Create(revisedItems))); var revisonDatePriorTheLastRevisionDate = bill.RevisionDate.AddDays(-1); Assert.Throws <ArgumentOutOfRangeException>(() => bill.Revise(revisonDatePriorTheLastRevisionDate, ListOfBillItems.Create(revisedItems))); bill.AttachInvoice(Guid.NewGuid().ToString()); Assert.Throws <InvalidOperationException>(() => bill.Revise(revisionDate, ListOfBillItems.Create(revisedItems))); }
private static decimal CalculateAmount(ListOfBillItems billItems) { return(billItems.Sum(i => i.Price * i.Quantity)); }