public void GetInvoiceObjct_MoreExpressive_Test() { // Arrange var expected = new List <InvoiceItem> { new InvoiceItem(1, "IPad", 20.00d), new InvoiceItem(2, "Stand for IPad", 15.00d), new InvoiceItem(3, "LapTop Asus", 505.00d) }.ToList(); // Act Invoice invoice = new InvoiceBuilder().WithInvoiceLines(); var resultTypeTest = invoice.GetInvoiceItems(); var resultValues = resultTypeTest.InvoiceList.ToList(); // Assert Assert.IsInstanceOf <InvoiceLines>(resultTypeTest); Assert.That(expected, DeepObj.DeepEqualTo(resultValues)); //AssertHelper.HasEqualFieldValues(expected, resultValues); //Assert.IsInstanceOf<List<InvoiceItem>>(lines); //Assert.That(expected, Is.EqualTo(lines)); //Assert.That("Hello", Is.TypeOf(typeof(string))); //Assert.That("Hello", Is.Not.TypeOf(typeof(int))); //Assert.That(invoice.lines, Is.EqualTo(expected)); //Assert.That(new[] { 1.05, 2.05, 3.05 }, Is.EquivalentTo(new[] { 3.0, 2.0, 1.0 })); }
private void btnInvoice_Click(object sender, EventArgs e) { if(lvItems.Items.Count <= 0) return; if (_order.Customer == null) SelectCustomer(); if (_order.Customer == null) return; var items = lvItems.Items.OfType<ListViewItem>() .Select(lvi => lvi.Tag as OrderItem) .ToList(); var invoice = InvoiceBuilder.Create(FinancialHandler.GenerateInvoiceNumber(), CreateInvoice(items), _order.Customer); invoice.Total = items.Select(oi => oi.CalculateTotal()) .DefaultIfEmpty(0) .Sum(); var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var path = Path.Combine(desktopPath, $"Factura-{invoice.Number}.pdf"); var pdfWriter = new PdfWriter(path); pdfWriter.Write(invoice.ToString()); pdfWriter.Save(); Process.Start(path); }
public void SimpleTestDataBuilder() { var invoice = new InvoiceBuilder() .With(new RecipientBuilder() .With(customerName: "Sherlock Holmes") .With(new AddressBuilder() .With(firstLine: "221b Baker Street", city: "London") .With(new PostCodeBuilder() .With(outwardCode: "NW1", inwardCode: "3RX") .Build()) .Build()) .Build()) .With(new List <InvoiceLine> { new InvoiceLineBuilder() .With(product: "Deerstalker Hat") .With(new PoundsShillingsPenceBuilder() .With(pounds: 0, shillings: 3, pence: 10) .Build()) .Build(), new InvoiceLineBuilder() .With(product: "Tweed Cape") .With(new PoundsShillingsPenceBuilder() .With(pounds: 0, shillings: 4, pence: 12) .Build()) .Build(), }) .Build(); }
public static IActionResult Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var invoiceBuilder = new InvoiceBuilder { Init = () => { }, GetRequestStream = () => new MemoryStream(Properties.Resources.Request), GetTemplateStream = (template) => new MemoryStream(Properties.Resources.Invoice), Output = (pdf) => { using (var stream = new MemoryStream()) { stream.Write(pdf, 0, pdf.Length); } } }; invoiceBuilder.Build(); return(new OkObjectResult(invoiceBuilder.ToString())); }
public void TestInvoices() { var departmentA = new DepartmentBuilder(this.Session).Build(); var departmentB = new DepartmentBuilder(this.Session).Build(); var accountantA = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("A").Build(); var accountantB = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("B").Build(); departmentA.AddAccountant(accountantA); departmentB.AddAccountant(accountantB); var invoiceA = new InvoiceBuilder(this.Session).Build(); var invoiceB = new InvoiceBuilder(this.Session).Build(); departmentA.AddInvoice(invoiceA); departmentB.AddInvoice(invoiceB); this.Session.Derive(); // Accountant A var aclAccountatAInvoiceA = new AccessControlList(invoiceA, accountantA); var aclAccountatAInvoiceB = new AccessControlList(invoiceB, accountantA); aclAccountatAInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); aclAccountatAInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); // Accountant B var aclAccountatBInvoiceA = new AccessControlList(invoiceA, accountantB); var aclAccountatBInvoiceB = new AccessControlList(invoiceB, accountantB); aclAccountatBInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); aclAccountatBInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); }
public void TestEmployeesCanRead() { var employeeRole = new Roles(this.Session).Employee; var employees = new UserGroupBuilder(this.Session) .WithName("Employees") .Build(); var john = new PersonBuilder(this.Session).WithFirstName("John").WithLastName("Doe").Build(); employees.AddMember(john); var invoice = new InvoiceBuilder(this.Session).Build(); var singleton = Singleton.Instance(this.Session); var defaultSecurityToken = singleton.DefaultSecurityToken; var accessControl = new AccessControlBuilder(this.Session) .WithRole(employeeRole) .WithObject(defaultSecurityToken) .WithSubjectGroup(employees) .Build(); var acl = new AccessControlList(invoice, john); acl.CanRead(Invoice.Meta.Total).ShouldBeTrue(); }
public void constructDocument(InvoiceBuilder invoiceBuilder, Order order, List <ProductDecorator> shoppingCartDecoratorsList, List <Product> shoppingCartList) { invoiceBuilder.AddReceiptTitle(); invoiceBuilder.AddSellerInfo(); invoiceBuilder.AddDate(); invoiceBuilder.AddPrice(order.Price); invoiceBuilder.AddProductsInfo(shoppingCartList.ToList(), shoppingCartDecoratorsList); }
public void constructDocument(InvoiceBuilder invoiceBuilder, Order order, List <ProductDecorator> shoppingCartDecoratorsList, List <Product> shoppingCartList) { invoiceBuilder.AddInvoiceTitle(); invoiceBuilder.AddSellerInfo(); invoiceBuilder.AddDate(); invoiceBuilder.AddCustomerInfo(order.Customer); invoiceBuilder.AddPrice(order.Price); invoiceBuilder.AddPaymentMethodInfo(order.PaymentMethod); invoiceBuilder.AddShippingMethodInfo(order.ShippingMethod); invoiceBuilder.AddProductsInfo(shoppingCartList.ToList(), shoppingCartDecoratorsList); }
public InvoiceForm(int patID, bool isPatID) { InitializeComponent(); cbStatus.SelectedIndex = 0; m_invBuilder = new InvoiceBuilder(); m_currentInvoice = m_invBuilder.Invoice; selectPatient(patID); }
public void build_invoice_with_nested_builders() { Invoice invoice = InvoiceBuilder.AnInvoice() .WithRecipient(RecipientBuilder.ARecipient().WithAddress(AddressBuilder.AnAddress().WithCity("London"))) .WithInvoiceLines(InvoiceLineBuilder.AnInvoiceLine().WithProduct("Boots"), InvoiceLineBuilder.AnInvoiceLine().WithProduct("Cape")) .Build(); Assert.That(invoice.recipient.address.city, Is.EqualTo("London")); Assert.That(invoice.lines.invoiceLines[1].product, Is.EqualTo("Cape")); }
public void build_invoice_with_no_postcode() { Invoice invoiceWithNoPostcode = InvoiceBuilder.AnInvoice() .WithRecipient(new RecipientBuilder() .WithAddress(new AddressBuilder() .WithNoPostcode() .Build()) .Build()) .Build(); Assert.That(invoiceWithNoPostcode.recipient.address.postCode, Is.Null); }
private void CompleteButton_Click(object sender, RoutedEventArgs e) { InvoiceBuilder invoiceBuilder = new InvoiceBuilder(); mainViewModel.saveCustomerProfiles(); mainViewModel.saveInvoiceNumber(); if (invoiceBuilder.build(mainViewModel)) { Close(); } }
public void ToDomain() { // Arrange var updateInvoice = new UpdateInvoiceBuilder().Build(); var expected = new InvoiceBuilder().Build(); // Act var actual = testSubject.ToDomain(updateInvoice, expected.Id); // Assert actual.ShouldBeEquivalentTo(expected); }
public void ToModel() { // Arrange var domainInvoice = new InvoiceBuilder().Build(); var expected = new Builders.Models.GetMinimalInvoiceBuilder().Build(); // Act var actual = testSubject.ToModel(domainInvoice); // Assert expected.ShouldBeEquivalentTo(actual); }
public void ToModel() { // Arrange var invoice = new InvoiceBuilder().Build(); var expected = new UpdateInvoiceBuilder().Build(); // Act var actual = testSubject.ToModel(invoice); // Assert actual.ShouldBeEquivalentTo(expected); }
public void InvoiceBuilderTest() { Staff saleRep = new Staff("QAD0001", "Shuayb", JobRole.Sale); Order order = Setup(); InvoiceBuilder iBuild = new InvoiceBuilder(); iBuild.Order = order; iBuild.Staff = saleRep; Sale sInvoice = iBuild.Prepare() as Sale; Assert.Fail(); }
public virtual ActionResult Download() { var rentalResult = Session["LastOrderResult"] as RentalResult; if (rentalResult == null) { return(RedirectToAction(MVC.Home.Index())); } var invoice = InvoiceBuilder.Build(CurrentUser, rentalResult); var content = Encoding.UTF8.GetBytes(invoice); return(File(content, "text/plain", "invoice.txt")); }
public void AddInvoicesToCustomer(int customerId, int numOfInvoices, ISession session) { var rand = new Random(); var builder = new InvoiceBuilder(1, 1, 1).AddAmountProvider(() => rand.NextDouble() * 100); using (ITransaction transaction = session.BeginTransaction()) { for (int i = 0; i < numOfInvoices; i++) { var obj = builder.Construct(); session.SaveOrUpdate(obj); } transaction.Commit(); } }
public void Statement_unknown_playtype_should_throw_exception() { const string invalidPlayId = "invalid"; var plays = new PlaysBuilder() .WithPlay(invalidPlayId, (PlayType)99) .Build(); var invoice = new InvoiceBuilder() .WithPerformance(invalidPlayId, 1) .Build(); var generator = new BillGenerator(); Action act = () => generator.Statement(invoice, plays); act.Should().Throw <Exception>().WithMessage("unknown type: 99"); }
public void Patch_should_return_NoContent() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); var updateInvoice = new UpdateInvoiceBuilder().Build(); updateInvoiceMapperMock.Setup(mapper => mapper.ToModel(invoice)).Returns((updateInvoice)); // Act var response = testSubject.Patch(Id, new JsonPatchDocument <UpdateInvoice>()); // Assert Assert.IsType <NoContentResult>(response); }
public void Post_should_return_created_response() { // Arrange var invoice = new UpdateInvoiceBuilder().Build(); var domainInvoice = new InvoiceBuilder().Build(); var getInvoice = new GetInvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Create(It.IsAny <Domain.Invoice>())).Returns(domainInvoice); getInvoiceMapperMock.Setup(mapper => mapper.ToModel(domainInvoice)).Returns(getInvoice); // Act var response = testSubject.Post(invoice); // Assert Assert.IsType <CreatedAtRouteResult>(response); }
public IList <Invoice> DeSerialize(string filename) { XDocument doc = XDocument.Load(filename); List <Invoice> listOfInvoices = new List <Invoice>(); var root = doc.Root; var ib = new InvoiceBuilder(); var sheets = root.Descendants() .Where(c => c.HasAttributes) .Where(c => c.FirstAttribute.ToString().Contains("Sheet")) .ToList(); var pattern = new Regex(@"Invoice (?<number>\d*)\s?Invoice date: (?<date>\d\d/\d\d/\d{4}) Type: (?<type>\w*) Payment due by: (?<date2>\d\d/\d\d/\d{4}) Sum: (?<price>\d*\.?\d*) Creditor Debtor Creditor name: (?<cn>[\w\s]*) Debtor name: (?<dn>[\w\s]*) Creditor address: (?<ca>[\w\s,]*) Debtor address: (?<da>[\w\s,]*) Creditor zip: (?<cz>\w*) Debtor zip: (?<dz>\w*)"); var pattern2 = new Regex(@"name: (?<name>\w*) cost: (?<cost>\d*\.?\d*)"); foreach (var sheet in sheets) { if (sheet.Value != "") { var dataToParse = sheet.Value; var match = pattern.Matches(dataToParse); var subMatch = pattern2.Matches(dataToParse); var type = match[0].Groups["type"].ToString() == "DEBT" ? InvoiceType.DEBT : InvoiceType.CREDIT; List <InvoiceItem> items = new List <InvoiceItem>(); foreach (Match item in subMatch) { items.Add(new InvoiceItem(System.Convert.ToDecimal(item.Groups["cost"].ToString()), item.Groups["name"].ToString())); } var invoice = ib.SetInvoiceNumber(match[0].Groups["number"].ToString()) .SetInvoiceType(type) .SetCreditor(new Person(match[0].Groups["cn"].ToString(), match[0].Groups["ca"].ToString(), match[0].Groups["cz"].ToString())) .SetDebtor(new Person(match[0].Groups["dn"].ToString(), match[0].Groups["da"].ToString(), match[0].Groups["dz"].ToString())) .SetInvoiceDate(DateTime.ParseExact(match[0].Groups["date"].ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)) .SetMaturityDate(DateTime.ParseExact(match[0].Groups["date2"].ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)) .SetInvoicedItems(items) .Build(); listOfInvoices.Add(invoice); } } return(listOfInvoices); }
public void Patch_should_return_PreconditionFailed_When_Etag_Is_Wrong() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); testSubject.Request.Headers.Add(HeaderNames.IfMatch, $"\"unknown\""); var updateInvoice = new UpdateInvoiceBuilder().Build(); updateInvoiceMapperMock.Setup(mapper => mapper.ToModel(invoice)).Returns((updateInvoice)); // Act var response = testSubject.Patch(Id, new JsonPatchDocument <UpdateInvoice>()); // Assert Assert.Equal(StatusCodes.Status412PreconditionFailed, ((StatusCodeResult)response).StatusCode); }
public void Post_should_return_ETag() { // Arrange var invoice = new UpdateInvoiceBuilder().Build(); var domainInvoice = new InvoiceBuilder().Build(); var getInvoice = new GetInvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Create(It.IsAny <Domain.Invoice>())).Returns(domainInvoice); getInvoiceMapperMock.Setup(mapper => mapper.ToModel(domainInvoice)).Returns(getInvoice); // Act testSubject.Post(invoice); // Assert var headers = testSubject.Response.GetTypedHeaders(); Assert.NotNull(headers.ETag); }
public void Get_should_return_NotModified_when_ETag_match_current_version() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); var expected = new GetInvoiceBuilder().Build(); getInvoiceMapperMock.Setup(map => map.ToModel(invoice)).Returns(expected); testSubject.Request.Headers.Add(HeaderNames.IfNoneMatch, $"\"{Guid.Empty}\""); // Act var response = testSubject.Get(Id) as StatusCodeResult; // Assert Assert.Equal(StatusCodes.Status304NotModified, response.StatusCode); }
public void Get_should_have_ETag_header() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); var expected = new GetInvoiceBuilder().Build(); getInvoiceMapperMock.Setup(map => map.ToModel(invoice)).Returns(expected); // Act testSubject.Get(Id); // Assert var headers = testSubject.Response.GetTypedHeaders(); Assert.NotNull(headers.ETag); }
public void Get_should_return_invoice() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); var expected = new GetInvoiceBuilder().Build(); getInvoiceMapperMock.Setup(map => map.ToModel(invoice)).Returns(expected); // Act var response = testSubject.Get(Id) as ObjectResult; // Assert Assert.IsType <GetInvoice>(response.Value); Assert.Equal((int)HttpStatusCode.OK, response.StatusCode.Value); Assert.Equal(expected, response.Value); }
public void Patch_should_return_ETag() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); invoiceRepositoryMock.Setup(r => r.Update(It.IsAny <Domain.Invoice>())).Returns(new Version("2")); var updateInvoice = new UpdateInvoiceBuilder().Build(); updateInvoiceMapperMock.Setup(mapper => mapper.ToModel(invoice)).Returns((updateInvoice)); // Act testSubject.Patch(Id, new JsonPatchDocument <UpdateInvoice>()); // Assert var headers = testSubject.Response.GetTypedHeaders(); Assert.NotNull(headers.ETag); }
public void Patch_should_return_NoContent_When_Etag_Is_Wildcard() { // Arrange var invoice = new InvoiceBuilder().Build(); invoiceRepositoryMock.Setup(r => r.Get(Id)).Returns(invoice); invoiceRepositoryMock.Setup(r => r.Update(It.IsAny <Domain.Invoice>())).Returns(new Version("2")); var updateInvoice = new UpdateInvoiceBuilder().Build(); updateInvoiceMapperMock.Setup(mapper => mapper.ToModel(invoice)).Returns((updateInvoice)); testSubject.Request.Headers.Add(HeaderNames.IfMatch, EntityTagHeaderValue.Any.Tag); // Act var response = testSubject.Patch(Id, new JsonPatchDocument <UpdateInvoice>()); // Assert Assert.IsType <NoContentResult>(response); }
private static InvoiceBuilder Build(int number) { System.Console.WriteLine($"Build No.{number}"); var invoiceBuilder = new InvoiceBuilder { Init = () => { }, GetRequestStream = () => new MemoryStream(Properties.Resources.Request), GetTemplateStream = (template) => new MemoryStream(Properties.Resources.Invoice), Output = (pdf) => { using (var stream = new MemoryStream()) { stream.Write(pdf, 0, pdf.Length); } } }; invoiceBuilder.Build(); return(invoiceBuilder); }
public async Task CreateAsync() { var clientId = await GetClientIdAsync(); var items = new List <InvoiceItemBase> { new InvoiceItem { Description = "Teszt termék (Próba)", Gross_unit_price = 1000, Qty = 2, Unit = "db", Vat_id = 1, }, }; var invoice = new InvoiceBuilder().SetDefaults(1, clientId, 0, items).SetElectronicInvoice(false).Build(); var createdInvoice = await invoicesRepository.CreateAsync(invoice); Assert.False(invoice.Is_paid); }
/// <summary> /// Process the payment and produces a tax invoice /// </summary> public string CreatePayment(CreditCard card) { if (_customer == null || _sInvoice == null) { return("Need to declare payment parameters!"); } string lResult = ""; PaymentProcessor pProcessor = new PaymentProcessor(); lResult = pProcessor.SetPaymentDetail(card); if (lResult != "VALID") { return("Payment details are not vaild."); } string paymentId = pProcessor.Pay(_sInvoice.TotalCost); if (paymentId == "ERROR") { return("An error occoured with the payment system. Unknown!."); } InvoiceBuilder iBuild = new InvoiceBuilder(); iBuild.Invoice = InvoiceType.Tax; iBuild.SaleInvoice = _sInvoice; iBuild.Customer = _customer; iBuild.PaymentId = paymentId; _tInvoice = iBuild.Prepare() as Tax; UpdateVehicleInventoryState(); string msg = _manager["Invoice"].Update(_tInvoice); if (msg != "Successfully updated.") { return(msg); } return("Payment Success."); }
public InvoiceForm(int invID) { InitializeComponent(); // Constuct invoice builder with premade invoice m_invBuilder = new InvoiceBuilder(invID); m_currentInvoice = m_invBuilder.Invoice; // Set binding source invoiceBindingSource.DataSource = m_currentInvoice; dtpBillDate.Value = m_currentInvoice.invDate; cbStatus.SelectedIndex = (m_currentInvoice.invStatus != null) ? (int)m_currentInvoice.invStatus : 0; selectPatient(m_currentInvoice.patID); // Read only mode since this invoice is already saved m_bIsUpdate = true; tsbDelete.Enabled = true; tsbSavePDF.Enabled = true; tsbStatement.Enabled = true; populateDataGrid(); }
public static async Task Run( [EventGridTrigger] EventGridEvent eventGridEvent, [Blob("{data.url}", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input, [Queue("diodocsqueue"), StorageAccount("AzureWebJobsStorage")] ICollector <string> msg, ILogger log) { var createdEvent = ((JObject)eventGridEvent.Data).ToObject <StorageBlobCreatedEventData>(); CloudBlobClient blobClient = null; var invoiceBuilder = new InvoiceBuilder { Init = () => { var storageAccount = CloudStorageAccount.Parse(BlobStorageConnectionString); blobClient = storageAccount.CreateCloudBlobClient(); }, GetRequestStream = () => input, GetTemplateStream = (template) => { var container = blobClient.GetContainerReference("excel"); var blockBlob = container.GetBlockBlobReference(template); return(blockBlob.OpenReadAsync().GetAwaiter().GetResult()); }, Output = (pdf) => { var container = blobClient.GetContainerReference("pdf"); var uri = new Uri(createdEvent.Url); var cloudBlob = new CloudBlob(uri); var blobName = cloudBlob.Name; var blockBlob = container.GetBlockBlobReference(blobName + ".pdf"); blockBlob.UploadFromByteArrayAsync(pdf, 0, pdf.Length).GetAwaiter().GetResult(); } }; invoiceBuilder.Build(); msg.Add($"Completed. {invoiceBuilder}"); }
public InvoiceForm() { InitializeComponent(); cbStatus.SelectedIndex = 0; m_invBuilder = new InvoiceBuilder(); }