public void TestDiscountIsAppliedIfNumberOfItemsIsThreeOrGreaterThanThree( )
        {
            List <CheckoutKata.Business.ISpecialPricingRule> rules = TestAssistant.CreateRulesFromTexFile( );
            var wh = new GenericCalculator(rules[0]);
            // Arrange
            var disCountProduct = TestAssistant.StockKeepingUnits(3, "A", 50);

            var expected = 130;

            var actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);

            disCountProduct = TestAssistant.StockKeepingUnits(5, "A", 50);
            expected        = 230;

            actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);

            disCountProduct = TestAssistant.StockKeepingUnits(10, "A", 50);
            expected        = 440;

            actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void AdditionTest()
        {
            var calculator = new GenericCalculator <T>();

            dynamic result = calculator.Add((dynamic)2, (dynamic)3);

            Assert.That(result, Is.EqualTo(5));
        }
        public void Addition_test()
        {
            dynamic a = 2;
            dynamic b = 3;

            var     calculator = new GenericCalculator <T>();
            dynamic result     = calculator.Add(a, b);

            Assert.That(result, Is.EqualTo(5));
        }
        public void TestNoDiscountAppliedIfNumberOfItemsIsLessThanThree( )
        {
            List <CheckoutKata.Business.ISpecialPricingRule> rules = TestAssistant.CreateRulesFromTexFile( );

            var disCountProduct = TestAssistant.StockKeepingUnits(2, "A", 50);

            var wh = new GenericCalculator(rules[0]);

            var expected = 100;

            var actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);
        }
Beispiel #5
0
        private static object Main <T>()
        {
            //define a joinpoint
            var _operationContractJoinpoint =
                new Func <MethodBase, bool>(_Method => _Method.IsDefined(typeof(OperationContractAttribute), true));

            //instantiate a calculator
            var _calculator = new GenericCalculator <T>();

            Console.WriteLine("Weaving");
            //weave logging for all operation contract
            Aspect.Weave <Logging>(_operationContractJoinpoint);
            Console.WriteLine("Weaved");


            //invoke an operation contract (logging is enabled)
            dynamic _value15 = 15;
            dynamic _value3  = 3;
            var     _return  = _calculator.Divide(_value15, _value3);

            Console.WriteLine("Releasing");
            //release logging for all operation contract
            Aspect.Release <Logging>(_operationContractJoinpoint);
            Console.WriteLine("Released");

            //invoke an operation contract (logging is disabled)
            _return = _calculator.Divide(_value15, _value3);

            Console.WriteLine("Weaving");
            //enable back logging aspect.
            Aspect.Weave <Logging>(_operationContractJoinpoint);
            Console.WriteLine("Weaved");

            //invoke an operation with an exception (divide by zero)
            try
            {
                dynamic _value0 = 0;
                _return = _calculator.Divide(_value15, _value0);
            }
            catch
            {
            }

            return(_return);
        }
        public void TestApplyDiscountReturnsZeroIfNoProductIsProcided( )
        {
            var rules = TestAssistant.CreateRulesFromTexFile( );

            // Arrange
            List <StockKeepingUnit> disCountProduct = null;
            var wh       = new GenericCalculator(rules[0]);
            var expected = 0;

            var actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);

            // Now initialised with no item on the list
            disCountProduct = new List <StockKeepingUnit>();

            actual = wh.ApplyDiscount(disCountProduct);

            Assert.AreEqual(expected, actual);
        }