Beispiel #1
0
        public void SetUp()
        {
            var taxCalculator = new TaxCalculator();
            var receiptBuilder = new ReceiptBuilder();

            _shoppingBasket = new ShoppingBasket(taxCalculator, receiptBuilder);
        }
Beispiel #2
0
        public void Can_do_roundtrip_storage([Values(true, false)] bool encodeWithTxHash, [Values(RlpBehaviors.Storage | RlpBehaviors.Eip658Receipts, RlpBehaviors.Storage)] RlpBehaviors encodeBehaviors, [Values(true, false)] bool withError, [Values(true, false)] bool valueDecoder)
        {
            TxReceipt GetExpected()
            {
                ReceiptBuilder receiptBuilder = Build.A.Receipt.WithAllFieldsFilled;

                if ((encodeBehaviors & RlpBehaviors.Eip658Receipts) != 0)
                {
                    receiptBuilder.WithState(null);
                }
                else
                {
                    receiptBuilder.WithStatusCode(0);
                }

                if (!encodeWithTxHash)
                {
                    receiptBuilder.WithTransactionHash(null);
                }

                if (!withError)
                {
                    receiptBuilder.WithError(string.Empty);
                }

                return(receiptBuilder.TestObject);
            }

            TxReceipt BuildReceipt()
            {
                ReceiptBuilder receiptBuilder = Build.A.Receipt.WithAllFieldsFilled;

                if (!withError)
                {
                    receiptBuilder.WithError(string.Empty);
                }

                return(receiptBuilder.TestObject);
            }

            TxReceipt txReceipt = BuildReceipt();

            ReceiptStorageDecoder encoder = new ReceiptStorageDecoder(encodeWithTxHash);
            Rlp rlp = encoder.Encode(txReceipt, encodeBehaviors);

            ReceiptStorageDecoder decoder = new ReceiptStorageDecoder();
            TxReceipt             deserialized;

            if (valueDecoder)
            {
                Rlp.ValueDecoderContext valueContext = rlp.Bytes.AsRlpValueContext();
                deserialized = decoder.Decode(ref valueContext, RlpBehaviors.Storage);
            }
            else
            {
                deserialized = decoder.Decode(rlp.Bytes.AsRlpStream(), RlpBehaviors.Storage);
            }

            deserialized.Should().BeEquivalentTo(GetExpected());
        }
        private async void btnTestCorrectiveInvoice_Click(object sender, EventArgs e)
        {
            //1. Create receipt
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(true)
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                          .AddSaleItem("1", "Coca Cola 0.5", 2, 2.5m, 21m)
                          .CalculateTotalAmount(EFIPaymentTypeEnum.CARD);

            var result = await SendReceipt(receipt);

            MessageBox.Show("Created recipt with IKOF " + result.UIDRequest);
            var receiptReference = new
            {
                IKOFReference = result.UIDRequest,
                IssuedAt      = receipt.ReceiptTime
            };

            //2. Delate receipt
            var correctiveReceipt = ReceiptBuilder.Build(Guid.NewGuid(), 2)
                                    .SetTCRCode(TCR_CODE)
                                    .SetDates(DateTime.Now, null)
                                    .SetIsCash(true)
                                    .SetUser(USER_NAME, USER_CODE)
                                    .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                                    .SetCorrectiveInvoice()
                                    .AddIKOFReference(receiptReference.IKOFReference, receiptReference.IssuedAt)
                                    .AddSaleItem("1", "Coca Cola 0.5", -2, 2.5m, 21m)
                                    .CalculateTotalAmount(EFIPaymentTypeEnum.CARD);

            result = await SendReceipt(correctiveReceipt);
        }
        private static TxReceipt BuildReceipt(Action <ReceiptBuilder> builder)
        {
            var builderInstance = new ReceiptBuilder();

            builder(builderInstance);

            return(builderInstance.TestObject);
        }
