Exemplo n.º 1
0
        public void Should_Store_Value_In_Extended_Data()
        {
            CalculationContext context = new CalculationContext()
            {
                ChargeElement = new ChargeElement() { Name = "Standing Charge", NetAmount = new decimal(12.71000) },
                Bill = new Bill() { BillStartDate = new DateTime(2012, 2, 10), BillEndDate = new DateTime(2012, 3, 12), TaxPointDate = new DateTime(2012, 03, 12), ExtendedData = new List<ExtendedDataElement>() { new ExtendedDataElement() { ElementName = "PowerFactor", ElementValue = "123" } } },
                Contract = new Contract() { }
            };

            var calculation = new Calculation()
            {
                Formula = "[ChargeElement.NetAmount] / [Bill.BillPeriod]",
                Target = "Bill.ExtendedData.PowerFactor"
            };

            var calculationEngine = new CalculationEngine();
            calculationEngine.Calculate(context, calculation);

            Assert.AreEqual(0.41d, decimal.Parse(context.Bill.ExtendedData.First(x=>x.ElementName == "PowerFactor").ElementValue));
        }
Exemplo n.º 2
0
        public void Should_Take_Value_From_ExtendedProperties_Using_Name()
        {
            CalculationContext context = new CalculationContext()
            {
                ChargeElement = new ChargeElement() { Name = "Standing Charge", NetAmount = new decimal(12.71000) },
                Bill = new Bill() { BillStartDate = new DateTime(2012, 2, 10), BillEndDate = new DateTime(2012, 3, 12), TaxPointDate = new DateTime(2012, 03, 12),ExtendedData = new List<ExtendedDataElement>(){new ExtendedDataElement(){ElementName = "PowerFactor", ElementValue = "123"}}},
                Contract = new Contract() { }
            };

            var calculation = new Calculation()
            {
                Formula = "[ChargeElement.NetAmount] / [Bill.BillPeriod] * [Bill.ExtendedData.PowerFactor]",
                Target = "ChargeElement.Quantity"
            };

            var calculationEngine = new CalculationEngine();
            calculationEngine.Calculate(context, calculation);

            Assert.AreEqual(50.43d, context.ChargeElement.Quantity);
        }
Exemplo n.º 3
0
        public void ShouldTakeFormulaAndUseCorrectPropertyValues()
        {
            CalculationContext context = new CalculationContext()
            {
                ChargeElement = new ChargeElement() { Name = "Standing Charge", NetAmount = new decimal(12.71000) },
                Bill = new Bill() { BillStartDate = new DateTime(2012, 2, 10), BillEndDate = new DateTime(2012, 3, 12), TaxPointDate = new DateTime(2012, 03, 12) },
                Contract = new Contract() {}
            };

            var calculation = new Calculation()
                                 {
                                     Formula = "[ChargeElement.NetAmount] / [Bill.BillPeriod]",
                                     Target = "ChargeElement.Quantity"
                                 };

            var calculationEngine = new CalculationEngine();
            calculationEngine.Calculate(context, calculation);

            Assert.AreEqual(0.41d, context.ChargeElement.Quantity);
        }