public void FunctionalTest() { var invoice = new Invoice(); invoice.AddLine(new InvoiceLine { Formula = "Energy", UnitPrice = 1, Volume = 2 }); invoice.AddLine(new InvoiceLine { Formula = "Distribution", UnitPrice = 2, Volume = 3 }); invoice.AddLine(new InvoiceLine { Formula = "Metering", UnitPrice = 1, Volume = 3 }); var draftException = Assert.Throws <InvoiceStateException>(() => invoice.CalculateTotalAmount()); Assert.IsTrue(draftException.Message.Contains("draft", System.StringComparison.OrdinalIgnoreCase)); invoice.ChangeState(new GeneratedState()); Assert.AreEqual(11, invoice.CalculateTotalAmount()); invoice.ChangeState(new CreditNoteState()); Assert.AreEqual(-11, invoice.CalculateTotalAmount()); invoice.ChangeState(new ErrorState()); var errorException = Assert.Throws <InvoiceStateException>(() => invoice.CalculateTotalAmount()); Assert.IsTrue(errorException.Message.Contains("error", System.StringComparison.OrdinalIgnoreCase)); }
static void Main(string[] args) { Console.WriteLine("Create invoice"); var invoice = new Invoice(); invoice.AddLine(new InvoiceLine { Formula = "Energy", UnitPrice = 33, Volume = 350 }); invoice.AddLine(new InvoiceLine { Formula = "Distribution", UnitPrice = 7, Volume = 380 }); invoice.AddLine(new InvoiceLine { Formula = "Metering", UnitPrice = 3, Volume = 350 }); decimal total; try { total = invoice.CalculateTotalAmount(); } catch (Exception exc) { var s = exc.Message; } invoice.ChangeState(new GeneratedState()); total = invoice.CalculateTotalAmount(); invoice.ChangeState(new CreditNoteState()); total = invoice.CalculateTotalAmount(); invoice.ChangeState(new ErrorState()); try { total = invoice.CalculateTotalAmount(); } catch (Exception exc) { var s = exc.Message; } }
public void ShouldSetPathToTotalAmount() { InvoiceService invoiceService = new InvoiceService(new CalculationService(), new ExcelFileService()); var invoice = new Invoice(); invoice.AddLine(new InvoiceLine { Formula = "Energy", UnitPrice = 1, Volume = 2 }); invoice.AddLine(new InvoiceLine { Formula = "Distribution", UnitPrice = 2, Volume = 3 }); invoice.AddLine(new InvoiceLine { Formula = "Metering", UnitPrice = 1, Volume = 4 }); invoiceService.GenerateInvoice(invoice); Assert.AreEqual("12.xlsx", invoice.FilePath); }
public void FunctionalTest() { var invoice = new Invoice(); invoice.AddLine(new InvoiceLine { Formula = "Energy", UnitPrice = 1, Volume = 2 }); invoice.AddLine(new InvoiceLine { Formula = "Distribution", UnitPrice = 2, Volume = 3 }); invoice.AddLine(new InvoiceLine { Formula = "Metering", UnitPrice = 1, Volume = 4 }); Assert.AreEqual(12, invoice.CalculateTotalAmount()); Assert.AreEqual(-12, new CreditNoteInvoiceDecorator(invoice).CalculateTotalAmount()); Assert.AreEqual(18, new VatInvoiceDecorator(invoice, 50).CalculateTotalAmount()); Assert.AreEqual(-18, new CreditNoteInvoiceDecorator(new VatInvoiceDecorator(invoice, 50)).CalculateTotalAmount()); }
private int CreateNewInvoice() { int id; using (ISession session = sessions.OpenSession()) using (ITransaction tx = session.BeginTransaction()) { var invoice = new Invoice(); invoice.AddLine(new InvoiceLine()); id = (int)session.Save(invoice); tx.Commit(); } return(id); }
//Prefer to have factory here. Followed by DDD rules about domain service definition. //Should be used when one aggregate is being transformed to another one. public Invoice CreateInvoice(Order order, ITaxPolicy taxPolicy) { Invoice invoice = new Invoice(order.Customer); foreach (var orderLine in order.OrderLines) { Tax tax = taxPolicy.CalculateTax(orderLine.Product, orderLine.TotalEffectivePrice); InvoiceLine line = new InvoiceLine(orderLine.Product, orderLine.Quantity, orderLine.TotalEffectivePrice, tax); invoice.AddLine(line); } return(invoice); }
public void CalculateTaxes() { Stock stock = new Stock(); Product product = stock.GetProductWithCode("x1abc3t3c"); Line line = new Line(); int quantity = 10; line.AddProducts(product, quantity); Invoice invoice = new Invoice(new TaxManager()); invoice.AddLine(line); float total = invoice.GetTotal(); Assert.IsTrue(quantity * product.Price < total); }
private static Invoice GetInvoice(dynamic json) { if (json is JArray) { return(null); } var address = new InvoiceAddress((string)json.address_1, (string)json.address_2, (string)json.address_3, (string)json.address_4, (string)json.address_5, (string)json.address_6); var invoice = new Invoice((DateTime)json.date, (string)json.number, (decimal)json.total, (decimal)json.tax, (string)json.pdf_url, address); foreach (var iL in json.invoice_lines) { var invoiceLine = new InvoiceLine((int)iL.quantity, (string)iL.details, (decimal)iL.unit_price, (decimal)iL.subtotal); invoice.AddLine(invoiceLine); } return(invoice); }
static async Task Connect() { Console.WriteLine("FactuurSturen.nl API Test Client"); var credentials = GetCredentials(); Console.WriteLine("Connecting..."); var client = new FactuurSturenClient(); await client.LoginAsync(credentials.UserName, credentials.Password); Console.WriteLine("Connected."); //var invoices = await client.GetInvoices(); var taxes = await client.GetTaxes(); var mybytes = await client.GetInvoicePdf("20150003"); var tax = await client.GetTaxType(TaxRates.H); var taxRate = tax.Percentage; var to = await client.GetClient("My client name"); // can also be via Id var invoice = new Invoice(to, InvoiceActions.Send, SendMethods.Email); var line1 = new InvoiceLine(1, "Test line", taxRate, price: 125); invoice.AddLine(line1); await client.CreateInvoice(invoice, true); //var products = await client.GetProducts(); //var product = await client.GetProduct(1); //var retval = await client.CreateProduct(product); //await client.DeleteProduct(product); //var invoice = await client.GetInvoice("20160086"); }