Beispiel #5
0
        public void GivenReceipt_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            this.InstantiateObjects(this.Session);

            var receipt = new ReceiptBuilder(this.Session).WithEffectiveDate(this.Session.Now()).Build();

            Assert.True(receipt.ExistUniqueId);
        }
        public void Setup()
        {
            var taxRateRetreiver  = new TaxRateRetriever();
            var taxesCalculator   = new TaxesCalculator(taxRateRetreiver);
            var basketItemManager = new BasketItemManager(taxesCalculator);
            var receiptBuilder    = new ReceiptBuilder();

            shoppingBasketService = new ShoppingBasketService(receiptBuilder, basketItemManager);
        }
        private async void btnTestAdvanceInvoice_Click(object sender, EventArgs e)
        {
            //1. Create advance
            var advance = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(false)
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                          .SetBuyer(_buyer.Name, _buyer.VATNumber, _buyer.Address)
                          .AddSaleItem("1", "Avans za gradjevinski materijal", 1, 400m, 21m)
                          .CalculateTotalAmount(EFIPaymentTypeEnum.ADVANCE);

            var result = await SendReceipt(advance);

            MessageBox.Show("Created recipt with IKOF " + result.UIDRequest);
            var advanceReference = new
            {
                IKOFReference = result.UIDRequest,
                IssuedAt      = advance.ReceiptTime
            };
            //2. Delate partialy or full amount of the advance payment
            var correctiveInvoice = ReceiptBuilder.Build(Guid.NewGuid(), 2)
                                    .SetTCRCode(TCR_CODE)
                                    .SetDates(DateTime.Now, null)
                                    .SetIsCash(false)
                                    .SetUser(USER_NAME, USER_CODE)
                                    .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                                    .SetBuyer(_buyer.Name, _buyer.VATNumber, _buyer.Address)
                                    .SetCorrectiveInvoice()
                                    .AddIKOFReference(advanceReference.IKOFReference, advanceReference.IssuedAt)
                                    .AddSaleItem("1", "Avans za gradjevinski materijal", -1, 150m, 21m)
                                    .CalculateTotalAmount(EFIPaymentTypeEnum.ADVANCE);

            result = await SendReceipt(correctiveInvoice);

            MessageBox.Show("Created recipt with IKOF " + result.UIDRequest);

            //3. Use partialy or full amount of the Advance payment
            var connectedInvoice = ReceiptBuilder.Build(Guid.NewGuid(), 3)
                                   .SetTCRCode(TCR_CODE)
                                   .SetDates(DateTime.Now, null)
                                   .SetIsCash(false)
                                   .SetUser(USER_NAME, USER_CODE)
                                   .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                                   .SetBuyer(_buyer.Name, _buyer.VATNumber, _buyer.Address)
                                   .AddIKOFReference(advanceReference.IKOFReference, advanceReference.IssuedAt)
                                   .AddSaleItem("2", "Gradjevinski materijal tip 1", 1, 100m, 21m)
                                   .AddSaleItem("3", "Gradjevinski materijal tip 2", 1, 50m, 21m)
                                   .CalculateTotalAmount(EFIPaymentTypeEnum.ACCOUNT);

            result = await SendReceipt(connectedInvoice);
        }
Beispiel #8
0
        public void when_building_with_sales_taxes()
        {
            var receiptBuilder = new ReceiptBuilder();

            var receipt = receiptBuilder
                .WithSalesTaxes(16.43m)
                .Build();

            var expectedReceipt =
                "Sales Taxes: 16.43\r\n" +
                "Total: 0.00\r\n";

            "It should generate the receipt".AssertThat(receipt, Is.EqualTo(expectedReceipt));
        }
        private async void btnReceiptWithError_Click(object sender, EventArgs e)
        {
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 3)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(false)
                          .SetJsonResponse()
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller("Primatech d.o.o.", "02863781", "Podgorica")
                          .SetBuyer("Buyer Company Name", "07654321", "Some Buyer Address")
                          .AddSaleItem("12", "Coca Cola 0.25l", 2, 2.20m, 21m)
                          .CalculateTotalAmount("ACCOUNT");

            await SendReceipt(receipt);
        }
