Ejemplo n.º 1
0
        public void GetProvincialSalesTaxCharged_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);

            //Act
            decimal salesTax = (servieInvoice.LabourCost + servieInvoice.PartsCost) * 0.2m;

            //Assert
            Assert.AreEqual(200m, salesTax);
        }
Ejemplo n.º 2
0
        public void Total_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);
            //Act
            decimal expectedTotal = (500 + 500 + 500) + (500 + 500) * 0.2m + (500 + 500 + 500) * 0.1m;
            decimal actualTotal   = servieInvoice.SubTotal + servieInvoice.ProvincialSalesTaxCharged + servieInvoice.GoodAndServicesTaxCharged;

            //Assert
            Assert.AreEqual(expectedTotal, actualTotal);
        }
Ejemplo n.º 3
0
        public void SubTotal_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);

            //Act
            decimal subTotal = servieInvoice.LabourCost + servieInvoice.PartsCost + servieInvoice.MaterialCost;

            //Assert
            Assert.AreEqual(1500, subTotal);
        }
Ejemplo n.º 4
0
        public void GetGoodsAndServicesTaxCharged_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);

            //Act
            decimal salesTax = (servieInvoice.LabourCost + servieInvoice.PartsCost + servieInvoice.MaterialCost) * 0.1m;

            //Assert
            Assert.AreEqual(150m, salesTax);
        }
Ejemplo n.º 5
0
        public void AddCost_LessThanZero_Test()
        {
            //Arrange
            decimal        provincialSalesTaxRate  = 0.2m;
            decimal        goodsAndServicesTaxRate = 1.1m;
            ServiceInvoice servieInvoice           = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            servieInvoice.AddCost(CostType.Labour, -1);
        }
Ejemplo n.º 6
0
        public void CostAdded_Test()
        {
            this.eventActual = null;
            ServiceInvoice serviceInvoice = new ServiceInvoice(0.2m, 0.2m);

            serviceInvoice.CostAdded += TestHandler;
            serviceInvoice.AddCost(CostType.Labour, 500);
            Assert.AreEqual("Event triggered.", eventActual);
        }
Ejemplo n.º 7
0
        public void AddCost_Equal_Exception_Test()
        {
            decimal        amount   = 0M;
            CostType       costType = CostType.Labour;
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            serviceInvoice.AddCost(costType, amount);
        }
Ejemplo n.º 8
0
        public void AddCost_NegativeAmount_Exception()
        {
            // Arrange
            CostType type = CostType.Labour;
            decimal  amount = -40M, provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            serviceInvoice.AddCost(type, amount);
        }
Ejemplo n.º 9
0
        public void AddCost_InvalidCostType_Exception()
        {
            // Arrange
            CostType type = (CostType)99;
            decimal  amount = 40M, provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            serviceInvoice.AddCost(type, amount);
        }
        public void ProvincialSalesTaxCharged_Test()
        {
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            serviceInvoice.AddCost(CostType.Material, 0.2M);
            decimal expectedProvincialSalesTaxCharged = 0.02M;
            decimal actualProvincialSalesTaxCharged   = serviceInvoice.ProvincialSalesTaxCharged;

            Assert.AreEqual(expectedProvincialSalesTaxCharged, actualProvincialSalesTaxCharged);
        }
Ejemplo n.º 11
0
        public void MaterialCost_Test()
        {
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);
            decimal        expectedMaterialCost    = 0.3M;

            serviceInvoice.AddCost(CostType.Material, expectedMaterialCost);
            decimal actualMaterialCost = serviceInvoice.MaterialCost;

            Assert.AreEqual(expectedMaterialCost, actualMaterialCost);
        }
