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); }
public void AuthorizableDiscountCalculatorThrowsWhenUnauthorized( Product testProduct, [Frozen] Mock <IAuthorize> authorizer, AuthorizableDiscountCalculator sut) { authorizer.Setup(x => x.IsAuthorized()).Returns(false); Assert.Throws <UnauthorizedException>(() => sut.GetDiscountPrice(testProduct)); }
public void AuthorizableDiscountCalculatorExecutesWhenAuthorized( Product testProduct, decimal expected, [Frozen] Mock <IAuthorize> authorizer, [Frozen] Mock <IDiscountQuery> baseQuery, AuthorizableDiscountCalculator sut) { authorizer.Setup(x => x.IsAuthorized()).Returns(true); baseQuery.Setup(x => x.GetDiscountPrice(testProduct)).Returns(expected); var actual = sut.GetDiscountPrice(testProduct); Assert.Equal(expected, actual); }