Пример #1
0
 public void UnknownDiscountStrategyThrowsIfRun(
     Product p,
     decimal discount,
     UnknownDiscountStrategy sut)
 {
     Assert.Throws <InvalidOperationException>(() => { sut.DiscountProduct(p, discount); });
 }
Пример #2
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);
        }
Пример #3
0
 public void UnknownDiscountStrategyShouldAlwaysRun(
     Product testProduct,
     UnknownDiscountStrategy sut)
 {
     Assert.Throws <UnknownDiscountTypeException>(() => sut.ShouldRunFor(testProduct));
 }