Ejemplo n.º 12
0
        public void AddCost_CostTypeMaterial_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            //Act
            decimal actualAmount = 300;

            servieInvoice.AddCost(CostType.Material, actualAmount);

            //Assert
            Assert.AreEqual(300, servieInvoice.MaterialCost);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// when click add button, add a list of the information input to the data grid view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            //when validate
            if (this.ValidateChildren())
            {
                //invoke ServiceInvoice constructor
                ServiceInvoice serviceInvoice = new ServiceInvoice(Decimal.Parse(ConfigurationManager.AppSettings.Get("Provincial Sales Tax (PST) Rate")),
                                                                   Decimal.Parse(ConfigurationManager.AppSettings.Get("Government Sales Tax (GST) Rate")));

                CostType costType = (CostType)(cboType.SelectedIndex);

                serviceInvoice.AddCost(costType, Decimal.Parse(txtCost.Text));

                //add new row to the data grid view
                dgvServiceList.Rows.Add(new[] { rowNumber.ToString(),
                                                txtDescription.Text,
                                                cboType.SelectedItem.ToString(),
                                                Decimal.Parse(txtCost.Text).ToString("c") });

                rowNumber++;

                //calculate display values
                this.LabourCost     = this.LabourCost + serviceInvoice.LabourCost;
                this.PartsCost      = this.PartsCost + serviceInvoice.PartsCost;
                this.MatericalsCost = this.MatericalsCost + serviceInvoice.MaterialsCost;

                //calculate the total values
                this.SubtotalDisplay += serviceInvoice.SubTotal;
                this.PstDisplay      += serviceInvoice.PSTCharged;
                this.GstDisplay      += serviceInvoice.GSTCharged;
                this.TotalDisplay    += serviceInvoice.Total;

                //display the values
                lblSubtotal.Text = this.SubtotalDisplay.ToString("c");
                lblPst.Text      = this.PstDisplay.ToString("F2");
                lblGst.Text      = this.GstDisplay.ToString("F2");
                lblTotal.Text    = this.TotalDisplay.ToString("c");

                clearForm();

                mnuDescriptionGenerate.Enabled = true;
                //enable context mune strip
                mnuContextClear.Enabled = true;
            }
        }