Beispiel #10
0
        public void GivenReceipt_WhenDeriving_ThenAmountCanNotBeSmallerThenAmountApplied()
        {
            this.InstantiateObjects(this.Session);

            var billToContactMechanism = new EmailAddressBuilder(this.Session).WithElectronicAddressString("*****@*****.**").Build();

            var customer = new PersonBuilder(this.Session)
                           .WithLastName("customer")

                           .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(customer)
            .Build();

            var invoice = new SalesInvoiceBuilder(this.Session)
                          .WithBillToCustomer(customer)
                          .WithAssignedBillToContactMechanism(billToContactMechanism)
                          .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice)
                          .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session)
                                                .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                                .WithProduct(this.good)
                                                .WithQuantity(1)
                                                .WithAssignedUnitPrice(100M)
                                                .Build())
                          .Build();

            this.Session.Derive();

            var receipt = new ReceiptBuilder(this.Session)
                          .WithAmount(100)
                          .WithEffectiveDate(this.Session.Now())
                          .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(50).Build())
                          .Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            receipt.AddPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(50).Build());

            Assert.False(this.Session.Derive(false).HasErrors);

            receipt.AddPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(1).Build());

            var derivationLog = this.Session.Derive(false);

            Assert.True(derivationLog.HasErrors);
            Assert.Contains(M.PaymentApplication.AmountApplied, derivationLog.Errors[0].RoleTypes);
        }
        private async void btnNonCashReceipt_Click(object sender, EventArgs e)
        {
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 2)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(false)
                          .SetJsonResponse()
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller("Primatech d.o.o.", "02863782", "Podgorica")
                          .SetBuyer("Buyer Company Name", "07654321", "Some Buyer Address")
                          .AddSaleItem("12", "Coca Cola 0.25l", 120, 1m, 21m)
                          .AddPayment("ACCOUNT", 100m)
                          .AddPayment("BUSINESSCARD", 20m);

            await SendReceipt(receipt);
        }
        private async void btnCashReceipt_Click(object sender, EventArgs e)
        {
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(true)
                          .SetJsonResponse()
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller("Primatech d.o.o.", "02863782", "Podgorica")
                          .AddSaleItem("12", "Coca Cola 0.25l", 2, 2.20m, 21m)
                          .AddSaleItem("22", "Fanta 0.5l", 2, 2.20m, 21m, 10)
                          .AddSaleItem("19", "Sir Gauda", 2, 2.20m, 7m, 0)
                          .CalculateTotalAmount("BANKNOTE");

            await SendReceipt(receipt);
        }
Beispiel #13
0
        public void when_building_with_a_purchased_item()
        {
            var receiptBuilder = new ReceiptBuilder();

            var receipt = receiptBuilder
                .WithPurchasedItem("book", false, 15.55m)
                .WithPurchasedItem("fridge", false, 7m)
                .Build();

            var expectedReceipt =
                "1 book: 15.55\r\n" +
                "1 fridge: 7.00\r\n" +
                "Sales Taxes: 0.00\r\n" +
                "Total: 0.00\r\n";

            "It should generate the receipt".AssertThat(receipt, Is.EqualTo(expectedReceipt));
        }
