예제 #1
0
        public void Should_AddCalculator_Compose_With_Itself()
        {
            var calculator      = new DiscountStrategyCalculator <Order>(DiscountStrategyOperations.Sum);
            var otherCalculator = new DiscountStrategyCalculator <Order>();

            calculator.Configure()
            .When(_ => true)
            .ApplyDiscount(_ => 42m);

            otherCalculator.Configure()
            .When(_ => true)
            .ApplyDiscount(_ => 42m);

            calculator.AddCalculator(otherCalculator);

            Assert.That(
                calculator.GetDiscount(new Order(Arg.Any <string>(), Arg.Any <string>(), 0.0725m)),
                Is.EqualTo(84m));
        }
예제 #2
0
        public void Should_AddCalculator_Throw_ArgumentException_When_Cyclic_References()
        {
            var sut = new DiscountStrategyCalculator <Order>();

            Assert.Throws <ArgumentException>(() => sut.AddCalculator(sut));
        }