Ejemplo n.º 14
0
        public void AddCost_SwitchPartCost_ReturnTotal()
        {
            // Arrange
            CostType type = CostType.Part;
            decimal  amount = 40M, provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            decimal startAmount           = serviceInvoice.PartsCost;

            serviceInvoice.AddCost(type, amount);

            // Assert
            decimal expected = startAmount + amount;

            Assert.AreEqual(expected, serviceInvoice.PartsCost);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Handles the event when the add button is clicked
        /// </summary>
        void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                dgvServiceItems.Rows.Add(new[] { dgvServiceItems.RowCount + 1, txtDescription.Text, cboType.SelectedItem, decimal.Parse(txtCost.Text).ToString("C") });

                invoice.AddCost((CostType)cboType.SelectedIndex, decimal.Parse(txtCost.Text));

                // A method that outputs the value for the Subtotal, PST and GST charged, and total cost
                serviceCalculation(invoice);

                mnuServiceGenerateInvoice.Enabled = true;
                mnuContextClear.Enabled           = true;

                // Clear the user input
                defaultState();
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            ///Initialize a SalesQuote object
            Console.WriteLine();
            SalesQuote saleQuote = new SalesQuote(0.1M, 0.2M, 0.3M, Accessories.All, ExteriorFinish.Custom);

            saleQuote.VehiclePriceChanged += new EventHandler(SalesQuote_VehiclePriceChanged);
            Console.WriteLine("Old value is {0}", saleQuote.VehicleSalePrice);
            saleQuote.VehicleSalePrice = 0.3M;
            Console.WriteLine("Change from 0.1 to {0} [VehicleSalePrice]", saleQuote.VehicleSalePrice);

            Console.WriteLine();
            saleQuote.TradeInAmountChanged += new EventHandler(SalesQuote_TradeInAmount);
            Console.WriteLine("Old value is {0}", saleQuote.TradeInAmount);
            saleQuote.TradeInAmount = 0.15M;
            Console.WriteLine("Change from 0.2 to {0} [TradeInAmount]", saleQuote.TradeInAmount);

            Console.WriteLine();
            saleQuote.AccessoriesChosenChanged += new EventHandler(SalesQuote_AccessoriesChosenChanged);
            Console.WriteLine("Old value is {0}", saleQuote.AccessoriesChosen);
            saleQuote.AccessoriesChosen = Accessories.ComputerNavigation;
            Console.WriteLine("Change from All to {0} [Accessories]", saleQuote.AccessoriesChosen);

            Console.WriteLine();
            saleQuote.ExteriorFinishChosenChanged += new EventHandler(SalesQuote_ExteriorFinishChosenChanged);
            Console.WriteLine("Old value is {0}", saleQuote.ExteriorFinishChosen);
            saleQuote.ExteriorFinishChosen = ExteriorFinish.None;
            Console.WriteLine("Change from Custom to {0} [ExteriorFinishChosen]", saleQuote.ExteriorFinishChosen);

            ServiceInvoice invoice        = new ServiceInvoice(0.1M, 0.3M);
            CarWashInvoice carWashInvoice = new CarWashInvoice(0.1M, 0.2M, 3000M, 4000M);

            Console.WriteLine();
            invoice.AddCost(CostType.Labour, 0.1M);
            Console.WriteLine("Old value is {0} [ProvincialSalesTaxCharged]", invoice.ProvincialSalesTaxCharged);
            Console.WriteLine("Old value is {0} [GoodsAndServicesTaxCharged]", invoice.GoodsAndServicesTaxCharged);
            invoice.CostAdded += new EventHandler(SalesQuote_ProvincialSalesTaxChanged);
            invoice.CostAdded += new EventHandler(SalesQuote_GoodsAndServicesTaxChanged);
            invoice.AddCost(CostType.Labour, 0.4M);
            Console.WriteLine("Change from 0.01 to {0} [ProvincialSalesTaxCharged]", invoice.ProvincialSalesTaxCharged);
            Console.WriteLine("Change from 0.03 to {0} [GoodsAndServicesTaxCharged]", invoice.GoodsAndServicesTaxCharged);


            Console.WriteLine();
            carWashInvoice.PackageCost = 0.3M;
            Console.WriteLine("Old value is {0}", carWashInvoice.PackageCost);
            carWashInvoice.PackageCostChanged += new EventHandler(SalesQuote_PackageCostChanged);
            carWashInvoice.PackageCost         = 0.2M;
            Console.WriteLine("Change from 0.3 to {0} [PackageCost]", carWashInvoice.PackageCost);

            Console.WriteLine();
            carWashInvoice.FragranceCost = 0.1M;
            Console.WriteLine("Old value is {0}", carWashInvoice.FragranceCost);
            carWashInvoice.FragranceCostChanged += new EventHandler(SalesQuote_FragranceCostChanged);
            carWashInvoice.FragranceCost         = 0.4M;
            Console.WriteLine("Change from 0.1 to {0} [FragranceCost]", carWashInvoice.FragranceCost);

            Console.WriteLine();
            invoice.CostAdded += new EventHandler(SalesQuote_CostAdded);
            Console.WriteLine("Old value is {0}", invoice.LabourCost);
            invoice.AddCost(CostType.Labour, 1.1M);
            /// It's 0.5 because I invoke it above for testing PST and GST
            Console.WriteLine("Change from 0.5 to {0} [Labour]", invoice.LabourCost);

            Console.WriteLine();
            Console.WriteLine("Old value is {0}", invoice.MaterialCost);
            invoice.AddCost(CostType.Material, 1.1M);
            Console.WriteLine("Change from 0 to {0} [Material]", invoice.MaterialCost);

            Console.WriteLine();
            Console.WriteLine("Old value is {0}", invoice.PartCost);
            invoice.AddCost(CostType.Part, 1.1M);
            Console.WriteLine("Change from 0 to {0} [Part]", invoice.PartCost);

            Console.ReadKey();
        }