Beispiel #14
0
        public void GivenPaymentApplication_WhenDeriving_ThenAmountAppliedCannotBeLargerThenAmountReceived()
        {
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build())
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer)
                .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation)
                .Build();

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(1000M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build())
                .Build();

            this.DatabaseSession.Derive(true);

            var receipt = new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(100)
                .WithEffectiveDate(DateTime.UtcNow)
                .Build();

            var paymentApplication = new PaymentApplicationBuilder(this.DatabaseSession)
                .WithAmountApplied(200)
                .WithInvoiceItem(invoice.InvoiceItems[0])
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            receipt.AddPaymentApplication(paymentApplication);

            var derivationLog = this.DatabaseSession.Derive();
            Assert.IsTrue(derivationLog.HasErrors);
            Assert.Contains(PaymentApplications.Meta.AmountApplied, derivationLog.Errors[0].RoleTypes);
        }
        public static EFIReceipt CreateReceipt()
        {
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                          .SetTCRCode("**********")
                          .SetDates(DateTime.Now, null)
                          //.SetIsCash(false)
                          .SetJsonResponse()
                          .SetUser("Marko Markovic", "**********")
                          .SetSeller("Seller Company Name", "01234567", "Some Seller Address")
                          .SetBuyer("Buyer Company Name", "07654321", "Some Buyer Address")
                          .AddSaleItem("12", "Coca Cola 0.25l", 2, 2.20m, 21m)
                          .AddSaleItem("22", "Fanta 0.5l", 2, 2.20m, 21m, 10)
                          .AddSaleItem("19", "Sir Gauda", 2, 2.20m, 7m, 0)
                          //.SetTotalDiscount(10)
                          .AddPayment("CASH", 120m)
                          .CalculateTotalAmount("CASH");

            return(receipt);
        }
Beispiel #16
0
        public void when_building_with_everything()
        {
            var receiptBuilder = new ReceiptBuilder();

            var receipt = receiptBuilder
                .WithPurchasedItem("book", false, 15.55m)
                .WithPurchasedItem("box of chocolates", true, 7.99m)
                .WithSalesTaxes(12.34m)
                .WithTotalPrice(123.77m)
                .Build();

            var expectedReceipt =
                "1 book: 15.55\r\n" +
                "1 imported box of chocolates: 7.99\r\n" +
                "Sales Taxes: 12.34\r\n" +
                "Total: 123.77\r\n";

            "It should generate the receipt".AssertThat(receipt, Is.EqualTo(expectedReceipt));
        }
