Exemple #1
0
        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);
        }
Exemple #2
0
        public ListOfBillItems AddBilledItems(Bill bill)
        {
            var billedItems = bill.GetBillItems();

            billedItems.AddRange(bill.GetBillItems());

            return(ListOfBillItems.Create(billedItems));
        }
Exemple #3
0
        public ListOfBillItems GetBillItems()
        {
            if (string.IsNullOrEmpty(this.BillItems))
            {
                return(ListOfBillItems.Create());
            }

            return((ListOfBillItems)this.BillItems);
        }
Exemple #4
0
 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
     });
 }
Exemple #5
0
        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);
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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)));
        }
Exemple #9
0
 private static decimal CalculateAmount(ListOfBillItems billItems)
 {
     return(billItems.Sum(i => i.Price * i.Quantity));
 }