Beispiel #1
0
        public void CharacterizeRefactoredVersion(
            Product dummyProduct,
            Mock <IDiscountRepository> dummyRepository,
            Mock <IAuthorize> dummyAuthorizer)
        {
            dummyProduct.DiscountType = "percentage";
            dummyRepository.Setup(x => x.GetDiscountForType(
                                      It.IsAny <string>(),
                                      It.IsAny <string>())).Returns(.5M);
            dummyAuthorizer.Setup(x => x.IsAuthorized()).Returns(true);

            // composition root
            var percentoff = new PercentageDiscountStrategy();
            var moneyoff   = new MoneyOffDiscountStrategy();
            var unknown    = new UnknownDiscountStrategy();

            var runfirst = new RunFirstCompositeStrategy(new IDiscountStrategy[]
            {
                percentoff,
                moneyoff,
                unknown
            });
            var discountCalculator = new RefactoredProductClass(
                dummyRepository.Object,
                runfirst);
            var authorizedSut = new AuthorizableDiscountCalculator(
                dummyAuthorizer.Object,
                discountCalculator);
            // end composition root

            var actual = authorizedSut.GetDiscountPrice(dummyProduct);

            Assert.Equal(dummyProduct.Price * .5M, actual);
        }
Beispiel #2
0
        public void CompositeStrategyReturnIsCorrect(
            Product product,
            decimal discount,
            decimal expectedDiscount,
            [Frozen] Mock <IDiscountStrategy> strategy,
            RunFirstCompositeStrategy sut)
        {
            strategy.Setup(x => x.ShouldRunFor(product)).Returns(true);
            strategy.Setup(x => x.DiscountProduct(product, discount)).Returns(expectedDiscount);
            var actual = sut.DiscountProduct(product, discount);

            Assert.Equal(expectedDiscount, actual);
        }
Beispiel #3
0
 public void CompositeStrategyShouldRun(
     Product testProduct,
     RunFirstCompositeStrategy sut)
 {
     Assert.True(sut.ShouldRunFor(testProduct));
 }