Beispiel #17
0
        public void GivenPaymentApplication_WhenDeriving_ThenAmountAppliedCannotBeLargerThenAmountReceived()
        {
            var contactMechanism = new ContactMechanisms(this.Session).Extent().First;
            var good             = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            var customer = new PersonBuilder(this.Session).WithLastName("customer").Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(customer)

            .Build();

            var invoice = new SalesInvoiceBuilder(this.Session)
                          .WithBillToCustomer(customer)
                          .WithBillToContactMechanism(contactMechanism)
                          .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithAssignedUnitPrice(1000M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build())
                          .Build();

            this.Session.Derive();

            var receipt = new ReceiptBuilder(this.Session)
                          .WithAmount(100)
                          .WithEffectiveDate(this.Session.Now())
                          .Build();

            var paymentApplication = new PaymentApplicationBuilder(this.Session)
                                     .WithAmountApplied(200)
                                     .WithInvoiceItem(invoice.InvoiceItems[0])
                                     .Build();

            this.Session.Derive();
            this.Session.Commit();

            receipt.AddPaymentApplication(paymentApplication);

            var derivationLog = this.Session.Derive(false);

            Assert.True(derivationLog.HasErrors);
            Assert.Contains(M.PaymentApplication.AmountApplied, derivationLog.Errors[0].RoleTypes);
        }
        public async Task <object> TestReceiptV2()
        {
            //generisemo testne podatke
            var buyer = new
            {
                CompanyName = "Buyer Company Name",
                VATNumber   = "07654321",
                Address     = "Some Buyer Address"
            };

            var sales =
                new[] {
                new{ ItemCode = "12", ItemName = "Coca Cola 0.25l", Quantity = 2, Price = 2.20m, TaxRate = 21m, Discount = 0 },
                new{ ItemCode = "22", ItemName = "Fanta 0.5l", Quantity = 2, Price = 2.20m, TaxRate = 21m, Discount = 10 },
                new{ ItemCode = "19", ItemName = "Sir Gauda", Quantity = 1, Price = 2.20m, TaxRate = 7m, Discount = 0 }
            };

            var service = new FiscalApiService(BASE_URL, TOKEN);

            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                          .SetTCRCode("**********")
                          .SetDates(DateTime.Now, null)
                          .SetUser("Marko Markovic", "**********")
                          .SetSeller("Seller Company Name", "01234567", "Some Seller Address");

            if (buyer != null)
            {
                receipt.SetBuyer(buyer.CompanyName, buyer.VATNumber, buyer.Address);
            }

            foreach (var saleRow in sales)
            {
                receipt.AddSaleItem(saleRow.ItemCode, saleRow.ItemName, saleRow.Quantity, saleRow.Price, saleRow.TaxRate);
            }

            receipt.AddPayment("CASH", 120m);

            return(await service.CreateReceipt(receipt.ToXMLModel()));
        }
        public async Task <object> TestReceipt()
        {
            var service = new FiscalApiService(BASE_URL, TOKEN);

            var receiptXML = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                             .SetTCRCode("**********")
                             .SetDates(DateTime.Now, null)
                             //.SetIsCash(false)
                             .SetJsonResponse()
                             .SetUser("Marko Markovic", "**********")
                             .SetSeller("Seller Company Name", "01234567", "Some Seller Address")
                             .SetBuyer("Buyer Company Name", "07654321", "Some Buyer Address")
                             .AddSaleItem("12", "Coca Cola 0.25l", 2, 2.20m, 21m)
                             .AddSaleItem("22", "Fanta 0.5l", 2, 2.20m, 21m, 10)
                             .AddSaleItem("19", "Sir Gauda", 2, 2.20m, 7m, 0)
                             //.SetTotalDiscount(10)
                             .AddPayment("CASH", 120m)
                             .CalculateTotalAmount("CASH")
                             .ToXMLModel();

            return(await service.CreateReceipt(receiptXML));
        }
        private async void btnTestOrderInvoice_Click(object sender, EventArgs e)
        {
            var order1 = ReceiptBuilder.Build(Guid.NewGuid(), 1)
                         .SetTCRCode(TCR_CODE)
                         .SetDates(DateTime.Now, null)
                         .SetIsCash(true)
                         .SetUser(USER_NAME, USER_CODE)
                         .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                         .AddSaleItem("1", "Coca Cola 0.25l", 2, 2.50m, 21m)
                         .CalculateTotalAmount(EFIPaymentTypeEnum.ORDER);

            var result = await SendReceipt(order1);

            MessageBox.Show("Created recipt with IKOF " + result.UIDRequest);
            var firstOrder = new
            {
                IKOFReference = result.UIDRequest,
                IssuedAt      = order1.ReceiptTime
            };
            var order2 = ReceiptBuilder.Build(Guid.NewGuid(), 2)
                         .SetTCRCode(TCR_CODE)
                         .SetDates(DateTime.Now, null)
                         .SetIsCash(true)
                         .SetUser(USER_NAME, USER_CODE)
                         .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address)
                         .AddSaleItem("2", "Fanta 0.25l", 1, 1.50m, 21m)
                         .AddSaleItem("2", "Bavaria", 1, 3.50m, 21m)
                         .CalculateTotalAmount(EFIPaymentTypeEnum.ORDER);

            result = await SendReceipt(order2);

            MessageBox.Show("Created recipt with IKOF " + result.UIDRequest);
            var secondOrder = new
            {
                IKOFReference = result.UIDRequest,
                IssuedAt      = order2.ReceiptTime
            };

            //summary invoice
            //1. Set Header
            var receipt = ReceiptBuilder.Build(Guid.NewGuid(), 3)
                          .SetTCRCode(TCR_CODE)
                          .SetDates(DateTime.Now, null)
                          .SetIsCash(true)
                          .SetUser(USER_NAME, USER_CODE)
                          .SetSeller(_seller.Name, _seller.VATNumber, _seller.Address);

            //2. Add items from all orders
            foreach (var saleItem in order1.Sales)
            {
                receipt.AddSaleItem(saleItem);
            }
            foreach (var saleItem in order2.Sales)
            {
                receipt.AddSaleItem(saleItem);
            }
            //3. Set type (summary), and add references to the orders
            receipt.SetSummaryInvoice();
            receipt.AddIKOFReference(firstOrder.IKOFReference, firstOrder.IssuedAt);
            receipt.AddIKOFReference(secondOrder.IKOFReference, secondOrder.IssuedAt);

            //4. Set payment type of summary invoice
            receipt.CalculateTotalAmount(EFIPaymentTypeEnum.CARD);

            result = await SendReceipt(receipt);
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            var director       = new Director();
            var receiptBuilder = new ReceiptBuilder();

            director.Builder = receiptBuilder;
            var header = new Header()
            {
                StoreName = "Semiorochka",
                Cashier   = new СashierName()
                {
                    FirstName = "Lius", MiddleName = "Pavlovich", LastName = "McLonder"
                }
            };
            var groceries = new List <IBody>();
            var bread     = new Grocery()
            {
                Id      = 0109890,
                Name    = "Bread Borodinskiy",
                Price   = 30.50,
                Amounth = 2
            };
            var milk = new Grocery()
            {
                Id      = 018797890,
                Name    = "Milk Prostokvashino",
                Price   = 50.60,
                Amounth = 3
            };
            var eggs = new Grocery()
            {
                Id      = 82462490,
                Name    = "Eggs Fermersky",
                Price   = 10.90,
                Amounth = 10
            };

            groceries.Add(bread);
            groceries.Add(milk);
            groceries.Add(eggs);

            var footer = new Footer()
            {
                ReceiptNumber = 5803498,
                FooterMessage = "Have a good day!!"
            };
            var receipt = new Receipt()
            {
                Header    = header,
                Groceries = groceries,
                Footer    = footer
            };

            Console.WriteLine("Standard basic ReceiptHtmlBuilder:");
            Console.WriteLine(director.BuildHtmlReceipt(receipt));

            Console.WriteLine("Custom product:");

            Console.Write(receiptBuilder.Init()
                          .BuildHeader(header)
                          .BuildBody(groceries)
                          .BuildFooter(footer)
                          .BuildTemplate()
                          .GetResult());
            Console.ReadKey();
        }
 public void SetUp()
 {
     receiptBuilder = new ReceiptBuilder();
 }
Beispiel #23
0
        // These methods could be as private but in the need or the exercise
        // We have ignored an isolated test for theses builders
        public string GetReceipt()
        {
            var receiptBuilder = new ReceiptBuilder();

            return(receiptBuilder.Build(Bracket));
        }
Beispiel #24
0
        public void GivenReceipt_WhenDeriving_ThenAmountCanNotBeSmallerThenAmountApplied()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var billToContactMechanism = new EmailAddressBuilder(this.DatabaseSession).WithElectronicAddressString("*****@*****.**").Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build();
            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer)
                .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation)
                .Build();

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(billToContactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession)
                                        .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                                        .WithProduct(this.good)
                                        .WithQuantity(1)
                                        .WithActualUnitPrice(100M)
                                        .Build())
                .Build();

            this.DatabaseSession.Derive(true);

            var receipt = new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(100)
                .WithEffectiveDate(DateTime.UtcNow)
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(50).Build())
                .Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            receipt.AddPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(50).Build());

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            receipt.AddPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice.SalesInvoiceItems[0]).WithAmountApplied(1).Build());

            var derivationLog = this.DatabaseSession.Derive();
            Assert.IsTrue(derivationLog.HasErrors);
            Assert.Contains(Receipts.Meta.Amount, derivationLog.Errors[0].RoleTypes);
        }
Beispiel #25
0
        public void GivenReceipt_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var receipt = new ReceiptBuilder(this.DatabaseSession).WithEffectiveDate(DateTime.UtcNow).Build();

            Assert.IsTrue(receipt.ExistUniqueId);
        }
Beispiel #26
0
        public void when_building_with_total_price_with_less_than_2_decimal_places()
        {
            var receiptBuilder = new ReceiptBuilder();

            var receipt = receiptBuilder
                .WithTotalPrice(16m)
                .Build();

            var expectedReceipt =
                "Sales Taxes: 0.00\r\n" +
                "Total: 16.00\r\n";

            "It should generate the receipt".AssertThat(receipt, Is.EqualTo(expectedReceipt));
        }